当前位置: 首页 > news >正文

kernel_liteos_m移植到正点原子阿波罗F429_keil版

前期准备

先调通打印点击跳转

能正常打印源码下载

下载代码仓

kernel_liteos_m源码
third_party_bounds_checking_function源码
使用git下载固定OpenHarmony-v6.0-Release节点,避免后续更新导致的编译失败

git clone git@gitee.com:openharmony/third_party_bounds_checking_function.git -b OpenHarmony-v6.0-Releasegit clone git@gitee.com:openharmony/kernel_liteos_m.git -b OpenHarmony-v6.0-Release

移植

新建文件夹

如果上面没有问题,你会有3个文件夹
在这里插入图片描述
在自己工程的目录下新增liteos文件夹
在这里插入图片描述
把kernel_liteos_m的arch、components、kernal、utils文件夹复制到自己的liteos目录下,再新建一个securec文件夹
在这里插入图片描述

kernel

删除BUILD.gn文件,只留两个文件夹即可
在这里插入图片描述

arch

arch下只留arm和include文件夹
在这里插入图片描述

arm目录下只留common、cortex-m4、include目录
cortex-m4下只留keil
在这里插入图片描述

components

components下只留exchook和signal

utils

不动

securec

把third_party_bounds_checking_function目录下include和src拷贝到securec目录下。
src下只保留memcpy_s.c、memset_s.c、strncpy_s.c、securecutil.h
文件

keil

新建文件夹

打开keil的配置,准备添加需要编译的文件
在这里插入图片描述
先新建5个跟文件夹前缀带liteos。
在这里插入图片描述

liteos/arch

在这里插入图片描述

liteos/components

在这里插入图片描述

liteos/kernal

在这里插入图片描述

liteos/utils

在这里插入图片描述

liteos/securec

在这里插入图片描述

添加头文件目录

在这里插入图片描述
在这里插入图片描述
记得一定要点OK才是保存

编译及错误修复

到这里你可以到尝试编译一次;会提示找不到target_config.h和sigset_t未定义

target_config.h

/** 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 "stm32f4xx.h"
#include "stm32f4xx_it.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                                0#define LOSCFG_BASE_CORE_SCHED_SLEEP                        1#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */#endif /* _TARGET_CONFIG_H */

把target_config.h文件放到arch\include下。

los_signal.h

