Skip to main content
Harvey White
Senior III
Oct 19, 2026 11:42 PM UTC
Question

CMSIS_OS2 proper priorities when overlaid on FreeRTOS

Transitioning a working FreeRTOS project over to CMSIS_os2.  Got most of the bits and pieces to compile.  It’s not working (surprise).

At the  simplest level, the patch of code that turns on an LED, then calls osDelay does not delay.  

investigating the problem using vTaskDelayUntil (and bypassing the CMSIS_OS2 wrapper for this one call to eliminate the possibility that the error is in how the cmsis_os2 routine is somehow wrong), the problem is that the xTickCount never increments.  (HAL TICK works and increments).

This triggers an error routine because the new timetowake is computed as less that the existing time.  

Therefore, no delays.

Going through error reports suggests that the TickCount interrupt never triggers.  This seems to be true.

My thought is that the default priorities that are assigned are wrong, so in cmsis, which assigns interrupt priorities, is getting it wrong.  The main task is at priority 24 (PriorityNormal).   Tasks created for LED blinking are set at priority 26 and use osDelay (which calls vTaskDelay).

Any thoughts (code works with not using cmsis threads, so I’m blaming setups.

 

 

6 replies

Bob S
Super User
Oct 20, 2026 5:44 PM UTC

There is a lot of missing info here, so here are some general ideas:

RTOS task/thread priorities are NOT the same as hardware interrupt priorities.  There is no way for thread priorities to prevent the system tick timer (hardware) interrupt from getting serviced.

FreeRTOS expects to have control over the SYSTICK timer.  You must use a different timer for the HAL tick.  It seems you might already have that since your existing FreeRTOS build works, but verify this.  And verify that the SYSTICK and whatever timer you use for the HAL tick point to the right interrupt handlers.

 

 

Harvey White
Senior III
Oct 20, 2026 8:07 PM UTC

Missing information:

What would you like to see?

points:

  1. Timebase source is TIM17 (programming habit)
  2. HAL_Tick interrupt works as advertised
  3. I do nothing (that I know of) to change the hardware interrupts of anything.
  4. The item that is NOT changing is the sTickCount.  it seems very happy to stay at zero.  The delay until fails because the routine thinks it’s being asked for a negative delay.  
  5. I haven’t been able to figure out what should be incrementing it.
  6. This seems to be something to do with either the cmsis-os2 wrapper or something buried in FreeRTOS.
  7. Assuming that it’s not a hardware priority, then some software is making assumptions
  8. changing a task (LED DELAY) priority to either 1, 24 (normal), or 30 makes no difference.  
  9. it’s doing task switching, but the delay within that task is what’s not working.

 

 

Harvey White
Senior III
Oct 20, 2026 10:18 PM UTC

looks as if this code in cmsis_os2.c is not executed:

#if defined(SysTick)
#undef SysTick_Handler

/* CMSIS SysTick interrupt handler prototype */
extern void SysTick_Handler (void);
/* FreeRTOS tick timer interrupt handler prototype */
extern void xPortSysTickHandler (void);

/*
SysTick handler implementation that also clears overflow flag.
*/


#if (USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION == 0)
void SysTick_Handler (void) {
/* Clear overflow flag */
SysTick->CTRL;

if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
/* Call tick handler */
xPortSysTickHandler();
}
}
#endif
#endif /* SysTick */

the SysTick_Handler routine never gets executed.

 

Pavel A.
Oct 22, 2026 1:31 AM UTC

Check where the systick is set up and actually handled. With those “weak” functions, it may get wrong and could change between cmsis-rtos versions 1 and 2.

 

ST Employee
Nov 2, 2026 3:39 PM UTC

Hello ​@Harvey White ,

The task priorities are unlikely to be the cause. CMSIS-RTOS2 thread priorities and NVIC interrupt priorities are separate; changing a thread’s priority cannot make the FreeRTOS system tick run. osPriorityNormal being 24 is expected.

Since xTickCount stays at zero, I’d first check the tick interrupt path. Once the scheduler is running, the active SysTick_Handler must call the FreeRTOS port tick handler (xPortSysTickHandler()). Check which handler is actually linked and mapped to the SysTick vector, and whether another strong or custom SysTick_Handler is overriding the CMSIS-RTOS2/FreeRTOS wrapper. If USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION is enabled, make sure the custom implementation forwards the tick to FreeRTOS.

FreeRTOS normally uses SysTick for its kernel tick. Using TIM17 for the HAL tick is fine, but verify that the two timers have separate, correctly wired handlers: the HAL timer should advance the HAL tick, and SysTick should advance the FreeRTOS tick.

If you can share the active SysTick_Handler, the CMSIS-RTOS2/FreeRTOS versions, and the relevant tick settings from FreeRTOSConfig.h, it should be possible to narrow down why the handler isn’t being reached.

Kind regards, 

DHIF Khaled

 

"Please mark my answer as best by clicking on the “Accept as solution"" button if it fully answered your question. This will help other users find this solution faster.​"
Harvey White
Senior III
Nov 2, 2026 4:13 PM UTC

I can see the what, I’m not sure about the why, and there is, somewhere, a why.

Things that I consider:

  1. the code used to work.
  2. The code that I use I did not write.  This was standard, hidden in FreeRTOS, generated by CubeMX code.
  3. Looking at this and asking a question:  What changed?
  4. I installed an earlier version, CubeMX 6.17.0
    1. it works.
    2. so….
      1. it’s either the 6.19.1 version generating bad code, OR
      2. something changed in the ioc file BUT
      3. you can’t use the 6.19.1 version on 6.17.0
    3. I have yet  to devote the time to track this down
    4. Do you still want more information?
    5. I’ll attach the IOC file just because.  This should be the right one.