赞
踩
1 openharmony
借助openharmony3.0的构建系统可以快速的搭建linux开发环境,总结一下AT32F437的适配过程
2 安装工具
2.1 安装gcc编译器
2.1.1 添加环境变量
- root@ubuntu:~/samba/tools# vim ~/.bashrc
- export PATH=$PATH:~/samba/tools/gcc-arm-none-eabi-10-2020-q4-major/bin
2.1.2 使变量生效
-
- root@ubuntu:~/samba/tools# source ~/.bashrc
2.1.3 查看gcc版本
-
- root@ubuntu:~/samba/tools# arm-none-eabi-gcc -v
- Thread model: single
- Supported LTO compression algorithms: zlib
- gcc version 10.2.1 20201103 (release) (GNU Arm Embedded Toolchain 10-2020-q4-major)
2.2 安装python脚本工具
2.2.1 解压
root@ubuntu:~/samba/tools# tar -xvf Python-3.9.0b4.tgz
2.2.2 安装依赖库
-
- root@ubuntu:~/samba/tools# apt-get install zlibc zlib1g-dev
- root@ubuntu:~/samba/tools# sudo apt-get install libffi-dev
2.2.3 编译并安装python
- root@ubuntu:~/samba/tools# cd Python-3.9.0b4/
- root@ubuntu:~/samba/tools/Python-3.9.0b4# ./configure --prefix=/usr
- root@ubuntu:~/samba/tools/Python-3.9.0b4# make
- root@ubuntu:~/samba/tools/Python-3.9.0b4# make install
2.2.4 解决错误
- root@ubuntu:~/samba/tools/Python-3.9.0b4#sudo find / -name 'lsb_release.py'
- root@ubuntu:~/samba/tools/Python-3.9.0b4#sudo cp
- /usr/lib/python3/dist-packages/lsb_release.py /usr/lib/python3.9/
2.2.5 再安装
root@ubuntu:~/samba/tools/Python-3.9.0b4# make install
2.3 安装pip3
-
- root@ubuntu:~/samba/tools/Python-3.9.0b4# apt-get install python3-pip
查看版本号
-
- root@ubuntu:~/samba/tools/Python-3.9.0b4# pip3 -V
- WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
- Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
- To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
- pip 20.1.1 from /usr/lib/python3.9/site-packages/pip (python 3.9)
2.4 安装build构建工具
进入到源码主目录下输入pip3 install build/lite
2.4.1 选择项目hb set
- 可能会报错
-
- ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'OpenSSL 1.0.2g 1 Mar 2016'. See: https://github.com/urllib3/urllib3/issues/2168
- 解决方法
输入以下指令指定urllib3版本
-
- pip3 install urllib3==1.26.15
3 添加产品源码
3.1 目录说明
3.2 添加产品配置文件
在vendor下创建at32/at32f437目录,添加config.json文件
-
- {
- "product_name": "at32_rtt_app",
- "ohos_version": "OpenHarmony 3.0",
- "device_company": "at32",
- "board": "at32f437",
- "kernel_type": "rtthread",
- "kernel_version": "3.0.0",
- "subsystems": [
- {
- "subsystem": "kernel",
- "components": [
- { "component": "rtthread",
- "features":[
-
- ]
- }
- ]
- }
- ],
- "vendor_adapter_dir": "//device/at32/at32f437",
- "third_party_dir": "//third_party",
- "product_adapter_dir": "",
- "ohos_product_type":"",
- "ohos_manufacture":"",
- "ohos_brand":"",
- "ohos_market_name":"",
- "ohos_product_series":"",
- "ohos_product_model":"",
- "ohos_software_model":"",
- "ohos_hardware_model":"",
- "ohos_hardware_profile":"",
- "ohos_serial":"",
- "ohos_bootloader_version":"",
- "ohos_secure_patch_level":"",
- "ohos_abi_list":""
- }

3.3 添加固件库目录at32_lib
在目录下添加构建脚本
-
- # Copyright (c) 2020 Huawei Device Co., Ltd.
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
-
- static_library("fwlib") {
- sources = [
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_acc.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_adc.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_can.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_crc.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_crm.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_dac.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_debug.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_dma.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_emac.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_ertc.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_exint.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_flash.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_gpio.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_i2c.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_misc.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_pwc.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_qspi.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_scfg.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_sdio.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_spi.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_tmr.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_usart.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_usb.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_wdt.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_wwdt.c",
- "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_xmc.c",
- ]
- include_dirs = [
- ".",
- "AT32F435_437_Firmware_Library/drivers/inc",
- "AT32F435_437_Firmware_Library/drivers/cmsis/cm4/core_support"
- ]
-
- }

