•STM32 Cube Software Package Code Structure
ARM has added a middleware layer, CMSIS_RTOS/cmsis_os.c, to ensure compatibility with various operating systems.
Taking the STM32L4XX MCU software package as an example, other FreeRTOS release code files are located at this path: STM32Cube_FW_L4_V1.18.0\Middlewares\Third_Party\FreeRTOS\Source
•vTask/xTask/eTask
Online explanations state that both vTask and xTask are tasks within the FreeRTOS system, but they have some differences. vTask is a basic task with only the fundamental task functionalities, while xTask is an extended task that can utilize more task features, such as task priority, task suspension, task deletion, etc.
•FreeRTOS Resource Comparison
Mail/semaphore/mutex/message are all implemented using queues at the lower level.
Semaphore supports binary semaphores, counting semaphores, and recursive semaphores.
Signals are implemented using notify based on event_list.
•Mutex can handle priority inversion issues.
There are many explanations online about priority inversion, which generally refers to a situation where a high-priority task is waiting for a resource held by a low-priority task, but that low-priority task is preempted by other tasks. At this point, the low-priority task holds the semaphore, further causing the high-priority task to be suspended.In Mutex, priority inheritance temporarily raises the task’s priority to the highest.
xTaskPriorityInherit(): compares the priority of the semaphore holder and the task attempting to acquire the semaphore. If the current holder’s level is lower, it updates to the requesting task’s priority and updates the task list.
xTaskPriorityDisinherit(): combines UBaseType_tuxBasePriority to reassign the last allocated priority to the task. Cancels the inherited priority.
If there are multiple instances of priority inversion with mutex variables, priority inheritance should switch to the current highest priority task to continue handling the inversion until all tasks are completed.
The inheritance function modifies the priority order by resetting the time list item valuexItemValue.
if( ( listGET_LIST_ITEM_VALUE( &( pxMutexHolderTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0UL )
{
listSET_LIST_ITEM_VALUE( &( pxMutexHolderTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES – ( TickType_t ) pxCurrentTCB->uxPriority );
/*lint !e961 MISRA exception as the casts are only redundant for some ports. */
}
else
{
mtCOVERAGE_TEST_MARKER();
}
In the code, this is defined asconfigLIST_VOLATILE TickType_t xItemValue;/*< The value being listed. In most cases, this is used to sort the list in descending order. */ This refers to the value of the task in the list item, used to sort list members in descending order. Before inserting into the list, the task priority is also modified to the higher value.
configMAX_PRIORITIES – uxPriority, because the linked list sorting uses smaller values first, while task priorities use larger values first. Here, does the priority refer to the list item value? Are these two parameters the same meaning? This needs to be confirmed.
•In the code, this is how objects are created.
/// Access a Mutex definition.
///
param name name of the mutex object.
///
ote CAN BE CHANGED: The parameter to osMutex shall be consistent but the
/// macro body is implementation specific in every CMSIS-RTOS.
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
#define osMutexDef(name) \\
const osMutexDef_t os_mutex_def_##name = { 0, NULL }
#define osMutexStaticDef(name, control) \\
const osMutexDef_t os_mutex_def_##name = { 0, (control) }
#else //configSUPPORT_STATIC_ALLOCATION == 0
#define osMutexDef(name) \\
const osMutexDef_t os_mutex_def_##name = { 0 }
#endif
•PRIVILEGED_FUNCTION
The marker after the function definition comes frommpu_wrappers.h, which restricts two wrapper macros to specify the memory segment for storing functions or variables.
#ifdef portUSING_MPU_WRAPPERS
#ifndef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
/* Ensure API functions go in the privileged execution section. */
#define PRIVILEGED_FUNCTION __attribute__((section(“privileged_functions”)))
#define PRIVILEGED_DATA __attribute__((section(“privileged_data”)))
#define FREERTOS_SYSTEM_CALL __attribute__((section( “freertos_system_calls”)))