Getting stuck in vListInsert() on Semaphore Wait

Hello!
I have read the comment in function vListInsert(). But it’s a bit tricky to troubleshoot.
The bug happens when the execution flow is as follow:
(1) semaphore ‘sem’ is created by thread func and initialized as 0
(2) Thread func called xSemaphoreTake() to block and wait infinitely for the semaphore sem
(3) In the for(;;) loops, when it calls prvLockQueue() and enter the vTaskPlaceOnEventList(), an interrupt comes simultaneously. The interrupt handler called “xSemaphoreGiveFromISR()” , and then “portYIELD_FROM_ISR()” if pxHigherPriorityTaskWoken is set to true. The semaphore is released.
(4) Thread func entered vListInsert() and stucked.

If the semephore is released by the IRQ handler before prvLockQueue() being called, this bug doesn’t happen.

I’m stuck on this problem and I‘m not sure where to start with. Does anyone have any ideas?

Thank you for your time!

This sounds like the sort of problem that happens if the ISR has too high of a priority. Note “too high” on Cortex-M processors means too low of a value. This makes the critical section used by prvLockQueue ineffective and corruption occurs.

Incorrectly configured ISR priorities should be caught by configASSERT. Have you defined configASSERT in your FreeRTOSConfig.h?

Yes, I’ve defined configASSERT, but it’s not being triggered.

Which FreeRTOS port and which FreeRTOS version are you using? Can you share your task and ISR definitions?