/** Copyright (c) 2022-2022 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.*/#ifndef _LOS_SIGNAL_H
#define _LOS_SIGNAL_H#include <signal.h>
#include "los_list.h"#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus *//*** @ingroup los_signal* Signal error code: The parameters of interface is error.** Value: 0x02003200**/
#define LOS_ERRNO_SIGNAL_INVALID                    LOS_ERRNO_OS_FATAL(LOS_MOD_SIGNAL, 0x00)/*** @ingroup los_signal* Signal error code: The memory requests failed.** Value: 0x02003201**/
#define LOS_ERRNO_SIGNAL_NO_MEMORY                  LOS_ERRNO_OS_ERROR(LOS_MOD_SIGNAL, 0x01)/*** @ingroup los_signal* Signal error code: The signal is not set.** Value: 0x02003202**/
#define LOS_ERRNO_SIGNAL_NO_SET                     LOS_ERRNO_OS_ERROR(LOS_MOD_SIGNAL, 0x02)/*** @ingroup los_signal* Signal error code: Waiting for signal timeout.** Value: 0x02003203**/
#define LOS_ERRNO_SIGNAL_TIMEOUT                    LOS_ERRNO_OS_ERROR(LOS_MOD_SIGNAL, 0x03)/*** @ingroup los_signal* Signal error code: The interface is used before system start.** Value: 0x02003204**/
#define LOS_ERRNO_SIGNAL_CAN_NOT_CALL               LOS_ERRNO_OS_ERROR(LOS_MOD_SIGNAL, 0x04)/**
* @ingroup los_signal
* Mutex error code: Waiting for signal in interrupt callback.
*
* Value: 0x02003205
*
*/
#define LOS_ERRNO_SIGNAL_PEND_INTERR                LOS_ERRNO_OS_ERROR(LOS_MOD_SIGNAL, 0x05)/*** @ingroup los_signal* Add the signal num to the signal set.*/
#define LOS_SIGNAL_MASK(sigNo)          (1U << ((sigNo) - 1))/*** @ingroup los_signal* Maximum signal supported num.*/
#define LOS_SIGNAL_SUPPORT_MAX           31/*** @ingroup los_signal* Signal handler type.*/
typedef VOID (*SIG_HANDLER)(INT32 sigNo);#if (LOSCFG_KERNEL_SIGNAL == 1)
typedef struct {sigset_t     sigSetFlag;                              /**< installing signals */sigset_t     sigPendFlag;                             /**< pending signals */sigset_t     sigWaitFlag;                             /**< waiting signals */siginfo_t    sigInfo;                                 /**< signal info */SIG_HANDLER  sigHandlers[LOS_SIGNAL_SUPPORT_MAX + 1]; /**< signal handler */LOS_DL_LIST  sigInfoList;                             /**< signal info list */VOID         *sigSaveSP;                              /**< save stack pointer */VOID         *sigRestoreSP;                           /**< restore stack pointer */UINT32       sigStatus;                               /**< status of signal */
} OsSigCB;typedef struct {LOS_DL_LIST node;siginfo_t info;
} OsSigInfoNode;#define OS_SIGNAL_STATUS_WAIT            0x0001
#define OS_SIGNAL_VALID(sigNo)           (((sigNo) > 0) && ((sigNo) <= LOS_SIGNAL_SUPPORT_MAX))UINT32 OsSignalInit(VOID);
#endif
UINTPTR OsSignalTaskContextRestore(VOID);
#if (LOSCFG_KERNEL_SIGNAL == 1)
/*** @ingroup los_signal* @brief Register the handler for the specified signal.** @par Description:* This API is used to register the handler for the specified signal, otherwise it is the default handler.** @attention None.** @param sigNo   [IN] The specified signal num.* @param handler [IN] The handler for this signal, which is either SIG_IGN, SIG_DFL,* or the address of a programmer-defined function.** @retval: SIG_ERR Type#SIG_HANDLER: error code.* @retval: old     Type#SIG_HANDLER: success, the previous handler is returned.* <ul><li>los_signal.h: the header file that contains the API declaration.</li></ul>* @see None*/
SIG_HANDLER LOS_SignalSet(INT32 sigNo, SIG_HANDLER handler);/*** @ingroup los_signal* @brief Shield the specified signal set.** @par Description:* This API is used to shield the specified signal set and get the current signal set.** @attention None.** @param how    [IN] The behavior of the call is dependent on the value of how, which is either SIG_BLOCK,* SIG_UNBLOCK, SIG_SETMASK.* @param set    [IN] The new signal set.* @param oldSet [OUT] The old signal set.** @retval: LOS_ERRNO_SIGNAL_CAN_NOT_CALL Type#UINT32: The interface is used before system start.* @retval: LOS_ERRNO_SIGNAL_NO_MEMORY Type#UINT32: The memory requests failed.* @retval: LOS_ERRNO_SIGNAL_INVALID Type#UINT32: The parameters of interface is error.* @retval: LOS_OK Type#UINT32: success.* <ul><li>los_signal.h: the header file that contains the API declaration.</li></ul>* @see None*/
UINT32 LOS_SignalMask(INT32 how, const sigset_t *set, sigset_t *oldSet);/*** @ingroup los_signal* @brief Suspend execution of the calling thread until one of the signals specified in* the signal set becomes pending.** @par Description:* This API is used to suspend execution of the calling thread until one of the signals* specified in the signal set becomes pending and return the signal number in sig.** @attention None.** @param set     [IN] The specified signal set which waiting for.* @param info    [OUT] The info of signal becomes pending.* @param timeout [IN] The waiting time.** @retval: LOS_ERRNO_SIGNAL_INVALID Type#UINT32: The parameters of interface is error.* @retval: LOS_ERRNO_SIGNAL_CAN_NOT_CALL Type#UINT32: The interface is used before system start.* @retval: LOS_ERRNO_SIGNAL_NO_MEMORY Type#UINT32: The memory requests failed.* @retval: LOS_ERRNO_SIGNAL_PEND_INTERR Type#UINT32: Waiting for signal in interrupt callback.* @retval: LOS_ERRNO_SIGNAL_TIMEOUT Type#UINT32: Waiting for signal timeout.* @retval: signo Type#UINT32: success, returning the signal num which becomes pending.* <ul><li>los_signal.h: the header file that contains the API declaration.</li></ul>* @see LOS_SignalSend*/
UINT32 LOS_SignalWait(const sigset_t *set, siginfo_t *info, UINT32 timeout);/*** @ingroup los_signal* @brief Send the specified signal to the specified task.** @par Description:* This API is used to send the specified signal to the specified task.** @attention None.** @param taskID   [IN] Send a signal to this task.* @param sigNo    [IN] The signal num.** @retval: LOS_ERRNO_SIGNAL_NO_MEMORY Type#UINT32: The memory requests failed.* @retval: LOS_ERRNO_SIGNAL_INVALID Type#UINT32: The parameters of interface is error.* @retval: LOS_ERRNO_SIGNAL_NO_SET Type#UINT32: The signal is not set.* @retval: LOS_OK Type#UINT32: success.* <ul><li>los_signal.h: the header file that contains the API declaration.</li></ul>* @see None*/
UINT32 LOS_SignalSend(UINT32 taskID, INT32 sigNo);
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */#endif /* _LOS_SIGNAL_H */

