stm32CubeIDE中CMSIS_V1和CMSIS_V2選項的區(qū)別
STM32CubeIDE在stm32開發(fā)者起著最基礎(chǔ)的作用,在STM32CubeIDE中配置FreeRTOS中間層時需要選擇interface,其中有三個選項:Disable、CMSIS_V1和CMSIS_V2
CMSIS定義了通用工具接口,并提供一致的設(shè)備支持,那么CMSIS_V1和CMSIS_V2有什么區(qū)別呢,該怎選擇呢?
微控制器軟件接口標準CMSIS
CMSIS ARM官方定義如下:
Cortex微控制器軟件接口標準(CMSIS)是獨立于供應(yīng)商的硬件抽象層,用于基于Arm Cortex處理器的微控制器,并且CMSIS提供了到處理器和外圍設(shè)備,實時操作系統(tǒng)以及中間件組件的接口,可以說非常實用。
CMSIS軟件接口簡化了軟件重用,減少了開發(fā)周期,而且也不受限操作系統(tǒng)的類型,去耦。
不同之處
-
RTOS v1使得軟件能夠在不同的實時操作系統(tǒng)下運行(屏蔽不同RTOS提供的API的差別)
-
而RTOS v2則是拓展了RTOS v1,兼容更多的CPU架構(gòu)和實時操作系統(tǒng)。
RTOS v1創(chuàng)建任務(wù)函數(shù)如下:
/*********************** 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創(chuàng)建任務(wù)函數(shù)如下:
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都要大一些。