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/icon-default.png?t=N7T8https://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:  (defined at arch/arm/Kconfig:34) defined with type unknown

根据错误提示并找不到问题在哪,
最后发现Makefile需要/vendor/demo/hello/kernel_configs/debug.config文件,空文件就行。

STM32F407移植OpenHarmony笔记4_第1张图片

进入Platform选择 Soc和stm32f407。

STM32F407移植OpenHarmony笔记4_第2张图片

Compat菜单下,选择newlibc 

STM32F407移植OpenHarmony笔记4_第3张图片

配置完菜单后,配置保存在.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

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

你可能感兴趣的:(学习笔记,MCU,OpenHarmony,STM32F407)