stm32CubeIDE中CMSIS_V1和CMSIS_V2选项的区别
2023-02-18 16:38:03 时间
来源:技术让梦想更伟大
作者:李肖遥
STM32CubeIDE在stm32开发者起着最基础的作用,在STM32CubeIDE中配置FreeRTOS中间层时需要选择interface,其中有三个选项:Disable、CMSIS_V1和CMSIS_V2
CMSIS定义了通用工具接口,并提供一致的设备支持,那么CMSIS_V1和CMSIS_V2有什么区别呢,该怎选择呢?
微控制器软件接口标准CMSIS
CMSIS ARM官方定义如下:
Cortex微控制器软件接口标准(CMSIS)是独立于供应商的硬件抽象层,用于基于Arm Cortex处理器的微控制器,并且CMSIS提供了到处理器和外围设备,实时操作系统以及中间件组件的接口,可以说非常实用。
CMSIS软件接口简化了软件重用,减少了开发周期,而且也不受限操作系统的类型,去耦。
不同之处
- RTOS v1使得软件能够在不同的实时操作系统下运行(屏蔽不同RTOS提供的API的差别)
- 而RTOS v2则是拓展了RTOS v1,兼容更多的CPU架构和实时操作系统。
RTOS v1创建任务函数如下:
/*********************** Thread Management *****************************/
/**
* @brief Create a thread and add it to Active Threads and set it to state READY.
* @param thread_def thread definition referenced with \ref osThread.
* @param argument pointer that is passed to the thread function as start argument.
* @retval thread ID for reference by other functions or NULL in case of error.
* @note MUST REMAIN UNCHANGED: \b osThreadCreate shall be consistent in every CMSIS-RTOS.
*/
osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument)
{
TaskHandle_t handle;
#if( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
if((thread_def->buffer != NULL) && (thread_def->controlblock != NULL)) {
handle = xTaskCreateStatic((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name,
thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority),
thread_def->buffer, thread_def->controlblock);
}
else {
if (xTaskCreate((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name,
thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority),
&handle) != pdPASS) {
return NULL;
}
}
#elif( configSUPPORT_STATIC_ALLOCATION == 1 )
handle = xTaskCreateStatic((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name,
thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority),
thread_def->buffer, thread_def->controlblock);
#else
if (xTaskCreate((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name,
thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority),
&handle) != pdPASS) {
return NULL;
}
#endif
return handle;
}
RTOS v2创建任务函数如下:
osThreadId_t osThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr) {
const char *name;
uint32_t stack;
TaskHandle_t hTask;
UBaseType_t prio;
int32_t mem;
hTask = NULL;
if (!IS_IRQ() && (func != NULL)) {
stack = configMINIMAL_STACK_SIZE;
prio = (UBaseType_t)osPriorityNormal;
name = NULL;
mem = -1;
if (attr != NULL) {
if (attr->name != NULL) {
name = attr->name;
}
if (attr->priority != osPriorityNone) {
prio = (UBaseType_t)attr->priority;
}
if ((prio < osPriorityIdle) || (prio > osPriorityISR) || ((attr->attr_bits & osThreadJoinable) == osThreadJoinable)) {
return (NULL);
}
if (attr->stack_size > 0U) {
/* In FreeRTOS stack is not in bytes, but in sizeof(StackType_t) which is 4 on ARM ports. */
/* Stack size should be therefore 4 byte aligned in order to avoid division caused side effects */
stack = attr->stack_size / sizeof(StackType_t);
}
if ((attr->cb_mem != NULL) && (attr->cb_size >= sizeof(StaticTask_t)) &&
(attr->stack_mem != NULL) && (attr->stack_size > 0U)) {
mem = 1;
}
else {
if ((attr->cb_mem == NULL) && (attr->cb_size == 0U) && (attr->stack_mem == NULL)) {
mem = 0;
}
}
}
else {
mem = 0;
}
if (mem == 1) {
#if (configSUPPORT_STATIC_ALLOCATION == 1)
hTask = xTaskCreateStatic ((TaskFunction_t)func, name, stack, argument, prio, (StackType_t *)attr->stack_mem,
(StaticTask_t *)attr->cb_mem);
#endif
}
else {
if (mem == 0) {
#if (configSUPPORT_DYNAMIC_ALLOCATION == 1)
if (xTaskCreate ((TaskFunction_t)func, name, (uint16_t)stack, argument, prio, &hTask) != pdPASS) {
hTask = NULL;
}
#endif
}
}
}
return ((osThreadId_t)hTask);
}
正常V1够用了,普通功能选V1,高级功能选择V2:
我分别选择CMSIS_V1和CMSIS_V2编译了两次进行对比,CMSIS_V2都要大一些。
‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧ END ‧‧‧‧‧‧‧‧‧‧‧‧‧‧‧
相关文章
- 【二】Latex入门使用、常见指令
- 【CSDN浏览器插件测评超详细版】——万能便捷的C功能,直接爱不释手,强烈推荐!更多功能等你探索
- 常见多智能体强化学习仿真环境介绍【一】{推荐收藏,真的牛}
- ABAP之SM30触发数据附加功能
- 协程笔记
- 说明
- MOV.AI Flow 可视化ROS IDE
- 多智能体强化学习算法【一】【MAPPO、MADDPG、QMIX】
- 多智能体强化学习算法【二】【MADDPG、QMIX、MAPPO】
- 新项目决定用 JDK 17了
- 多智能体强化学习算法【三】【QMIX、MADDPG、MAPPO】
- 《吐血整理》高级系列教程-吃透Fiddler抓包教程(36)-掌握Fiddler中Fiddler Script用法,你会有多牛逼-上篇
- 《吐血整理》高级系列教程-吃透Fiddler抓包教程(37)-掌握Fiddler中Fiddler Script用法,你会有多牛逼-下篇
- 环境调试bug【一】
- 【Qbot】3.加入内容审核功能
- 环境调试bug【二】无法加载源“<string>”: Source unavailable
- parser.add_argument()用法——命令行选项、参数和子命令解析器
- 一次TiDB GC阻塞引发的性能问题分析
- windows共享文件创建----局域网办公
- 【一】分布式训练---单机多卡多机多卡(飞桨paddle1.8)