cancel
Showing results for 
Search instead for 
Did you mean: 

FreeRTOS priorities

JJRR
Senior

Please. In STM32CubeMX I want to set the same priority for RTOS timers and for tasks - what is equivalent of osPriorityNormal... what Number should I set for timer priority?

Thank you. Jan.

6 REPLIES 6
Bob S
Principal

Do you mean timers like TIM1, TIM2 (i.e. hardware timers on the STM32)? If so, hardware interrupt priorities are different than software RTOS task priorities. Hardware interrupts will ALWAYS interrupt ANY RTOS task unless the task disables interrupts. You can assign priorities to hardware interrupts (up to 16 levels, depending on how you configure the NVIC), so that, say, TIM6 will be able to interrupt the TIM2 interrupt handler. But, again, they all will interrupt RTOS tasks.

If you mean RTOS software-based timers ( from the CubeMX "Timers and Semaphores" tab), those timers run at whatever priority the the RTOS "timer task" uses. See the configTIMER_TASK_PRIORITY define in FreeRTOSConfig.h. This typically defaults to a very low priority.

JJRR
Senior

Sorry for unclear question. I mean RTOS software timers. Problem is that CubeMX defines the priorities of task like normal, above normal, high... but priority of os timer is defined by number. (Do not understand why..). So if I have priority of task normal - what number should I set for timer priority (..to maintain the same priority of task and os timer)... Hope my question is now clear?

Thank you very much.

Bob S
Principal

Yep - clear. And, yeah, it can be a pain/inconvenient that FreeRTOSConfig.h uses a number for the timer task priority instead of the enums. But, you have all the FreeRTOS source files. Did you try searching for osPriorityNormal (or whatever priority you want)? Be ware that there are TWO places where the osPriorityXXXX enums are defined, depending on whether you use cmsis 1 or 2.

JJRR
Senior

I tried, but...:

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;

OK.. if I analyzed it well, the normal priority is number 6, because of this:

tatic unsigned portBASE_TYPE makeFreeRtosPriority (osPriority priority)
{
  unsigned portBASE_TYPE fpriority = tskIDLE_PRIORITY;
  
  if (priority != osPriorityError) {
    fpriority += (priority - osPriorityIdle);
  }
  
  return fpriority;
}

Thank you very much :)

Bob S
Principal

Are you using CMSIS_V1? Because those are the priority values you listed above. And "normal" is not 6 is either CMSOS_V1 or CMSIS_V2. In CMSIS_V1 the "normal" used by FreeRTOS (as opposed to CMSIS "normal") is 3 based on the function you posted (tskIDLE_PRIORITY is zero, osPriorityIdle is -3 and osPriorityNormal is 0, for CMSIS_V1).

JJRR
Senior

You are right!

I use CMSIS_V1...OK It means:

fpriority = tskIDLE_PRIORITY = 0;

fpriority += (osNormal - osPriorityIdle) => fpriority += 0 - -3 = 0+3 = 3.

it means in CMSISV1 the osNormalPriority is equal to number 3. I should set the timer priority to 3 to have a same priority as tasks.

Thank you very much.