3.4 添加设备配置文件
3.4.1 rtthread
- rtconfig.h
添加RTOS配置文件
- config.gni
定义编译选项、宏定义等
-
- # Copyright (c) 2021 Huawei Device Co., Ltd.
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
-
- # Kernel type, e.g. "linux", "liteos_a", "liteos_m".
- kernel_type = "rtthread"
-
- # Kernel version.
- kernel_version = "3.0.0"
-
- # Board CPU type, e.g. "cortex-a7", "riscv32".
- board_cpu = "cortex-m4"
-
- # Board arch, e.g. "armv7-a", "rv32imac".
- board_arch = ""
-
- # Toolchain name used for system compiling.
- # E.g. gcc-arm-none-eabi, arm-linux-harmonyeabi-gcc, ohos-clang, riscv32-unknown-elf.
- # Note: The default toolchain is "ohos-clang". It's not mandatory if you use the default toochain.
- board_toolchain = "arm-none-eabi-gcc"
- # The toolchain path instatlled, it's not mandatory if you have added toolchian path to your ~/.bashrc.
- board_toolchain_path = ""
-
- # Compiler prefix.
- board_toolchain_prefix = "arm-none-eabi-"
-
- # Compiler type, "gcc" or "clang".
- board_toolchain_type = "gcc"
- board_outtype = "boot"
-
- # Board related common compile flags.
- board_cflags = [
- "-mfpu=fpv4-sp-d16",
- "-mfloat-abi=hard",
- "-mthumb",
- "-Os",
- "-ffunction-sections",
- "-fdata-sections",
- ]
-
- board_cxx_flags = board_cflags
-
- out_dir = rebase_path(root_build_dir)
-
- board_macro_defines = [
- "__STDC_LIMIT_MACROS",
- "RT_USING_ARMLIBC",
- "RT_USING_LIBC",
- "AT32F437ZMT7",
- "AT_START_F437_V1",
- "USE_STDPERIPH_DRIVER",
- "__CLK_TCK=RT_TICK_PER_SECOND",
- "__RTTHREAD__",
- "RT_USING_ARM_LIBC",
- ]
- out_dir = rebase_path(root_build_dir)
-
- board_default_path = [
- "-L${out_dir}/libs"
- ]
-
- board_ld_flags = [
- "-nostartfiles",
- "--specs=nano.specs",
- "--specs=nosys.specs",
- "-Wl,--gc-sections",
- "-Wl,-Map=${out_dir}/test.map",
- "-Wl,-rpath-link=${out_dir}",
- "-Wl,-u_printf_float",
- ]
-
- # Board related headfiles search path.
- board_include_dirs = [
- "//vendor/at32/at32f437/at32_lib/AT32F435_437_Firmware_Library/cmsis/cm4/core_support",
- "//vendor/at32/at32f437/at32_lib/AT32F435_437_Firmware_Library/cmsis/cm4/device_support",
- ]
-
- # Board adapter dir for OHOS components.
- board_adapter_dir = ""
-
- # Sysroot path.
- board_configed_sysroot = ""
-
- # Board storage type, it used for file system generation.
- storage_type = ""

3.4.2 BUILD.gn
添加构建脚本,定义要编译的APP目录
-
- # Copyright (c) 2021 Huawei Device Co., Ltd.
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
-
- import("//build/lite/config/component/lite_component.gni")
-
- group("at32f437") {
- }
-
- build_ext_component("at32f437_app") {
- exec_path = rebase_path(".", root_build_dir)
- outdir = rebase_path("$root_out_dir")
- print("$board_toolchain")
-
- command = "./build.sh ${outdir}"
-
- deps = [
- "//applications/app:app",
- ]
-
- }

3.4.3 添加Makefile
定义要输出的目标文件
-
- ##########################################################################################################################
-
- # File automatically-generated by tool: [projectgenerator] version: [3.13.0-B3] date: [Fri Apr 30 08:31:16 CST 2021]
-
- ##########################################################################################################################
-
-
-
- # ------------------------------------------------
-
- # Generic Makefile (based on gcc)
-
- #
-
- # ChangeLog :
-
- # 2017-02-10 - Several enhancements + project update mode
-
- # 2015-07-22 - first version
-
- # ------------------------------------------------
-
-
-
- ######################################
-
- # target
-
- ######################################
-
- TARGET = at32f437_app
-
- FILE_NAME = app
-
-
-
- BUILD_DIR = $(OUT_DIR_PATH)
-
-
-
- #######################################
- # toolchain paths
- #######################################
-
- # Toolchain path
-
- ifneq ($(TOOLCHAIN_DIR_PATH), )
-
- GCC_PATH = $(TOOLCHAIN_DIR_PATH)
-
- endif
-
-
-
- #######################################
- # binaries
- #######################################
-
- PREFIX = arm-none-eabi-
-
- # The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
-
- # either it can be added to the PATH environment variable.
-
- ifneq ($(GCC_PATH), )
-
- CC = $(GCC_PATH)/$(PREFIX)gcc
-
- AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
-
- CP = $(GCC_PATH)/$(PREFIX)objcopy
-
- SZ = $(GCC_PATH)/$(PREFIX)size
-
- else
-
- CC = $(PREFIX)gcc
-
- AS = $(PREFIX)gcc -x assembler-with-cpp
-
- CP = $(PREFIX)objcopy
-
- SZ = $(PREFIX)size
-
- endif
-
- HEX = $(CP) -O ihex
-
- BIN = $(CP) -O binary -S
-
-
-
- # default action: build all
-
- all: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
-
-
-
- $(BUILD_DIR)/%.hex: $(BUILD_DIR)/unstripped/bin/$(FILE_NAME).elf | $(BUILD_DIR)
-
- $(HEX) $< $@
-
-
-
- $(BUILD_DIR)/%.bin: $(BUILD_DIR)/unstripped/bin/$(FILE_NAME).elf | $(BUILD_DIR)
-
- $(BIN) $< $@
-
-
-
- $(BUILD_DIR):
-
- mkdir -p $@
-
-
-
- #######################################
- # clean up
- #######################################
-
- clean:
-
- -rm -fR $(BUILD_DIR)
-
-
-
- # *** EOF ***

