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还不能运行,明天继续。

相关推荐
左手厨刀右手茼蒿2 天前
Flutter 三方库 all_lint_rules_community 的鸿蒙化适配指南 - 在鸿蒙系统上构建极致、严谨、基于全量社区 Lint 规则的工业级静态代码质量与安全审计引擎
flutter·harmonyos·鸿蒙·openharmony·all_lint_rules_community
王码码20352 天前
Flutter 三方库 servicestack 的鸿蒙化适配指南 - 实现企业级 Message-based 架构集成、支持强类型 JSON 序列化与跨端服务调用同步
flutter·harmonyos·鸿蒙·openharmony·message-based
里欧跑得慢2 天前
Flutter 三方库 jsonata_dart 的鸿蒙化适配指南 - 实现高性能的 JSON 数据查询与转换、支持 JSONata 表达式引擎与端侧复杂数据清洗
flutter·harmonyos·鸿蒙·openharmony·jsonata_dart
国医中兴2 天前
Flutter 三方库 superclass 的鸿蒙化适配指南 - 支持原生高性能类构造、属性代理与深层元数据解析实战
flutter·harmonyos·鸿蒙·openharmony
加农炮手Jinx3 天前
Flutter 组件 ubuntu_service 适配鸿蒙 HarmonyOS 实战:底层系统服务治理,构建鸿蒙 Linux 子系统与守护进程交互架构
flutter·harmonyos·鸿蒙·openharmony·ubuntu_service
王码码20353 天前
Flutter 三方库 login_client 的鸿蒙化适配指南 - 打造工业级安全登录、OAuth2 自动化鉴权、鸿蒙级身份守门员
flutter·harmonyos·鸿蒙·openharmony·login_client
国医中兴3 天前
Flutter 三方库 dson 的鸿蒙化适配指南 - 极简的序列化魔法、在鸿蒙端实现反射式 JSON 映射实战
flutter·harmonyos·鸿蒙·openharmony
国医中兴3 天前
Flutter 三方库 cloudflare_r2_uploader 的鸿蒙化适配指南 - 云端存储的疾速通道、在鸿蒙端实现 R2 分段上传实战
flutter·harmonyos·鸿蒙·openharmony·cloudflare_r2_uploader
国医中兴3 天前
Flutter 三方库 weaver 的鸿蒙化适配指南 - 玩转轻量级服务发现、在鸿蒙端实现模块化治理与解构实战
flutter·harmonyos·鸿蒙·openharmony
国医中兴3 天前
Flutter 三方库 tapper 的鸿蒙化适配指南 - 单元测试的“闪电侠”、在鸿蒙端实现极简函数式测试实战
flutter·harmonyos·鸿蒙·openharmony