[Bug] CMSIS-RTOS V2 has incorrect implementation of osFlagsWaitAll option for osEventFlagsWait()
Outlined the bug on github page for L4 firmware pack: https://github.com/STMicroelectronics/STM32CubeL4/issues/7
Thought someone might find this useful until its fixed. Details below.
The set-up
* Custom board using STM32L452CCUx MCU
* STM32CubeIDE v1.3.1 under Windows 10 x64 using STM32CubeL4 pack v1.15.1
* FreeRTOS v10.2.1 with CMSIS-RTOS v2.00
Description of the bug
Incorrect implementation of `osFlagsWaitAll` option for `osEventFlagsWait()` is causing incorrect code functioning. When using `osEventFlagsWait()` function with `osFlagsWaitAll` I expect that the thread calling gets unblocked when *all* of the *specified* flags are set. However if any other flags (additional to specified) are also set - `osEventFlagsWait()` returns with `osErrorTimeout`. This happens even with `osWaitForever` timeout, which is nonsense.
Problem lies in the ST's wrapper around FreeRTOS function `xEventGroupWaitBits()`. If more flags then specified are set - the function will report error, which shouldn't happen.
Specifically this check on cmsis_os2.c line 1179 is causing the bug. Here is the piece of code around those lines:
rflags = xEventGroupWaitBits (hEventGroup, (EventBits_t)flags, exit_clr, wait_all, (TickType_t)timeout);
if (options & osFlagsWaitAll) {
if (flags != rflags) { // <--------- THIS IS A BUG
if (timeout > 0U) {
rflags = (uint32_t)osErrorTimeout;
} else {
rflags = (uint32_t)osErrorResource;
}
}
}
else {
if ((flags & rflags) == 0U) {
if (timeout > 0U) {
rflags = (uint32_t)osErrorTimeout;
} else {
rflags = (uint32_t)osErrorResource;
}
}
}Proposed solution
Replace the buggy condition check:
if (flags != rflags) { // <--------- THIS IS A BUG
// ...
}with a correct one:
if ((flags & rflags) != flags) { // <--------- THIS IS CORRECT IMPLEMENTATION
// ...
}--
Same problem is observed with STM32CubeF4 v1.25.0 pack and many others since they contain CMSIS-RTOS v2.00 Middleware implementation as well.
