cancel
Showing results for 
Search instead for 
Did you mean: 

Why does task behavior change depending on priority in STM32 FreeRTOS?

eunoia
Associate II

I'm using an STM32G431 with FreeRTOS.

I have a total of 5 tasks, including the default task, and all of them were set to osPriorityLow.

With this configuration, the tasks did not run properly. When creating the tasks, NULL was not returned and no error occurred.

After changing all task priorities to osPriorityNormal, the problem was fixed.

I don't really understand why this happens. Each task has a reasonable osDelay(), so I don't think any specific task is blocking the others. Also, if a task were blocking, I would expect the same problem to happen even after changing the priority.

I also tried changing the heap size and the stack size, but that did not seem to be the cause.

Has anyone experienced a similar issue, or does anyone know why changing all tasks from osPriorityLow to osPriorityNormal would make a difference?

 

 

3 REPLIES 3
Andrew Neil
Super User

@eunoia wrote:

the tasks did not run properly.


What, exactly, do you mean by that ?

Please give details.

 

Note that there is a Windows port of FreeRTOS - perhaps use that to rule out anything STM32-specific?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
Pavel A.
Super User

osPriorityLow and osPriorityNormal are not priorities of FreeRTOS. They are defined in the CMSIS-RTOS wrapper. May be the behavior is caused by the CMSIS-RTOS wrapper that you use (provided by ST or custom).

 

Khaled_DHIF
ST Employee

Hello all, 

From what I tested, FreeRTOS itself does not seem to have any issue running five tasks at osPriorityLow. I built a simple project with five separate low-priority tasks, kept the default task minimal, and they all ran normally as long as each task actually blocked with osDelay().

That suggests the issue may not be the Low priority itself, but rather something else in your project that remains ready and keeps consuming CPU time. In other words, one or more tasks may not be blocking as expected, which can starve lower-priority work or prevent the system from behaving as intended.

I would also ask @eunoia : how exactly are the tasks not “running properly”?
For example, are they not starting at all, not switching as expected, or appearing to stall after some time?

 

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.​