当前位置:   article > 正文

开源鸿蒙适配AT32F437_快速适配openharmony

快速适配openharmony

1 openharmony
借助openharmony3.0的构建系统可以快速的搭建linux开发环境,总结一下AT32F437的适配过程

2 安装工具

2.1 安装gcc编译器
2.1.1 添加环境变量

  1. root@ubuntu:~/samba/tools# vim ~/.bashrc
  2. export PATH=$PATH:~/samba/tools/gcc-arm-none-eabi-10-2020-q4-major/bin

2.1.2 使变量生效

  1. root@ubuntu:~/samba/tools# source ~/.bashrc

2.1.3 查看gcc版本

  1. root@ubuntu:~/samba/tools# arm-none-eabi-gcc -v
  2. Thread model: single
  3. Supported LTO compression algorithms: zlib
  4. 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 安装依赖库

  1. root@ubuntu:~/samba/tools# apt-get install zlibc zlib1g-dev
  2. root@ubuntu:~/samba/tools# sudo apt-get install libffi-dev

2.2.3 编译并安装python

  1. root@ubuntu:~/samba/tools# cd Python-3.9.0b4/
  2. root@ubuntu:~/samba/tools/Python-3.9.0b4# ./configure --prefix=/usr
  3. root@ubuntu:~/samba/tools/Python-3.9.0b4# make
  4. root@ubuntu:~/samba/tools/Python-3.9.0b4# make install

2.2.4 解决错误

  1. root@ubuntu:~/samba/tools/Python-3.9.0b4#sudo find / -name 'lsb_release.py'
  2. root@ubuntu:~/samba/tools/Python-3.9.0b4#sudo cp
  3. /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

  1. root@ubuntu:~/samba/tools/Python-3.9.0b4# apt-get install python3-pip

查看版本号

  1. root@ubuntu:~/samba/tools/Python-3.9.0b4# pip3 -V
  2. WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
  3. Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
  4. To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
  5. 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
- 可能会报错

  1. 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版本

  1. pip3 install urllib3==1.26.15

3 添加产品源码
3.1 目录说明

 3.2 添加产品配置文件
在vendor下创建at32/at32f437目录,添加config.json文件

  1. {
  2. "product_name": "at32_rtt_app",
  3. "ohos_version": "OpenHarmony 3.0",
  4. "device_company": "at32",
  5. "board": "at32f437",
  6. "kernel_type": "rtthread",
  7. "kernel_version": "3.0.0",
  8. "subsystems": [
  9. {
  10. "subsystem": "kernel",
  11. "components": [
  12. { "component": "rtthread",
  13. "features":[
  14. ]
  15. }
  16. ]
  17. }
  18. ],
  19. "vendor_adapter_dir": "//device/at32/at32f437",
  20. "third_party_dir": "//third_party",
  21. "product_adapter_dir": "",
  22. "ohos_product_type":"",
  23. "ohos_manufacture":"",
  24. "ohos_brand":"",
  25. "ohos_market_name":"",
  26. "ohos_product_series":"",
  27. "ohos_product_model":"",
  28. "ohos_software_model":"",
  29. "ohos_hardware_model":"",
  30. "ohos_hardware_profile":"",
  31. "ohos_serial":"",
  32. "ohos_bootloader_version":"",
  33. "ohos_secure_patch_level":"",
  34. "ohos_abi_list":""
  35. }

