2025-02-21 09:59 AM - last edited on 2025-02-21 11:48 AM by mƎALLEm
Hello,
I am configuring a project from scratch for a STM32 FreeRTOS based.
From FreeRTOS documentation:
Low priority numbers denote low priority tasks.
The idle task has priority zero (tskIDLE_PRIORITY).
2-Kernel/02-Kernel-features/01-Tasks-and-co-routines/15-Idle-task
It is possible for application tasks to share the idle task priority (tskIDLE_PRIORITY).
See the configIDLE_SHOULD_YIELD configuration parameter for information on how this behaviour can be configured.
#define tskIDLE_PRIORITY ( ( unsigned portBASE_TYPE ) 0U )
This matches with what I can see from my project debugging:
But, I don't understant why in STM32 code, in 'cmsis_os2.h', IDLE thread priority is '1' instead of '0'.
/// Priority values.
typedef enum {
osPriorityNone = 0, ///< No priority (not initialized).
osPriorityIdle = 1, ///< Reserved for Idle thread.
osPriorityLow = 8, ///< Priority: low
And also, the 'osThreadNew' does not let me create a task with priority '0', in 'cmsis_os2.c'
[...]
prio = (UBaseType_t)osPriorityNormal;
[...]
if (attr->priority != osPriorityNone) {
prio = (UBaseType_t)attr->priority;
}
if ((prio < osPriorityIdle) || (prio > osPriorityISR) || ((attr->attr_bits & osThreadJoinable) == osThreadJoinable)) {
return (NULL);
}
[...]
Is this a mistake? Or is the intended behaviour?
From my point of view:
The idle task is responsible for freeing memory allocated by the RTOS to tasks that have since been deleted.
It is therefore important in applications that make use of the vTaskDelete() function to ensure the idle task is not starved of processing time.
The idle task has no other active functions so can legitimately be starved of microcontroller time under all other conditions.
Looking forward for your answer,
Thanks,
Carles
2025-02-21 10:36 AM
Cmsis_os2.c/h is wrapper to make FreeRTOS CMSIS compatible, so the priorities in cmsis_os2.h are different from the priorities used by FreeRTOS.
In FreeRTOS the Idle Thread is created automatically, you don't have to start or define it by yourself.
Martin