开源地址:https://gitee.com/AT32437_OpenHarmony
1.学习本文档的意义
1.学习移植OpenHarmony轻量系统到AT32全系列mcu上,本文档移植的具体型号为AT32F437ZMT7
2.学习OpenHarmony轻量系统开发
2.移植前的准备工作
1.移植之前必须要先熟悉AT-START-F437开发板的使用,了解板子的裸机编程、板子裸机工程的默认调试串口。
2.获取到AT32F437的底层驱动源代码(Firmware Library)
2.0 熟悉AT32F437的裸机开发
1.雅特力提供了官方的开发工具AT32IDE
,下载地址:https://www.arterytek.com/cn/product/AT32F437.jsp#Resource

当然AT32F437也支持了Keil
和IAR
这个两个开发工具,但是这里我们使用AT32IDE
就足够了。
2.具体使用AT32IDE
开发AT32F437的步骤请参考雅特力提供的使用手册,笔者在创建第一个裸机工程437_led_printf时候发现默认的调试串口是PA9

3.通过分析裸机工程获取到要移植涉及的at32f437相关文件,这些都是移植需要的文件

2.1 安装源码对应的hb工具
使用什么版本的OpenHarmony的源码,就安装此版本源码对应的hb工具
3.轻量系统AT32F437芯片移植案例
3.1 目录规划
AT32F437基于Cortex-M4
,移植架构采用Board与SoC分离方案,使用arm-none-eabi-gcc
工具链(在轻量系统源码中可以指定编译工具链路径,具体可以查看 https://gitee.com/AT32437_OpenHarmony/arm-gnu-toolchain-12.3.rel1-x86_64-arm-none-eabi)
芯片适配目录规划为:
产品样例目录规划为:
3.2 预编译适配
预编译适配内容就是围绕hb set命令的适配,使工程能够通过该命令设置根目录、单板目录、产品目录、单板公司名等环境变量,为后续适配编译做准备。
具体的预编译适配步骤如下:
1.在vendor/artery/AT-START-F437目录下新增config.json文件,用于描述这个产品样例所使用的单板、内核等信息,描述信息可参考如下内容:
2.在/device/board/artery_board/atstartf437/liteos_m目录下新增一个config.gni文件,用于描述该产品的编译配置信息:
# Kernel type, e.g. "linux", "liteos_a", "liteos_m".
kernel_type = "liteos_m"
# 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 toolchain.
board_toolchain = "arm-none-eabi-gcc"
#use_board_toolchain = true
# The toolchain path installed, it's not mandatory if you have added toolchain 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 related common compile flags.
board_cflags = [ # cflag标志
"-mcpu=cortex-m4",
"-march=armv7e-m",
"-mthumb",
"-mfloat-abi=hard",
"-mfpu=fpv4-sp-d16",
"-O3", # gcc编译优化等级为-O3
"-fdata-sections",
"-ffunction-sections",
"-g",
"-DTRACE",
"-DAT_START_F437_V1", # 厂商提供sdk中说明需要添加的cflags标志
"-DOS_USE_TRACE_SEMIHOSTING_DEBUG",
"-DAT32F437ZMT7", # 厂商提供sdk中说明需要添加的cflags标志
"-DUSE_STDPERIPH_DRIVER", # 厂商提供sdk中说明需要添加的cflags标志
"-DEXTEND_SRAM=FLASH_EOPB0_SRAM_512K", # 厂商提供sdk中说明需要添加的cflags标志
"-std=c99",
]
board_cxx_flags = board_cflags
board_asmflags = []
board_ld_flags = [ # 链接选项,与厂商Makefile中的LDFLAGS变量对应。
"-Xlinker",
"--gc-sections",# 需要的Linker 配置
"--specs=nano.specs", # 为了使用printf函数
"--specs=nosys.specs", # 为了使用printf函数
"-Wl,--wrap=_calloc_r",
"-Wl,--wrap=_malloc_r",
"-Wl,--wrap=_realloc_r",
"-Wl,--wrap=_reallocf_r",
"-Wl,--wrap=_free_r",
"-Wl,--wrap=_memalign_r",
"-Wl,--wrap=_malloc_usable_size_r",
]
# Board related headfiles search path.
board_include_dirs = [
"//commonlibrary/utils_lite/include",
]
# 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 = ""
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
board_cpu
中指定芯片为cortex-m4系列mcu
board_toolchain
中指定编译工具链为"arm-none-eabi-gcc"
board_cflags
中添加编译标志,
- 需要添加裸机工程的构建目录的makefile中的链接标识
-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -g
,另外关于链接优化等级可以设置为-O3
- 还需要从裸机工程.cproject获取板级cflags
-DAT_START_F437_V1
、-DAT32F437ZMT7
、-DUSE_STDPERIPH_DRIVER
、-DEXTEND_SRAM=FLASH_EOPB0_SRAM_512K