3.3 添加固件库目录at32_lib

 在目录下添加构建脚本

  1. # Copyright (c) 2020 Huawei Device Co., Ltd.
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software
  9. # distributed under the License is distributed on an "AS IS" BASIS,
  10. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. # See the License for the specific language governing permissions and
  12. # limitations under the License.
  13. static_library("fwlib") {
  14. sources = [
  15. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_acc.c",
  16. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_adc.c",
  17. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_can.c",
  18. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_crc.c",
  19. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_crm.c",
  20. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_dac.c",
  21. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_debug.c",
  22. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_dma.c",
  23. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_emac.c",
  24. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_ertc.c",
  25. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_exint.c",
  26. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_flash.c",
  27. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_gpio.c",
  28. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_i2c.c",
  29. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_misc.c",
  30. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_pwc.c",
  31. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_qspi.c",
  32. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_scfg.c",
  33. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_sdio.c",
  34. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_spi.c",
  35. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_tmr.c",
  36. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_usart.c",
  37. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_usb.c",
  38. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_wdt.c",
  39. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_wwdt.c",
  40. "AT32F435_437_Firmware_Library/drivers/src/at32f435_437_xmc.c",
  41. ]
  42. include_dirs = [
  43. ".",
  44. "AT32F435_437_Firmware_Library/drivers/inc",
  45. "AT32F435_437_Firmware_Library/drivers/cmsis/cm4/core_support"
  46. ]
  47. }

3.4 添加设备配置文件

 3.4.1 rtthread
- rtconfig.h
添加RTOS配置文件
- config.gni
定义编译选项、宏定义等

  1. # Copyright (c) 2021 Huawei Device Co., Ltd.
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software
  9. # distributed under the License is distributed on an "AS IS" BASIS,
  10. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. # See the License for the specific language governing permissions and
  12. # limitations under the License.
  13. # Kernel type, e.g. "linux", "liteos_a", "liteos_m".
  14. kernel_type = "rtthread"
  15. # Kernel version.
  16. kernel_version = "3.0.0"
  17. # Board CPU type, e.g. "cortex-a7", "riscv32".
  18. board_cpu = "cortex-m4"
  19. # Board arch, e.g. "armv7-a", "rv32imac".
  20. board_arch = ""
  21. # Toolchain name used for system compiling.
  22. # E.g. gcc-arm-none-eabi, arm-linux-harmonyeabi-gcc, ohos-clang, riscv32-unknown-elf.
  23. # Note: The default toolchain is "ohos-clang". It's not mandatory if you use the default toochain.
  24. board_toolchain = "arm-none-eabi-gcc"
  25. # The toolchain path instatlled, it's not mandatory if you have added toolchian path to your ~/.bashrc.
  26. board_toolchain_path = ""
  27. # Compiler prefix.
  28. board_toolchain_prefix = "arm-none-eabi-"
  29. # Compiler type, "gcc" or "clang".
  30. board_toolchain_type = "gcc"
  31. board_outtype = "boot"
  32. # Board related common compile flags.
  33. board_cflags = [
  34. "-mfpu=fpv4-sp-d16",
  35. "-mfloat-abi=hard",
  36. "-mthumb",
  37. "-Os",
  38. "-ffunction-sections",
  39. "-fdata-sections",
  40. ]
  41. board_cxx_flags = board_cflags
  42. out_dir = rebase_path(root_build_dir)
  43. board_macro_defines = [
  44. "__STDC_LIMIT_MACROS",
  45. "RT_USING_ARMLIBC",
  46. "RT_USING_LIBC",
  47. "AT32F437ZMT7",
  48. "AT_START_F437_V1",
  49. "USE_STDPERIPH_DRIVER",
  50. "__CLK_TCK=RT_TICK_PER_SECOND",
  51. "__RTTHREAD__",
  52. "RT_USING_ARM_LIBC",
  53. ]
  54. out_dir = rebase_path(root_build_dir)
  55. board_default_path = [
  56. "-L${out_dir}/libs"
  57. ]
  58. board_ld_flags = [
  59. "-nostartfiles",
  60. "--specs=nano.specs",
  61. "--specs=nosys.specs",
  62. "-Wl,--gc-sections",
  63. "-Wl,-Map=${out_dir}/test.map",
  64. "-Wl,-rpath-link=${out_dir}",
  65. "-Wl,-u_printf_float",
  66. ]
  67. # Board related headfiles search path.
  68. board_include_dirs = [
  69. "//vendor/at32/at32f437/at32_lib/AT32F435_437_Firmware_Library/cmsis/cm4/core_support",
  70. "//vendor/at32/at32f437/at32_lib/AT32F435_437_Firmware_Library/cmsis/cm4/device_support",
  71. ]
  72. # Board adapter dir for OHOS components.
  73. board_adapter_dir = ""
  74. # Sysroot path.
  75. board_configed_sysroot = ""
  76. # Board storage type, it used for file system generation.
  77. storage_type = ""

