使用STM32CubeMx生成代码时,会让我们选用CMSIS_V1还是CMSIS_V2,这两者有什么区别?
V2比V1具有更多的功能,下面是STM32F103VET的STM32CubeMx生成代码不经任何修改编译后内存、Flash情况:
V1:
V2:
在代码上V1、V2区别如下:
V2提供了更多的功能,如果我们不使用带os前缀的功能,只使用FreeRTOS原生的接口,那么CMSIS-V1、V2对我们来说都是多余的,举例,使用CMSIS-V1创建任务方法为:
osThreadStaticDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128, defaultTaskBuffer, &defaultTaskControlBlock);
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
osThreadStaticDef是一个cmsis_os.h中的宏定义:
#define osThreadStaticDef(name, thread, priority, instances, stacksz, buffer, control) \
const osThreadDef_t os_thread_def_##name = \
{ #name, (thread), (priority), (instances), (stacksz), (buffer), (control) }
osThreadCreate是cmsis_os.c中的一个函数:
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;
}
可以看出,对于普通玩家来说cmsis_os.c只是把FreeRTOS的xTaskCreateStatic/ xTaskCreate等接口重新封装了一遍,没有什么区别;重新封装的目的大致为:让玩家不用关心FreeRTOS内部调用关系,只管用就行了。
文章来源地址https://uudwc.com/A/mJ65v文章来源:https://uudwc.com/A/mJ65v