STM32F407移植OpenHarmony笔记4

上一篇写到make menuconfig报错,继续开整。

make menuconfig需要/device/soc/*下面有对应的Kconfig文件。

直接去gitee下载stm32的配置文件拿来参考用。

先提取Kconfig文件,后面再添加其它文件。https://gitee.com/openharmony/device_soc_st/tree/OpenHarmony-v3.2-Beta5/https://gitee.com/openharmony/device_soc_st/tree/OpenHarmony-v3.2-Beta5/

soc下的目录结构如下:

复制代码
└── soc
    └── st
        ├── Kconfig.liteos_m.defconfig
        ├── Kconfig.liteos_m.series
        ├── Kconfig.liteos_m.soc
        └── stm32f4xx
            ├── Kconfig.liteos_m.defconfig.series
            ├── Kconfig.liteos_m.defconfig.stm32f4xx
            ├── Kconfig.liteos_m.series
            └── Kconfig.liteos_m.soc

Kconfig.liteos_m.soc会在菜单里添加st这个SOC_COMPANY

还会扫描子目录下的Kconfig.liteos_m.soc,

在stm32f4xx子目录下面的这个文件又向菜单添加SOC_STM32F407

Kconfig.liteos_m.series扫描子目录下的同名文件,

在stm32f4xx子目录里的这个文件又向菜单添加SOC_SERIES_STM32F4xx


再次测试make menuconfig还是会报错:

复制代码
warning: <choice> (defined at arch/arm/Kconfig:34) defined with type unknown

根据错误提示并找不到问题在哪,

最后发现Makefile需要/vendor/demo/hello/kernel_configs/debug.config文件,空文件就行。

进入Platform选择 Soc和stm32f407。

Compat菜单下,选择newlibc

配置完菜单后,配置保存在.config,并生成config.h文件,

同时还会向/vendor/demo/hello/kernel_configs/debug.config写入一部分配置内容。


再次编译看看报什么错:

复制代码
[OHOS INFO] ERROR at //kernel/liteos_m/BUILD.gn:140:18: Unable to load "/home/openharmony/device/board/demo/BUILD.gn".

根据错误,添加BUILD.gn

复制代码
# /device/board/demo/BUILD.gn
# https://kerndev.blog.csdn.net/

import("//kernel/liteos_m/liteos.gni")
module_name = get_path_info(rebase_path("."), "name")
module_group(module_name) {
    modules = [ "demo_board" ]
}

再次测试,继续根据错误提示,添加以下文件:

复制代码
/home/openharmony/device/soc/st/BUILD.gn
/home/openharmony/device/soc/st/stm32f4xx/BUILD.gn
/home/openharmony/device/board/demo/demo_board/BUILD.gn
/home/openharmony/vendor/demo/hello/BUILD.gn
/home/openharmony/device/soc/st/stm32f4xx/sdk/BUILD.gn
/home/openharmony/device/soc/st/stm32f4xx/sdk/Drivers
/home/openharmony/device/soc/st/stm32f4xx/sdk/hals

然后再次编译错误是:

复制代码
[OHOS ERROR] ../../../device/soc/st/stm32f4xx/sdk/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c:302:10: fatal error: stm32f4xx_hal.h: No such file or directory
[OHOS ERROR]   302 | #include "stm32f4xx_hal.h"
[OHOS ERROR]       |          ^~~~~~~~~~~~~~~~~
[OHOS ERROR] compilation terminated.

这个问题就是BUILD.gn里面没有正确配置include的路径。

打开bsp/BUILD.gn抄一段config():

复制代码
config("public") {
  defines = [
    "STM32F407xx",
    "STM32F40_41xxx",
  ]
  include_dirs = [
    "include",
    "//device/soc/st/stm32f4xx/sdk/Core/Inc",
    "//device/soc/st/stm32f4xx/sdk/Drivers/STM32F4xx_HAL_Driver/Inc",
    "//device/soc/st/stm32f4xx/sdk/Drivers/CMSIS/Device/ST/STM32F4xx/Include",
    "//foundation/systemabilitymgr/samgr_lite/interfaces/kits/samgr",
  ]
  ldflags = [
    "-Wl,-T" + rebase_path("ld/STM32F407IG_FLASH.ld"),
    "-Wl,-u_printf_float",
  ]
  libs = [
    "c",
    "m",
    "nosys",
  ]
}

这里面有defines预定义2个宏,include_dirs添加头文件路径,

ldflags定义链接脚本路径,libs添加要链接的基本库。


再次编译报错,还要添加/device/demo/demo_board/liteos_m/bsp/include/target_config.h文件。

复制代码
[OHOS ERROR] ../../../kernel/liteos_m/kernel/include/los_config.h:40:10: fatal error: target_config.h: No such file or directory
[OHOS ERROR]    40 | #include "target_config.h"
[OHOS ERROR]       |          ^~~~~~~~~~~~~~~~~
[OHOS ERROR] compilation terminated.

再次编译报错:bool没定义,这个问题就不是我们的配置问题了,

把源码里的bool改为int,或者在源码内#include <stdbool.h>

复制代码
[OHOS ERROR] ../../../kernel/liteos_m/components/fs/vfs/vfs_fs.c:214:43: error: unknown type name 'bool'
[OHOS ERROR]   214 | static int VfsPathCheck(const char *path, bool isFile)

再次编译找不到STM32F407IG_FLASH.ld文件,按提示添加这个文件。

最后再次编译通过:

复制代码
[OHOS INFO] ---------------------------------------------
[OHOS INFO] ccache summary:
[OHOS INFO] cache hit (direct)  : 0
[OHOS INFO] cache hit (preprocessed)  : 0
[OHOS INFO] cache miss  : 0
[OHOS INFO] hit rate:  0.00% 
[OHOS INFO] mis rate: 0.00% 
[OHOS INFO] ---------------------------------------------
[OHOS INFO] c targets overlap rate statistics
[OHOS INFO] subsystem           files NO.       percentage      builds NO.      percentage      overlap rate
[OHOS INFO] kernel                    48        40.3%         48        40.3%   1.00
[OHOS INFO] securec                   39        32.8%         39        32.8%   1.00
[OHOS INFO] third_party               40        33.6%         40        33.6%   1.00
[OHOS INFO] thirdparty                40        33.6%         40        33.6%   1.00
[OHOS INFO] 
[OHOS INFO] c overall build overlap rate: 1.00
[OHOS INFO] 
[OHOS INFO] 
[OHOS INFO] hello build success
[OHOS INFO] cost time: 0:00:03
root@86cd4274494f:/home/openharmony# 

虽然编译通过,但产生的OHOS_Image.bin还不能运行,明天继续。

相关推荐
nullregedit8 天前
OpenHarmony 小鸿 AI 开发实战 10:CI1302 语音上行的 UART 帧、Opus 与 VAD
openharmony·语音交互·开源鸿蒙·ws63·ci1302
nullregedit12 天前
OpenHarmony 小鸿 AI 开发实战 04:WS63 BurnTool 烧录、Loader、导出与回滚
openharmony·嵌入式开发·开源鸿蒙·ws63·burntool
nullregedit12 天前
OpenHarmony 小鸿 AI 开发实战 05:烧录成功仍黑屏的 GPIO14/PWR_ON 故障复盘
openharmony·gpio·故障排查·开源鸿蒙·ws63
nullregedit13 天前
OpenHarmony 小鸿 AI 开发实战 01:先认对工程,WS63 与 ESP32-P4 路径怎么选
openharmony·嵌入式开发·开源鸿蒙·esp32-p4·ws63
北京麟卓20 天前
卓奕引擎×OrangePi 5B开发板 | 面向开源鸿蒙的一站式安卓兼容验证方案
openharmony·安卓应用兼容
Industio_触觉智能22 天前
开源鸿蒙OpenHarmony再进阶,OneConnect规范即将升级为国家级行业标准
嵌入式硬件·物联网·硬件架构·智能硬件·openharmony·开源鸿蒙
北京麟卓23 天前
鸿蒙平板生态建设遇阻?卓奕引擎:安卓应用快速迁移+迁移成本直降80%以上
openharmony·安卓兼容
Industio_触觉智能2 个月前
瑞芯微RK3576落地智能农业新生态,鸿蒙农机平板应用场景拓展
嵌入式硬件·openharmony·开源鸿蒙·核心板·鸿蒙开发板·rk3576·农机平板
fakerth2 个月前
【OpenHarmony】communication_ipc模块
操作系统·openharmony
IOT那些事儿2 个月前
STM32F407测量1MHz波形频率
tim·stm32f407·脉冲捕获