记录一下移植openharmony到STM32H743IIT6的过程
一、用STM32CubeMX生成一个makefile的工程
选择第一个创建工程
选择对应的芯片,这里我用的是stm32h743的野火的开发板
移植现象以点亮led为例,选择点亮led的引脚为输出模式,其他默认
这一步看个人习惯吧,默认不管也可以
选择工具链为makefile,如果对时钟有需求可以在Clock Configuration选项修改,我这里直接默认生成了
二、搭建系统环境
要用虚拟机ubuntu编译,具体配置命令可以参考华为官方教程: https://device.harmonyos.com/cn/docs/documentation/guide/quickstart-lite-package-environment-0000001105407498.
(20.04版本有很多bug,安装工具时会提示各种依赖,就很烦,而且我个人也解决不了,所以就改用的18版本)
18版本下载地址
因为鸿蒙源码比较大,安装ubuntu时虚拟硬盘最好搞大点,我这里直接给了100G
如果安装的过程中提示没有某个工具,那就按照ubuntu的提示安装就好了,类似:
安装hb需要python3.8以上版本,我的3.6会提示这个错误:
安装python3.8:
sudo apt install python3.8
python3.8 --version #检验是否安装成功
python3.8 -m pip install --user ohos-build #把上面的python3改成python3.8
实际上最主要的目的就是安装hb,安装好后执行hb -h命令,如出现以下信息则安装成功:
20版本的话会提示各种依赖的问题,如果解决不了就换18版本吧。除了会提示工具缺少需要安装外,应该就没有其他问题了
三、用vscode连接虚拟机
为了方便代码编写,直接在主机端用vscode连接虚拟机,怎么连接的可以参考:
vscode使用ssh连接远程Ubuntu服务器
四、下载openharmony3.0源码
可以按官方的教程用git下载,也可以直接从镜像站点下载,看个人喜好了。
我是从镜像站点下载的。
1、官方教程git下载
2、镜像站点下载
下好源码后通过共享文件放到ubuntu里面,或者你直接在ubuntu里面下也行。
注意先别解压
将源码压缩包复制到新建的openharmony目录下后再解压
cp code-v3.0-LTS.tar.gz ~/openharmony
tar -zxvf code-v3.0-LTS.tar.gz #在~/openharmony目录下解压
这里推荐用FileZilla软件:下载地址
连接后就可以在Windows和ubuntu之间方便快捷的传输文件了
再用vscode连接虚拟机后,就可以打开源码目录了:
子目录代表的含义:
五、移植准备
注:参考了华为官方文档内容,如果对细节部分更感兴趣可以直接去看官方文档:https://device.harmonyos.com/cn/docs/documentation/guide/porting-chip-prepare-knows-0000001064030766
目录规范
HarmonyOS整体工程较为复杂,我们只是简单的移植,不涉及复杂的特性增强,只需要重点关注如下目录即可:
目录名称 | 描述 |
---|---|
/build/lite | HarmonyOS基础编译构建框架 |
/kernel/liteos_m | 基础内核,其中芯片架构相关实现在arch目录下 |
/device | 板级相关实现,各个三方厂商按照HarmonyOS规范适配实现 |
/vendor | 产品级相关实现,主要由华为或者产品厂商贡献 |
其中我们要配置的就是device和vendor目录
目录结构和具体描述如下:
├── device --- 单板样例
│ └── xxx --- <单板厂商名>
│ └── xxx --- <单板名>,里面包含liteos-m内核的,并且能够运行的demo
│ ├── BUILD.gn --- 定义单板的编译配置文件
│ ├── board --- 板子特定的实现(可选,如果本单板直接提供产品级demo,则相关应用层实现放在此目录)
│ ├── liteos_m --- 根据BUILD.gn文件中的kernel_type,使用liteos_m内核
│ │ └── config.gni --- 编译选项
│ ├── libraries --- 板级SDK
│ │ └── include --- SDK提供对外头文件
│ │ └── ... --- binary or source
│ ├── main.c --- main函数入口(如果产品级存在相同定义,则使用产品级配置)
│ ├── target_config.h --- 板级内核配置
│ ├── project --- 单板级工程配置文件(如果产品级存在相同定义,则使用产品级配置)
│ └── adapter --- 单板适配上层应用组件的适配层接口,根据能力可选
│ └── hals
│ ├── communication
│ │ └── wifi_lite
│ │ ├── ...
│ └── iot_hardware
│ ├── upgrade
│ ├── utils
│ └── wifiiot_lite
├── vendor --- 提供端到端的HarmonyOS特性产品样例
│ └── huawei --- 厂商名字
│ └── wifiiot --- wifiiot表示特性产品
│ ├── app
│ │ └── main.c --- 产品的main函数入口
│ ├── project --- 工程配置文件
│ ├── BUILD.gn --- 工程编译入口
│ └── config.json --- 定义产品的编译配置文件,配置产品所使用的组件等。
└── out --- 编译过程中的输出目录
├── ... --- 单板/产品编译产生的bin等
根据上述目录规范要求规范文件夹:
device/厂商名称/单板名
vendor/厂商名称/单板名
把第一步stm32cubemx生成的工程文件全部放到 /device/st/stm32h743_harmony 里,顺便把vendor的目录也创建好
板级 device 配置
编译工具链和编译选项配置
在代码根目录 /device/st/stm32h743_harmony 里新建 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".(开发板CPU类型)
board_cpu = "cortex-m7"
# Board arch, e.g. "armv7-a", "rv32imac".(开发芯片arch)
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 toochain.
#(开发板自定义的编译工具链名称)
board_toolchain = "arm-none-eabi-gcc"
# The toolchain path instatlled, it's not mandatory if you have added toolchian 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.(开发板配置的c文件编译选项)
board_cflags = [
"-mcpu=cortex-m7",
"-mfpu=fpv5-d16",
"-mfloat-abi=soft",
"-mthumb",
"-Og",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-DUSE_HAL_DRIVER", #看情况修改 (Makefile里C_DEFS的配置)
"-DSTM32H743xx", #看情况修改
]
#(开发板配置的cpp文件编译选项)
board_cxx_flags = board_cflags
#(开发板配置的链接选项)
board_ld_flags = []
# Board related headfiles search path.(头文件路径)
board_include_dirs = [
"//kernel/liteos_m/kernel/arch/arm/cortex-m7/gcc",
"//device/st/stm32h743",
"//device/st/stm32h743/Core/Inc",
"//device/st/stm32h743/Drivers/CMSIS/Include",
"//device/st/stm32h743/Drivers/CMSIS/Device/ST/STM32H7xx/Include",
"//device/st/stm32h743/Drivers/STM32H7xx_HAL_Driver/Inc",
"//device/hisilicon/hispark_pegasus/hi3861_adapter/kal/cmsis",
]
# 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 = ""
编译脚本配置
新增的开发板,对应目录下需要新增BUILD.gn文件作为开发板编译的总入口
首先是根目录下的BUILD.gn:
import("//build/lite/config/component/lite_component.gni")
group("stm32h743_harmony") {
}
build_ext_component("stm32h743_harmony_ninjia") {
exec_path = rebase_path(".", root_build_dir)
outdir = rebase_path("$root_out_dir")
if (board_toolchain_path != "") {
toolchain_path = rebase_path("$board_toolchain_path")
command = "./build.sh ${outdir} ${toolchain_path}"
} else {
command = "./build.sh ${outdir}"
}
deps = [ "//build/lite:ohos" ]
}
static_library("startup_stm32h743xx") {
sources = [ "startup_stm32h743xx.s" ]
include_dirs = [ "." ]
deps = [
"//device/st/stm32h743_harmony/Core:core",
"//device/st/stm32h743_harmony/Drivers/STM32H7xx_HAL_Driver:STM32H7xx_HAL_Driver",
]
}
group直接写文件夹名
build_ext_component自定义,但是要与Makefile文件里有效代码第一行TARGET一致
sources 为stm32cubemx生成的.s文件的名称
deps 为下级gn文件列表
接着是Drivers\STM32H7xx_HAL_Driver下的BUILD.gn:
static_library("STM32H7xx_HAL_Driver") {
sources = [
"Src/stm32h7xx_hal_cortex.c",
"Src/stm32h7xx_hal_dma_ex.c",
"Src/stm32h7xx_hal_dma.c",
"Src/stm32h7xx_hal_exti.c",
"Src/stm32h7xx_hal_flash.c",
"Src/stm32h7xx_hal_flash_ex.c",
"Src/stm32h7xx_hal_gpio.c",
"Src/stm32h7xx_hal_hsem.c",
"Src/stm32h7xx_hal_i2c_ex.c",
"Src/stm32h7xx_hal_i2c.c",
"Src/stm32h7xx_hal_mdma.c",
"Src/stm32h7xx_hal_pwr_ex.c",
"Src/stm32h7xx_hal_pwr.c",
"Src/stm32h7xx_hal_rcc_ex.c",
"Src/stm32h7xx_hal_rcc.c",
"Src/stm32h7xx_hal_tim_ex.c",
"Src/stm32h7xx_hal_tim.c",
"Src/stm32h7xx_hal.c",
]
include_dirs = [
"Inc",
"Inc/Legacy",
"../CMSIS/Include",
"../CMSIS/Device/ST/STM32H7xx/Include",
"../../Core/Inc",
]
}
sources 为此目录下的.c文件
include_dirs为头文件路径
最后是 \Core 下的BUILD.gn:
static_library("core") {
sources = [
"Src/main.c",
"Src/gpio.c",
"Src/stm32h7xx_hal_msp.c",
"Src/stm32h7xx_it.c",
"Src/system_stm32h7xx.c",
]
include_dirs = [
"Inc",
"../",
"../Drivers/STM32H7xx_HAL_Driver/Inc",
"../Drivers/STM32H7xx_HAL_Driver/Inc/Legacy",
"../Drivers/CMSIS/Include",
"../Drivers/CMSIS/Device/ST/STM32H7xx/Include",
"//kernel/liteos_m/kernel/include",
"//kernel/liteos_m/utils",
"//kernel/liteos_m/kal/cmsis",
"//kernel/liteos_m/kernel/arch/include",
]
}
同理,sources 为此目录下的.c文件
include_dirs为头文件路径
总共3个gn
Makefile配置
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [3.15.2] date: [Thu Jan 20 16:37:40 CST 2022]
##########################################################################################################################
# ------------------------------------------------
# Generic Makefile (based on gcc)
#
# ChangeLog :
# 2017-02-10 - Several enhancements + project update mode
# 2015-07-22 - first version
# ------------------------------------------------
######################################
# target
######################################
TARGET = stm32h743_harmony_ninjia #改成与同级目录下的BUILD.gn里的build_ext_component一致
######################################
# building variables
######################################
# debug build?
DEBUG = 1
# optimization
OPT = -Og
#######################################
# paths
#######################################
# Build path
BUILD_DIR = build
######################################
# source
######################################
# C sources
C_SOURCES = \
Core/Src/main.c \
Core/Src/stm32h7xx_it.c \
Core/Src/stm32h7xx_hal_msp.c \
Core/Src/system_stm32h7xx.c \
Core/Src/gpio.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim_ex.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc_ex.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash_ex.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_gpio.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_hsem.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma_ex.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mdma.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr_ex.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c_ex.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_exti.c
# ASM sources
ASM_SOURCES = \
startup_stm32h743xx.s
#######################################
# binaries
#######################################
PREFIX = arm-none-eabi-
# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
# either it can be added to the PATH environment variable.
ifdef GCC_PATH
CC = $(GCC_PATH)/$(PREFIX)gcc
AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
CP = $(GCC_PATH)/$(PREFIX)objcopy
SZ = $(GCC_PATH)/$(PREFIX)size
else
CC = $(PREFIX)gcc
AS = $(PREFIX)gcc -x assembler-with-cpp
CP = $(PREFIX)objcopy
SZ = $(PREFIX)size
endif
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S
#######################################
# CFLAGS
#######################################
# cpu
CPU = -mcpu=cortex-m7
# fpu
FPU = -mfpu=fpv5-d16
# float-abi
FLOAT-ABI = -mfloat-abi=hard
# mcu
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
# macros for gcc
# AS defines
AS_DEFS =
# C defines
C_DEFS = \
-DUSE_HAL_DRIVER \
-DSTM32H743xx
# AS includes
AS_INCLUDES =
# C includes
C_INCLUDES = \
-ICore/Inc \
-IDrivers/STM32H7xx_HAL_Driver/Inc \
-IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy \
-IDrivers/CMSIS/Device/ST/STM32H7xx/Include \
-IDrivers/CMSIS/Include
# compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2
endif
# Generate dependency information
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
#######################################
# LDFLAGS
#######################################
# link script
LDSCRIPT = STM32H743IITx_FLASH.ld
# libraries
LIBS = -lc -lm -lnosys
LIBDIR =
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
# default action: build all
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
#######################################
# build the application
#######################################
# list of objects
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))
# list of ASM program objects
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
vpath %.s $(sort $(dir $(ASM_SOURCES)))
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
$(AS) -c $(CFLAGS) $< -o $@
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
$(SZ) $@
$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(HEX) $< $@
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(BIN) $< $@
$(BUILD_DIR):
mkdir $@
#######################################
# clean up
#######################################
clean:
-rm -fR $(BUILD_DIR)
#######################################
# dependencies
#######################################
-include $(wildcard $(BUILD_DIR)/*.d)
# *** EOF ***
build.sh配置
在代码根目录 /device/st/stm32h743_harmony 里新建build.sh文件:
#!/bin/bash
set -e
OUT_DIR="$1"
TOOLCHAIN_DIR="$2"
function main(){
ROOT_DIR=$(cd $(dirname "$0");pwd)
if [ -z "${TOOLCHAIN_DIR}" ]; then
make clean && make -j16 OUT_DIR_PATH=${OUT_DIR}
else
make clean && make -j16 OUT_DIR_PATH=${OUT_DIR} TOOLCHAIN_DIR_PATH=${TOOLCHAIN_DIR}
fi
}
main "$@"
内核特性配置项 target_config.h
liteos_m的完整配置能力及默认配置在los_config.h定义,该头文件中的配置项可以根据不同的单板进行裁剪配置。
要进行不同的板级配置,则可将对应的配置项直接定义到对应单板的device/xxxx/target_config.h文件中,其他未定义的配置项,采用los_config.h中的默认值。
在代码根目录下创建 target_config.h 文件
#ifndef _TARGET_CONFIG_H
#define _TARGET_CONFIG_H
#include "stm32h7xx.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/*=============================================================================
System clock module configuration
=============================================================================*/
#define OS_SYS_CLOCK SystemCoreClock
#define LOSCFG_BASE_CORE_TICK_PER_SECOND (1000UL)
#define LOSCFG_BASE_CORE_TICK_HW_TIME 0
#define LOSCFG_BASE_CORE_TICK_WTIMER 0
#define LOSCFG_BASE_CORE_TICK_RESPONSE_MAX SysTick_LOAD_RELOAD_Msk
/*=============================================================================
Hardware interrupt module configuration
=============================================================================*/
#define LOSCFG_PLATFORM_HWI 1
#define LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT 1
#define LOSCFG_PLATFORM_HWI_LIMIT 128
/*=============================================================================
Task module configuration
=============================================================================*/
#define LOSCFG_BASE_CORE_TSK_LIMIT 24
#define LOSCFG_BASE_CORE_TSK_IDLE_STACK_SIZE (0x500U)
#define LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE (0x2D0U)
#define LOSCFG_BASE_CORE_TSK_MIN_STACK_SIZE (0x130U)
#define LOSCFG_BASE_CORE_TIMESLICE 1
#define LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT 20000
/*=============================================================================
Semaphore module configuration
=============================================================================*/
#define LOSCFG_BASE_IPC_SEM 1
#define LOSCFG_BASE_IPC_SEM_LIMIT 48
/*=============================================================================
Mutex module configuration
=============================================================================*/
#define LOSCFG_BASE_IPC_MUX 1
#define LOSCFG_BASE_IPC_MUX_LIMIT 24
/*=============================================================================
Queue module configuration
=============================================================================*/
#define LOSCFG_BASE_IPC_QUEUE 1
#define LOSCFG_BASE_IPC_QUEUE_LIMIT 24
/*=============================================================================
Software timer module configuration
=============================================================================*/
#define LOSCFG_BASE_CORE_SWTMR 1
#define LOSCFG_BASE_CORE_SWTMR_ALIGN 0
#define LOSCFG_BASE_CORE_SWTMR_LIMIT 48
/*=============================================================================
Memory module configuration
=============================================================================*/
#define LOSCFG_MEM_MUL_POOL 1
#define OS_SYS_MEM_NUM 20
/*=============================================================================
Exception module configuration
=============================================================================*/
#define LOSCFG_PLATFORM_EXC 1
/* =============================================================================
printf module configuration
============================================================================= */
#define LOSCFG_KERNEL_PRINTF 1
#define LOSCFG_BASE_CORE_SCHED_SLEEP 1
#define LOSCFG_SYS_HEAP_SIZE 0x4000UL
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _TARGET_CONFIG_H */
main函数
#include "main.h"
#include "gpio.h"
#include "los_task.h"
uint32_t LED_Task_Handle;
uint32_t Creat_LED_Task(void);
void LED_Task(void);
void AppTaskCreate(void);
void SystemClock_Config(void);
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
AppTaskCreate();
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Supply configuration update enable
*/
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
/** Configure the main internal regulator output voltage
*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV1;
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
{
Error_Handler();
}
}
/* USER CODE BEGIN 4 */
uint32_t Creat_LED_Task(void)
{
uint32_t uwRet = LOS_OK;
TSK_INIT_PARAM_S task_init_param;
task_init_param.pcName = "LED_Task";
task_init_param.usTaskPrio = 5;
task_init_param.pfnTaskEntry = (TSK_ENTRY_FUNC)LED_Task;
task_init_param.uwStackSize = 1024;
uwRet = LOS_TaskCreate(&LED_Task_Handle,&task_init_param);
return uwRet;
}
void LED_Task(void)
{
while(1)
{
HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_15);
//HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET);
LOS_TaskDelay(1000);
}
}
void AppTaskCreate(void)
{
uint32_t uwRet = LOS_OK;
uwRet = LOS_KernelInit();
if(uwRet==LOS_OK)
{
Creat_LED_Task();
LOS_Start();
}
}
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
产品级 vendor 配置
config.json配置
在 \vendor\st\stm32h743_harmony 下新建 config.json
{
"product_name": "stm32h743_harmony", //产品名称,支持自定义,建议与vendor下的三级目录名称一致
"ohos_version": "OpenHarmony 3.0", //HarmonyOS版本号
"device_company": "st", //芯片解决方案厂商名称,建议与device的二级目录名称一致
"board": "stm32h743_harmony", //开发板名称,建议与device的三级级目录名称一致
"kernel_type": "liteos_m", //内核类型,应与开发板支持的内核类型匹配
"kernel_version": "3.0.0", //内核版本号,应与开发板支持的内核版本匹配
"subsystems": [ //产品选择的子系统,应为OS支持的子系统
{
"subsystem": "kernel",
"components": [ //产品选择的某个子系统下的组件,应为某个子系统支持的组件
{ "component": "liteos_m",
"features":[ //产品配置的某个组件的特性
"enable_ohos_kernel_liteos_m_fs = false",
"enable_ohos_kernel_liteos_m_kal = false"
]
}
]
}
],
"vendor_adapter_dir": "//device/st/stm32h743_harmony",
"third_party_dir": "//third_party",
"product_adapter_dir": "",
"ohos_product_type":"",
"ohos_manufacture":"",
"ohos_brand":"",
"ohos_market_name":"",
"ohos_product_series":"",
"ohos_product_model":"",
"ohos_software_model":"",
"ohos_hardware_model":"",
"ohos_hardware_profile":"",
"ohos_serial":"",
"ohos_bootloader_version":"",
"ohos_secure_patch_level":"",
"ohos_abi_list":""
}
编译脚本配置
在 \vendor\st\stm32h743_harmony 下新建 BUILD.gn
group("stm32h743_harmony") {
}
六、开始移植
将配置好的目录移植到鸿蒙源码对应的目录,
即device里的st文件夹移到鸿蒙device目录里,
vendor里的st文件夹移植到鸿蒙vendor目录里
点击“+”新建终端,再用cd命令进入到源码目录
输入 hb set
选择st下的stm32h743_harmony后回车,再输入hb build -f 命令编译
不出意外会报错:
这是官方源码漏了一个字符串,直接进入对应目录,对应行号添加一下:
只改这一个,再编译后,我这里又出现新的问题:
鸿蒙这玩意就是坑多,而且不允许有一个警告,有就编译不通过。
明明有这个头文件却识别不出来,后续改了其他地方,报的错又不一样了,感觉还是脚本和makefile那里没写好,毕竟我也是参考的别人的。
等博主makefile学精了以后再来尝试吧,本贴就给各位借鉴一下。如有大佬指点就更好了。
另外如果正常编译通过的话会显示编译seccess,然后再把OUT目录下的hex文件烧录到板子上就算成功了。