I too have observed this issue with FreeRTOS version 10.2.1 (as it is the one that Gets included in my project when I use STM32CubeMX to generate code for STM32H7xx microcontroller).
What I found out is that when xTaskNotifyWait() API has two code lines listed below:
and
which are concerning.
My code’s has an ISR that calls xTaskNotifyFromISR(). The ISR would usually trigger sometime after taskEXIT_CRITICAL(); i.e.
is triggered but the next line has not executed.
In above case, the Notify does not work as expected.
I did not had an immediate fix, so I had to add an osDelsy(8) in the ISR just before making a call to xTaskNotifyFromISR().
I know this is not the correct / right solution, but no other fix is known to me.
Can you post the relevant code signaling the notification in ISR and waiting for/processing it in the task ? Do you use the notification exclusively for signaling this interrupt event to the post-processing task ? I think it might be just a misunderstanding or usage issue.
Is it possible for you to share an email where I can share the code parts related with this communication thread. I otherwise will have to modify the function before posting it here (as it uses proprietary product names).
I will need some time to share the modified code here.
I think it should be fine to post just the lines with giving the notification and taking it (maybe with adjusted variable names). Since notifications can be used for different scenarios or modes depending on the arguments used, it’s possible to get it wrong for the intended purpose. That’s why I’m asking for it
Given that your real code uses xTaskNotifyGiveFromISR in the ISR I suspect that the issue is caused by the surrounding code e.g. dealing with bSignalProprietaryPrInput and bSignalProprietaryInput flags in the ISR and the po_C__ProprietaryDataIn pointer in the task.
In fact your notification signaling mechanism depends on some other (shared ?) flags and variables which could be easily handled slightly wrong causing a subtle race condition.
Then sometimes a delay here and there seem to solve a problem but just (unreliably) works around a symptom.
Sorry - your notification API calls are right and I’m convinced the FreeRTOS notification implementation is correct even if I don’t have a STM32H7 MCU, but others. I’d carefully review the usage of all those flags/variables and would try to get rid of as much as possible, because they make the code very complex and hard to get right.
Not sure how that is even possible, if the osDelay() is waiting for the tick interrupt and the tick interrupt has the lowest priority.
It is not immediately clear what the issue is in that, what is not working, and where does the interrupt occur - I’m assuming between the taskEXIT_CRITICAL() and taskENTER_CRITICAL() in the code you posted above. What makes you concerned about these lines? I’ve never seen a problem here and the code is extensively tested - however different devices have difference characteristics and different compilers do different things. If you can repeat the issue try adding a memory barrier between the exit and re-entry of the critical section. In GCC that can be done by adding: __asm volatile( “” ::: memory );
If one checks the code associated with taskENTER_CRITICAL() one would observe a call made to portDISABLE_INTERRUPTS()
When referring to file tasks.C, it is understood that the Interrupt would have occurred after Line number 4768 got executed and before line number 4804 executed. The interrupt can however be serviced only after Line Number 4802 gets executed.
Thanks for the additional information but it is not clear what the issue is. The critical section is exited then reentered specifically to allow interrupts to execute - so they are not held disabled too long. So the behaviour you describe so far is intended. Are you saying allowing interrupts to execute at that point is creating a race condition or other issue if the interrupt is sending or otherwise using the notification that is being waited for by that function call?
I have been working on a different project these days. It would be hard for me to move to the (earlier) discussed project (whose code pieces I shared) and take out code pieces to come up with a small project. I am not sure how I will ensure that the while the Notify Take function parts are executing, the code execution triggers a Notify Give (which is necessary for triggering the earlier shared concern).