STM32WB55: FreeRTOS osThreadFlagsWait can change behavior of osWaitForever
Hello, a while ago I ran into a problem with my system consuming to much power.
After searching this forum, I came across this post:
It describes how osThreadFlagsWait adjusts the timeout and explains that this can cause problems.
In the thread i described my problem with this function (see below), but I was asked to post that question in a new thread.
No problem, of course, so I did :)
I discovered another annoying problem with osThreadFlagsWait.
I was measuring the current consumption to check if it was sufficiently low in case the system goes into stop2.
To my surprise, I discovered that it wasn't (draining 6mA instead of 30uA).
After a long search, I discovered that the high-consuming task state wasn't "suspended", but "blocked"!
A little later, I realized this would happen when I called osThreadFlagsWait.
I assumed the timout value could be osWaitForever, so the task would sleep (and thus be suspended) until a signal arrives.
However, in a similar scenario, tout -= td becomes the result; what's done essentially amounts to timeout -= td.
Therefore, timeout != osWaitForever, and xTaskNotifyWait (wrapped in osThreadFlagsWait) will notice this and set a very long timeout.
This causes the behavior to be different (the task is blocked, not suspended).
I've currently tested this as a solution:
if (timeout != osWaitForever) {
if (td > tout) {
tout = 0;
}
else {
tout -= td;
}
}
if (timeout != osWaitForever)
{
if (td >= timeout)
{
tout = 0;
}
else
{
tout = (timeout - td);
}
}
Is this a correct sollution?
I am also using stm32wb55 and STM32CubeIDE (Version: 1.19.0 Build: 25607_20250703_0907 (UTC)) as tool to configure the hw and generate code.
It generated the FreeRTOS code (FreeRTOS Kernel V10.3.1.h states: FreeRTOS Kernel V10.3.1)