就是sigset_t在keil未定位,需要屏蔽下。
在.h的115行和141加上

#if (LOSCFG_KERNEL_SIGNAL == 1)

在.h的139行和231加上

#endif

到此编译成功。

上板运行

需要在main调用下任务初始哈函数:

user_main.c

#include "user_main.h"#include "printf.h"#include "stm32f4xx_hal.h"#include "los_task.h"VOID TaskSampleEntry2(VOID)
{while (1) {Printf("TaskSampleEntry2 running...\n");(VOID)LOS_TaskDelay(2000);}
}VOID TaskSampleEntry1(VOID)
{while (1) {Printf("TaskSampleEntry1 running...\n");(VOID)LOS_TaskDelay(1000);}
}
VOID TaskSample(VOID)
{UINT32 uwRet;UINT32 taskID1;UINT32 taskID2;TSK_INIT_PARAM_S stTask = {0};stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskSampleEntry1;stTask.uwStackSize = 0x1000;stTask.pcName = "TaskSampleEntry1";stTask.usTaskPrio = 6; /* Os task priority is 6 */uwRet = LOS_TaskCreate(&taskID1, &stTask);if (uwRet != LOS_OK) {Printf("Task1 create failed\n");}stTask.pfnTaskEntry = (TSK_ENTRY_FUNC)TaskSampleEntry2;stTask.uwStackSize = 0x1000;stTask.pcName = "TaskSampleEntry2";stTask.usTaskPrio = 7; /* Os task priority is 7 */uwRet = LOS_TaskCreate(&taskID2, &stTask);if (uwRet != LOS_OK) {Printf("Task2 create failed\n");}
}void UserMain(void)
{Printf("Hello, World!\r\n");UINT32 ret = LOS_KernelInit();  //初始化内核。if (ret == LOS_OK) {TaskSample();  //示例任务函数,在此函数中创建线程任务。LOS_Start();   //开始任务调度,程序执行将阻塞在此,由内核接管调度。}while(1) {HAL_Delay(1000);Printf("Hello World!\r\n");}
}

