STM32F103RCT6移植LiteOS-M-V5.0.2-Release
下載源碼
kernel_liteos_m: OpenHarmony-v5.0.2-Release
third_party_bounds_checking_function: OpenHarmony-v5.0.2-Release
third_party_cmsis: OpenHarmony-v5.0.2-Release
進(jìn)入gitee
界面后點(diǎn)擊克隆/下載
按鈕,下載ZIP
壓縮包后解壓縮。下載路徑自定義。
使用STM32CubeMX創(chuàng)建工程模板
配置晶振和燒寫口
NVIC配置(默認(rèn)配置,未修改)
晶振配置
系統(tǒng)配置
時(shí)鐘配置
工程配置
生成路徑根據(jù)實(shí)際情況配置
代碼生成配置
生成代碼
配置使用Jlink+SWD方式下載程序
-
配置
Jlink
-
配置
SWD
模式 -
配置燒寫成功后復(fù)位運(yùn)行
編譯成功
模板添加目錄
原有目錄結(jié)構(gòu)
增加目錄
-
APP
- 應(yīng)用代碼 -
Config
- 配置文件 -
Lib
- 庫文件 -
Middleware
- 中間件
現(xiàn)有目錄
添加日志庫-simplelogger
simplelogger: 一款簡易的日庫庫,主要對(duì)接 J-Link RTT 使用 - Gitee.com
下載源文件
-
進(jìn)入
Middleware
文件夾 -
使用
Git Base Here
進(jìn)入Git
控制臺(tái) -
執(zhí)行命令
git clone https://gitee.com/Newcapec_cn/simplelogger.git
添加源文件
-
添加
Middleware\simplelogger\src\*.c
-
添加
Middleware\simplelogger\port\*.c
-
添加
Middleware\simplelogger\rtt\*.c
配置頭文件路徑
-
增加頭文件路徑
..\Middleware\simplelogger\inc
增加測試代碼
-
APP
文件夾創(chuàng)建APP_main.c
文件,文件內(nèi)容為
#include "slog.h"
void app_main(void) {
slog_test();
while (1) {
;
}
}
-
添加
APP_main.c
文件到工程
-
在模板
main
函數(shù)的while
循環(huán)中添加app_main
函數(shù)
void app_main(void);
app_main();
完整main
函數(shù)如下
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
void app_main(void);
app_main();
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
編譯運(yùn)行測試
測試成功界面
移植LiteOS-M
移植源碼
-
將
kernel_liteos_m-OpenHarmony-v5.0.2-Release
的arch
、kal
、kernel
、utils
文件夾拷貝至項(xiàng)目Middleware\liteos-m
文件夾 -
刪除文件夾
Middleware\liteos-m\arch\arm\arm9
Middleware\liteos-m\arch\arm\arm4
Middleware\liteos-m\arch\arm\arm7
Middleware\liteos-m\arch\arm\arm33
Middleware\liteos-m\arch\arm\arm55
Middleware\liteos-m\arch\csky
Middleware\liteos-m\arch\risc-v
Middleware\liteos-m\arch\xtensa
Middleware\liteos-m\kal\libc
Middleware\liteos-m\kal\libsec
Middleware\liteos-m\kal\posix
-
在
Middleware\liteos-m
路徑下創(chuàng)建文件夾bounds_checking
-
將
third_party_bounds_checking_function-OpenHarmony-v5.0.2-Release
的include
和src
文件夾拷貝至項(xiàng)目Middleware\liteos-m\bounds_checking
文件夾中 -
刪除非源碼文件(可不操作)
文件結(jié)構(gòu)為:
liteos-m
├── arch
│ ├── arm
│ │ ├── common
│ │ │ ├── los_common_interrupt.c
│ │ │ └── los_common_interrupt.h
│ │ ├── cortex-m3
│ │ │ └── keil
│ │ │ ├── los_arch_atomic.h
│ │ │ ├── los_arch_context.h
│ │ │ ├── los_arch_interrupt.h
│ │ │ ├── los_arch_timer.h
│ │ │ ├── los_atomic.S
│ │ │ ├── los_context.c
│ │ │ ├── los_dispatch.S
│ │ │ ├── los_exc.S
│ │ │ ├── los_interrupt.c
│ │ │ ├── los_startup.s
│ │ │ └── los_timer.c
│ │ └── include
│ │ └── arch_elf.h
│ └── include
│ ├── los_arch.h
│ ├── los_atomic.h
│ ├── los_context.h
│ ├── los_interrupt.h
│ ├── los_mpu.h
│ └── los_timer.h
├── bounds_checking
│ ├── include
│ │ ├── securec.h
│ │ └── securectype.h
│ └── src
│ ├── fscanf_s.c
│ ├── fwscanf_s.c
│ ├── gets_s.c
│ ├── input.inl
│ ├── memcpy_s.c
│ ├── memmove_s.c
│ ├── memset_s.c
│ ├── output.inl
│ ├── scanf_s.c
│ ├── secinput.h
│ ├── securecutil.c
│ ├── securecutil.h
│ ├── secureinput_a.c
│ ├── secureinput_w.c
│ ├── secureprintoutput_a.c
│ ├── secureprintoutput.h
│ ├── secureprintoutput_w.c
│ ├── snprintf_s.c
│ ├── sprintf_s.c
│ ├── sscanf_s.c
│ ├── strcat_s.c
│ ├── strcpy_s.c
│ ├── strncat_s.c
│ ├── strncpy_s.c
│ ├── strtok_s.c
│ ├── swprintf_s.c
│ ├── swscanf_s.c
│ ├── vfscanf_s.c
│ ├── vfwscanf_s.c
│ ├── vscanf_s.c
│ ├── vsnprintf_s.c
│ ├── vsprintf_s.c
│ ├── vsscanf_s.c
│ ├── vswprintf_s.c
│ ├── vswscanf_s.c
│ ├── vwscanf_s.c
│ ├── wcscat_s.c
│ ├── wcscpy_s.c
│ ├── wcsncat_s.c
│ ├── wcsncpy_s.c
│ ├── wcstok_s.c
│ ├── wmemcpy_s.c
│ ├── wmemmove_s.c
│ └── wscanf_s.c
├── kal
│ └── cmsis
│ ├── cmsis_liteos2.c
│ ├── cmsis_os2.h
│ ├── cmsis_os.h
│ ├── hos_cmsis_adp.h
│ └── kal.h
├── kernel
│ ├── include
│ │ ├── los_config.h
│ │ ├── los_event.h
│ │ ├── los_membox.h
│ │ ├── los_memory.h
│ │ ├── los_mux.h
│ │ ├── los_queue.h
│ │ ├── los_sched.h
│ │ ├── los_sem.h
│ │ ├── los_sortlink.h
│ │ ├── los_swtmr.h
│ │ ├── los_task.h
│ │ └── los_tick.h
│ └── src
│ ├── los_event.c
│ ├── los_init.c
│ ├── los_mux.c
│ ├── los_queue.c
│ ├── los_sched.c
│ ├── los_sem.c
│ ├── los_sortlink.c
│ ├── los_swtmr.c
│ ├── los_task.c
│ ├── los_tick.c
│ └── mm
│ ├── los_membox.c
│ └── los_memory.c
└── utils
├── internal
│ ├── los_hook_types.h
│ └── los_hook_types_parse.h
├── los_compiler.h
├── los_debug.c
├── los_debug.h
├── los_error.c
├── los_error.h
├── los_hook.c
├── los_hook.h
├── los_list.h
└── los_reg.h
19 directories, 106 files
項(xiàng)目添加源文件
添加頭文件路徑
..\Middleware\simplelogger\inc
..\Middleware\liteos-m\arch\include
..\Middleware\liteos-m\arch\arm\include
..\Middleware\liteos-m\arch\arm\cortex-m3\keil
..\Middleware\liteos-m\arch\arm\common
..\Middleware\liteos-m\kernel\include
..\Middleware\liteos-m\utils
..\Middleware\liteos-m\bounds_checking\include
編譯器選擇
Use default compiler version 6
Use MicroLlB
C語言使用C11
規(guī)則
C語言優(yōu)化等級(jí)-0
解決target_config.h
未找到問題
-
在
Config
文件夾下創(chuàng)建空文件ARMCM3.h
和target_config.h
-
target_config.h
添加以下內(nèi)容/* * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. * * 3. Neither the name of the copyright holder nor the names of its contributors may be used * to endorse or promote products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /**@defgroup los_config System configuration items * @ingroup kernel */ #ifndef _TARGET_CONFIG_H #define _TARGET_CONFIG_H #include "ARMCM3.h" #include "stm32f1xx_hal.h" #include "los_common_interrupt.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_WTIMER 0 #define LOSCFG_BASE_CORE_TICK_RESPONSE_MAX (0xFFFFFFFFUL) /*============================================================================= Hardware interrupt module configuration =============================================================================*/ #define LOSCFG_PLATFORM_HWI 0 #define LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT 0 #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 1 #define LOSCFG_BASE_CORE_SWTMR_LIMIT 48 /*============================================================================= Memory module configuration =============================================================================*/ #define LOSCFG_SYS_EXTERNAL_HEAP 0 #define LOSCFG_SYS_HEAP_SIZE 0x00008000 #define LOSCFG_MEM_MUL_POOL 1 #define OS_SYS_MEM_NUM 20 /*============================================================================= Exception module configuration =============================================================================*/ #define LOSCFG_PLATFORM_EXC 0 /* ============================================================================= PM module configuration ============================================================================= */ #define LOSCFG_KERNEL_PM 0 /* ============================================================================= printf module configuration ============================================================================= */ #define LOSCFG_KERNEL_PRINTF 2 #ifdef __cplusplus #if __cplusplus } #endif /* __cplusplus */ #endif /* __cplusplus */ #endif /* _TARGET_CONFIG_H */
-
添加
Config
文件夾為頭文件路徑
解決HWI_PROC_FUNC
未定義問題
在Middleware\liteos-m\arch\arm\common\los_common_interrupt.h
中添加以下代碼
/* ---> liteos-m add */
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
typedef VOID (*HWI_PROC_FUNC)(VOID *parm);
#else
typedef VOID (*HWI_PROC_FUNC)(void);
#endif
/* ---/ */
強(qiáng)制內(nèi)存池4字節(jié)對(duì)齊
Middleware\liteos-m\kernel\src\mm\los_memory.c
53行 由STATIC UINT8 g_memStart[LOSCFG_SYS_HEAP_SIZE];
修改為STATIC UINT8 __attribute__((aligned(4))) g_memStart[LOSCFG_SYS_HEAP_SIZE];
增加__attribute__((aligned(4)))
預(yù)處理
修改SysTick_Config
參數(shù)
將Middleware\liteos-m\arch\arm\cortex-m3\keil\los_timer.c
文件中調(diào)用SysTick_Config
接口的參數(shù) 由LOSCFG_BASE_CORE_TICK_RESPONSE_MAX
修改為OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND
移植PendSV_Handler
在PendSV_Handler
函數(shù)中調(diào)用HalPendSV
接口
void PendSV_Handler(void)
{
/* USER CODE BEGIN PendSV_IRQn 0 */
void HalPendSV(void);
HalPendSV();
/* USER CODE END PendSV_IRQn 0 */
/* USER CODE BEGIN PendSV_IRQn 1 */
/* USER CODE END PendSV_IRQn 1 */
}
移植OsTickHandler
在SysTick_Handler
函數(shù)中調(diào)用OsTickHandler
接口
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
/* USER CODE BEGIN SysTick_IRQn 0 */
void OsTickHandler(void);
OsTickHandler();
/* USER CODE END SysTick_IRQn 0 */
/* USER CODE BEGIN SysTick_IRQn 1 */
/* USER CODE END SysTick_IRQn 1 */
}
增加內(nèi)核打印接口
-
HalConsoleOutput
增加調(diào)用Jlink-RTT
打印功能WEAK VOID HalConsoleOutput(LogModuleType type, INT32 level, const CHAR *fmt, ...) { /* ---> liteos-m add */ #include "../rtt/SEGGER_RTT.h" va_list ParamList; va_start(ParamList, fmt); SEGGER_RTT_vprintf(0, fmt, &ParamList); va_end(ParamList); /* ---/ */ }
測試LiteOS-M
-
APP_main.c
添加測試代碼,其完整文件為:#include "slog.h" #include "los_task.h" VOID taskSampleEntry2(VOID) { while (1) { LOS_TaskDelay(1000); log_v("taskSampleEntry2 running..."); } } VOID taskSampleEntry1(VOID) { while (1) { LOS_TaskDelay(2000); log_v("taskSampleEntry1 running..."); } } UINT32 taskSample(VOID) { UINT32 uwRet; UINT32 taskID1, taskID2; TSK_INIT_PARAM_S stTask1 = {0}; stTask1.pfnTaskEntry = (TSK_ENTRY_FUNC)taskSampleEntry1; stTask1.uwStackSize = 0X1000; stTask1.pcName = "taskSampleEntry1"; stTask1.usTaskPrio = 6; uwRet = LOS_TaskCreate(&taskID1, &stTask1); if (uwRet != LOS_OK) { log_v("create task1 failed\n"); } stTask1.pfnTaskEntry = (TSK_ENTRY_FUNC)taskSampleEntry2; stTask1.uwStackSize = 0X1000; stTask1.pcName = "taskSampleEntry2"; stTask1.usTaskPrio = 7; uwRet = LOS_TaskCreate(&taskID2, &stTask1); if (uwRet != LOS_OK) { log_v("create task2 failed\n"); } return LOS_OK; } void app_main(void) { unsigned int ret; slog_test(); ret = LOS_KernelInit(); if (ret == LOS_OK) { taskSample(); LOS_Start(); } while (1) { ; } }
-
測試成功界面為
適配 CMSIS
添加源碼
Middleware\liteos-m\kal\cmsis\cmsis_liteos2.c
修改源碼
third_party_cmsis-OpenHarmony-v5.0.2-Release\CMSIS\RTOS2\Include\cmsis_os2.h
覆蓋Middleware\liteos-m\kal\cmsis\cmsis_os2.h
添加頭文件路徑
..\Middleware\liteos-m\kal\cmsis
創(chuàng)建使用cmsis_os2
接口的源碼
-
在
APP
文件夾中創(chuàng)建源文件cmsis_os2_creat_thread.c
,代碼如下:/** * @file cmsis_os2_creat_thread.c * @author TianBeiBei (tianbeibei5628@dingtalk.com) * @brief * @version 0.1 * @date 2025-02-25 * * @copyright Copyright (c) 2025 * */ #include "slog.h" #include "cmsis_os2.h" #define MINI_TASK_DELAY_MS (1 * 1000) /* Definitions for BelowNormalTask */ osThreadId_t BelowNormalTaskHandle; const osThreadAttr_t BelowNormalTask_attributes = { .name = "BelowNormalTask", .stack_size = 1024 * 4, .priority = (osPriority_t)osPriorityBelowNormal, }; /* Definitions for NormalTask */ osThreadId_t NormalTaskHandle; const osThreadAttr_t NormalTask_attributes = { .name = "NormalTask", .stack_size = 1024 * 4, .priority = (osPriority_t)osPriorityNormal, }; /* Definitions for LowTask */ osThreadId_t LowTaskHandle; const osThreadAttr_t LowTask_attributes = { .name = "LowTask", .stack_size = 1024 * 4, .priority = (osPriority_t)osPriorityLow, }; void low_task(void *argument) { for (;;) { log_v("low_task runing"); osDelay(MINI_TASK_DELAY_MS * 3); } #if 0 osThreadExit();/* 任務(wù)退出 */ #endif } void normal_task(void *argument) { for (;;) { log_v("normal_task runing"); osDelay(MINI_TASK_DELAY_MS * 2); } #if 0 osThreadExit();/* 任務(wù)退出 */ #endif } void below_normal_task(void *argument) { for (;;) { log_v("below_normal_task runing"); osDelay(MINI_TASK_DELAY_MS * 1); } #if 0 osThreadExit();/* 任務(wù)退出 */ #endif } void liteos_m_thread_init(void) { /* Create the thread(s) */ /* creation of NormalTask */ NormalTaskHandle = osThreadNew(normal_task, NULL, &NormalTask_attributes); /* creation of BelowNormalTask */ BelowNormalTaskHandle = osThreadNew(below_normal_task, NULL, &BelowNormalTask_attributes); /* creation of LowTask */ LowTaskHandle = osThreadNew(low_task, NULL, &LowTask_attributes); } void cmsis_os2_main(void) { /* Init scheduler */ osKernelInitialize(); /* Call init function for freertos objects (in freertos.c) */ liteos_m_thread_init(); /* Start scheduler */ osKernelStart(); }
-
將
cmsis_os2_creat_thread.c
文件添加到工程中
-
修改
APP_main.c
源碼,添加調(diào)用cmsis_os2
接口的代碼,不再調(diào)用源碼接口,修改后的源碼如下:#include "slog.h" #include "los_task.h" VOID taskSampleEntry2(VOID) { while (1) { log_v("taskSampleEntry2 running..."); LOS_TaskDelay(1000); } } VOID taskSampleEntry1(VOID) { while (1) { log_v("taskSampleEntry1 running..."); LOS_TaskDelay(2000); } } UINT32 taskSample(VOID) { UINT32 uwRet; UINT32 taskID1, taskID2; TSK_INIT_PARAM_S stTask1 = {0}; stTask1.pfnTaskEntry = (TSK_ENTRY_FUNC)taskSampleEntry1; stTask1.uwStackSize = 0X1000; stTask1.pcName = "taskSampleEntry1"; stTask1.usTaskPrio = 6; uwRet = LOS_TaskCreate(&taskID1, &stTask1); if (uwRet != LOS_OK) { log_v("create task1 failed\n"); } stTask1.pfnTaskEntry = (TSK_ENTRY_FUNC)taskSampleEntry2; stTask1.uwStackSize = 0X1000; stTask1.pcName = "taskSampleEntry2"; stTask1.usTaskPrio = 7; uwRet = LOS_TaskCreate(&taskID2, &stTask1); if (uwRet != LOS_OK) { log_v("create task2 failed\n"); } return LOS_OK; } void app_main(void) { unsigned int ret; slog_test(); #if 1 /* 0-原接口 1-cmsis_os2接口 */ void cmsis_os2_main(void); cmsis_os2_main(); #else ret = LOS_KernelInit(); if (ret == LOS_OK) { taskSample(); LOS_Start(); } #endif while (1) { ; } }
測試成功界面如下:
-
移植
+關(guān)注
關(guān)注
1文章
391瀏覽量
28502 -
Liteos
+關(guān)注
關(guān)注
10文章
33瀏覽量
47880 -
STM32F103RCT6
+關(guān)注
關(guān)注
10文章
24瀏覽量
10362
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
STM32F103RCT6是什么?STM32F103RCT6有哪些特性?
STM32F103RCT6是什么
STM32F103RCT6數(shù)據(jù)手冊(cè)
STM32F103RCT6用SPI和FATFS訪問SD卡
stm32f103rct6引腳圖及使用手冊(cè)

STM32F103RCT6的Sch原理圖免費(fèi)下載

STM32F103RCT6的最小系統(tǒng)原理圖免費(fèi)下載

STM32F103RCT6移植到STM32F103C8T6需要注意那些事項(xiàng)

基于STM32F103RCT6 移植W5500 最新ioLibrary_Driver(一)

STM32F103RCT6 基于STM32Cube_FW_F1_V1.8.0庫建立工程模板

評(píng)論