3.5 设置产品根路径为.
- root@ubuntu:~/samba/code/test_prj# hb set
- [OHOS INFO] Input code path: .
选择对应的产品名称
3.6 编译错误及解决方法
3.6.1 undefined reference to
`__rt_libc_exit'
添加components\libc\compilers\common目录下的cstdlib.c
3.6.2 如果报错找不到end定义
需要在链接脚本link.lds中的__bss_end = .;下方添加相关定义
end = .;
3.6.3 如果需要打印浮点数,就要添加编译选项
"-Wl,-u_printf_float",
3.6.4 使用"-Wl,--gc-sections"
因为rtthread被编译成了静态库,用以下方式声明的函数可能不会被执行,这些源文件需要放在app目录下的构建文件中引用:
-
- #define INIT_BOARD_EXPORT(fn) INIT_EXPORT(fn, "1")
-
- /* pre/device/component/env/app init routines will be called in init_thread */
- /* components pre-initialization (pure software initialization) */
- #define INIT_PREV_EXPORT(fn) INIT_EXPORT(fn, "2")
- /* device initialization */
- #define INIT_DEVICE_EXPORT(fn) INIT_EXPORT(fn, "3")
- /* components initialization (dfs, lwip, ...) */
- #define INIT_COMPONENT_EXPORT(fn) INIT_EXPORT(fn, "4")
- /* environment initialization (mount disk, ...) */
- #define INIT_ENV_EXPORT(fn) INIT_EXPORT(fn, "5")
- /* application initialization (rtgui application etc ...) */
- #define INIT_APP_EXPORT(fn) INIT_EXPORT(fn, "6")
3.7 编译正常会有以下输出
- [OHOS INFO] [67/72] AR libs/libfwlib.a
- [OHOS INFO] [68/72] gcc cross compiler obj/kernel/rtthread/src/libos.kservice.o
- [OHOS INFO] [69/72] AR libs/libos.a
- [OHOS INFO] [70/72] LINK ./bin/app.elf
- [OHOS INFO] [71/72] ACTION //device/at32/at32f437:at32f437_app(//build/lite/toolchain:arm-none-eabi-gcc)
- [OHOS INFO] [72/72] STAMP obj/device/at32/at32f437/at32f437_app.stamp
- [OHOS INFO] /home/xxx/samba/code/test_prj/vendor/at32/at32f437/fs.yml not found, stop packing fs. If the product does not need to be packaged, ignore it.
- [OHOS INFO] at32_rtt_app build success
- [OHOS INFO] cost time: 0:00:02
3.8 目标文件
4 测试
4.1 测试程序
-
- /*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2022-05-16 shelton first version
- */
- #include <rtthread.h>
- #include <rtdevice.h>
- #include "drv_common.h"
- #include "drv_gpio.h"
-
- /* defined the led2 pin: pd13 */
- #define LED2_PIN GET_PIN(D, 13)
- /* defined the led3 pin: pd14 */
- #define LED3_PIN GET_PIN(D, 14)
- /* defined the led4 pin: pd15 */
- #define LED4_PIN GET_PIN(D, 15)
-
- int main(void)
- {
- rt_uint32_t speed = 500;
- /* set led2 pin mode to output */
- rt_pin_mode(LED2_PIN, PIN_MODE_OUTPUT);
- /* set led3 pin mode to output */
- rt_pin_mode(LED3_PIN, PIN_MODE_OUTPUT);
- /* set led4 pin mode to output */
- rt_pin_mode(LED4_PIN, PIN_MODE_OUTPUT);
-
- rt_pin_write(LED4_PIN, PIN_HIGH);
-
- float temp = 0.8;
-
- while (1)
- {
- uint8_t set_val[8]={0};
-
- sprintf(set_val,"%.1f",temp);
-
- temp += 0.1;
-
- if (temp>=1.2)
- {
- temp =0;
- }
-
- rt_kprintf("test openharmony[%s]\n",set_val);
-
- rt_pin_write(LED2_PIN, PIN_LOW);
- rt_pin_write(LED3_PIN, PIN_LOW);
- rt_thread_mdelay(speed);
- rt_pin_write(LED2_PIN, PIN_HIGH);
- rt_pin_write(LED3_PIN, PIN_HIGH);
- rt_thread_mdelay(speed);
- }
- }

5 总结
目前只是借助了openharmony的构建系统来搭建linux开发环境,还可以借助它的ACE LITE来开发显示屏项目,支持javascript脚本方式来搭建界面和逻辑.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。