3.4.2 BUILD.gn
添加构建脚本,定义要编译的APP目录

  1. # Copyright (c) 2021 Huawei Device Co., Ltd.
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software
  9. # distributed under the License is distributed on an "AS IS" BASIS,
  10. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. # See the License for the specific language governing permissions and
  12. # limitations under the License.
  13. import("//build/lite/config/component/lite_component.gni")
  14. group("at32f437") {
  15. }
  16. build_ext_component("at32f437_app") {
  17. exec_path = rebase_path(".", root_build_dir)
  18. outdir = rebase_path("$root_out_dir")
  19. print("$board_toolchain")
  20. command = "./build.sh ${outdir}"
  21. deps = [
  22. "//applications/app:app",
  23. ]
  24. }

3.4.3 添加Makefile
定义要输出的目标文件

  1. ##########################################################################################################################
  2. # File automatically-generated by tool: [projectgenerator] version: [3.13.0-B3] date: [Fri Apr 30 08:31:16 CST 2021]
  3. ##########################################################################################################################
  4. # ------------------------------------------------
  5. # Generic Makefile (based on gcc)
  6. #
  7. # ChangeLog :
  8. # 2017-02-10 - Several enhancements + project update mode
  9. # 2015-07-22 - first version
  10. # ------------------------------------------------
  11. ######################################
  12. # target
  13. ######################################
  14. TARGET = at32f437_app
  15. FILE_NAME = app
  16. BUILD_DIR = $(OUT_DIR_PATH)
  17. #######################################
  18. # toolchain paths
  19. #######################################
  20. # Toolchain path
  21. ifneq ($(TOOLCHAIN_DIR_PATH), )
  22. GCC_PATH = $(TOOLCHAIN_DIR_PATH)
  23. endif
  24. #######################################
  25. # binaries
  26. #######################################
  27. PREFIX = arm-none-eabi-
  28. # The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
  29. # either it can be added to the PATH environment variable.
  30. ifneq ($(GCC_PATH), )
  31. CC = $(GCC_PATH)/$(PREFIX)gcc
  32. AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
  33. CP = $(GCC_PATH)/$(PREFIX)objcopy
  34. SZ = $(GCC_PATH)/$(PREFIX)size
  35. else
  36. CC = $(PREFIX)gcc
  37. AS = $(PREFIX)gcc -x assembler-with-cpp
  38. CP = $(PREFIX)objcopy
  39. SZ = $(PREFIX)size
  40. endif
  41. HEX = $(CP) -O ihex
  42. BIN = $(CP) -O binary -S
  43. # default action: build all
  44. all: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
  45. $(BUILD_DIR)/%.hex: $(BUILD_DIR)/unstripped/bin/$(FILE_NAME).elf | $(BUILD_DIR)
  46. $(HEX) $< $@
  47. $(BUILD_DIR)/%.bin: $(BUILD_DIR)/unstripped/bin/$(FILE_NAME).elf | $(BUILD_DIR)
  48. $(BIN) $< $@
  49. $(BUILD_DIR):
  50. mkdir -p $@
  51. #######################################
  52. # clean up
  53. #######################################
  54. clean:
  55. -rm -fR $(BUILD_DIR)
  56. # *** EOF ***

