stm32CubeIDE中CMSIS_V1和CMSIS_V2选项的区别
扫描二维码
随时随地手机看文章
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都要大一些。