编译烧录运行,串口打印如下,移植成功
在这里插入图片描述


文章转载自:

http://cZIJD3D2.rmpfh.cn
http://T5Wv0Ky3.rmpfh.cn
http://18KdBCMD.rmpfh.cn
http://pXHKQygR.rmpfh.cn
http://qwKiDuzQ.rmpfh.cn
http://3hqEbUwD.rmpfh.cn
http://a1ZxWr54.rmpfh.cn
http://5M90BVqV.rmpfh.cn
http://mgjTSfUM.rmpfh.cn
http://vA06S0OE.rmpfh.cn
http://sBVf7xjZ.rmpfh.cn
http://FNZ2MMHw.rmpfh.cn
http://tC11dg67.rmpfh.cn
http://mmJWUKRg.rmpfh.cn
http://LWgvOksi.rmpfh.cn
http://PDmF5Phj.rmpfh.cn
http://tSTPcezB.rmpfh.cn
http://Y5Nltm05.rmpfh.cn
http://JWBzT4zu.rmpfh.cn
http://6rgYPqVH.rmpfh.cn
http://VQtWej6d.rmpfh.cn
http://Gv66Q1ic.rmpfh.cn
http://ME845etX.rmpfh.cn
http://mSYsAc0e.rmpfh.cn
http://MG5WgzNm.rmpfh.cn
http://OZTK6iQu.rmpfh.cn
http://CijMSTZw.rmpfh.cn
http://HiWwqzxo.rmpfh.cn
http://XbL9M7e4.rmpfh.cn
http://hQhkwYDM.rmpfh.cn
http://www.dtcms.com/a/376724.html

相关文章:

  • <数据集>yolo梨幼果识别数据集<目标检测>
  • BUG排查流程
  • 搞坏了docker 双系统下重装ubuntu22.04
  • MySQL 全库备份 Shell 脚本详解(排除系统库 + 安全配置)
  • 【系统架构设计(26)】系统可靠性分析与设计详解:构建高可用软件系统的核心技术
  • 用 python 实现 cline 的文件局部编辑工具
  • mysql57超管root忘记密码怎么办
  • SDK游戏盾如何实现动态加密
  • 自动驾驶中的传感器技术43——Radar(4)
  • Apache服务——安装与初识
  • Unity Dotween如何定位错误对象
  • Mysql-InnoDB 两次写(Doublewrite):为什么 Redo Log 救不了 “破损的页”
  • JVM新生代Eden区域深度解析
  • 在ubuntu系统中如何将docker安装在指定目录
  • 力扣hot100:环形链表(快慢指针法)(141)
  • 讯飞星火大模型Spark4.0Ultra的WebSocket交互实现解析
  • LeetCode 2958.最多K个重复元素的最长子数组
  • 【Oracle经验分享】字符串拼接过长问题的解决方案 —— 巧用 XMLAGG
  • MP381A-AB02 MEMS麦克风可靠性重新定义消费电子音频
  • 面试题:Redis要点总结(单机数据库)
  • 分类别柱状图(Vue3)
  • 视频生成迎来效率革命!字节提出视频生成稀疏注意力机制,计算量降20倍,速度升17.79倍!
  • 快速开发一类似个人网站空间的工具使用什么方式比较好,比如网页或者个Windows程序,并且使用什么技术开发比较好,区别优势局限性,分别说明一下
  • 计算机毕设选题:基于Python+MySQL校园美食推荐系统【源码+文档+调试】
  • vscode启用GEMINI CODE ASSIST插件
  • 仿QQ音乐的音乐播放器自动化测
  • daily notes[18]
  • 网络编程学习
  • App 上架全流程指南,iOS App 上架步骤、App Store 应用发布流程、uni-app 打包上传与审核要点详解
  • Java Flow API — Publisher、Subscriber 与 Processor 实战