3.5 设置产品根路径为.

  1. root@ubuntu:~/samba/code/test_prj# hb set
  2. [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目录下的构建文件中引用:

  1. #define INIT_BOARD_EXPORT(fn) INIT_EXPORT(fn, "1")
  2. /* pre/device/component/env/app init routines will be called in init_thread */
  3. /* components pre-initialization (pure software initialization) */
  4. #define INIT_PREV_EXPORT(fn) INIT_EXPORT(fn, "2")
  5. /* device initialization */
  6. #define INIT_DEVICE_EXPORT(fn) INIT_EXPORT(fn, "3")
  7. /* components initialization (dfs, lwip, ...) */
  8. #define INIT_COMPONENT_EXPORT(fn) INIT_EXPORT(fn, "4")
  9. /* environment initialization (mount disk, ...) */
  10. #define INIT_ENV_EXPORT(fn) INIT_EXPORT(fn, "5")
  11. /* application initialization (rtgui application etc ...) */
  12. #define INIT_APP_EXPORT(fn) INIT_EXPORT(fn, "6")

3.7 编译正常会有以下输出

  1. [OHOS INFO] [67/72] AR libs/libfwlib.a
  2. [OHOS INFO] [68/72] gcc cross compiler obj/kernel/rtthread/src/libos.kservice.o
  3. [OHOS INFO] [69/72] AR libs/libos.a
  4. [OHOS INFO] [70/72] LINK ./bin/app.elf
  5. [OHOS INFO] [71/72] ACTION //device/at32/at32f437:at32f437_app(//build/lite/toolchain:arm-none-eabi-gcc)
  6. [OHOS INFO] [72/72] STAMP obj/device/at32/at32f437/at32f437_app.stamp
  7. [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.
  8. [OHOS INFO] at32_rtt_app build success
  9. [OHOS INFO] cost time: 0:00:02

3.8 目标文件

 4 测试
4.1 测试程序

  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-05-16 shelton first version
  9. */
  10. #include <rtthread.h>
  11. #include <rtdevice.h>
  12. #include "drv_common.h"
  13. #include "drv_gpio.h"
  14. /* defined the led2 pin: pd13 */
  15. #define LED2_PIN GET_PIN(D, 13)
  16. /* defined the led3 pin: pd14 */
  17. #define LED3_PIN GET_PIN(D, 14)
  18. /* defined the led4 pin: pd15 */
  19. #define LED4_PIN GET_PIN(D, 15)
  20. int main(void)
  21. {
  22. rt_uint32_t speed = 500;
  23. /* set led2 pin mode to output */
  24. rt_pin_mode(LED2_PIN, PIN_MODE_OUTPUT);
  25. /* set led3 pin mode to output */
  26. rt_pin_mode(LED3_PIN, PIN_MODE_OUTPUT);
  27. /* set led4 pin mode to output */
  28. rt_pin_mode(LED4_PIN, PIN_MODE_OUTPUT);
  29. rt_pin_write(LED4_PIN, PIN_HIGH);
  30. float temp = 0.8;
  31. while (1)
  32. {
  33. uint8_t set_val[8]={0};
  34. sprintf(set_val,"%.1f",temp);
  35. temp += 0.1;
  36. if (temp>=1.2)
  37. {
  38. temp =0;
  39. }
  40. rt_kprintf("test openharmony[%s]\n",set_val);
  41. rt_pin_write(LED2_PIN, PIN_LOW);
  42. rt_pin_write(LED3_PIN, PIN_LOW);
  43. rt_thread_mdelay(speed);
  44. rt_pin_write(LED2_PIN, PIN_HIGH);
  45. rt_pin_write(LED3_PIN, PIN_HIGH);
  46. rt_thread_mdelay(speed);
  47. }
  48. }

5 总结
目前只是借助了openharmony的构建系统来搭建linux开发环境,还可以借助它的ACE LITE来开发显示屏项目,支持javascript脚本方式来搭建界面和逻辑.

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号