FreeRTOS v10.2.1 task priority versus CMSIS_RTOS v1 task priority

I’m using FreeRTOS v10.2.1, and CMSIS_RTOS v1, on STM32 MCU. main.c, as generated by CubeMX, has:

osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);

where osPriorityNormal is zero as defined in cmsis_os.h

There is another task, lwip, that is also created with osPriorityNormal priority.

I spawn all my tasks using the FreeRTOS xTaskCreate() call where task priority is from 0…MAX_PRIORITIES-1. How does FreeRTOS task priority map to CMSIS task priority if it maps at all? How do the tasks with osPriorityNormal get scheduled against those tasks created with xTaskCreate?

I generated the code for CMSIS_RTOS v1 for STM32H743ZI and here are my findings:

This is the code which defines CMSIS priority:

typedef enum  {
  osPriorityIdle          = -3,          ///< priority: idle (lowest)
  osPriorityLow           = -2,          ///< priority: low
  osPriorityBelowNormal   = -1,          ///< priority: below normal
  osPriorityNormal        =  0,          ///< priority: normal (default)
  osPriorityAboveNormal   = +1,          ///< priority: above normal
  osPriorityHigh          = +2,          ///< priority: high
  osPriorityRealtime      = +3,          ///< priority: realtime (highest)
  osPriorityError         =  0x84        ///< system cannot determine priority or thread has illegal priority
} osPriority;

The CMSIS osThreadCreate function eventually calls xTaskCreate in the file cmsis_os.c and here is the function which maps CMSIS priorities to FreeRTOS priorities:

/* Convert from CMSIS type osPriority to FreeRTOS priority number */
static unsigned portBASE_TYPE makeFreeRtosPriority (osPriority priority)
{
  unsigned portBASE_TYPE fpriority = tskIDLE_PRIORITY;
  
  if (priority != osPriorityError) {
    fpriority += (priority - osPriorityIdle);
  }
  
  return fpriority;
}

Thanks.

Thanks! That’s exactly what i’m looking for.