Binary semaphore Take causing infinite loop in listInsert

I have a problem with my project when using a binary semaphore to wait for an isr.

The setup is that I have one active task (and idle at a lower priority) and I call xSemaphoreTake.
When I call this, the cpu hangs in vListInsert trying to insert the task into the semaphore pending list. This is because the task is already in this list.

A little bit of tracing shows:

  • call xSemaphoreTake
  • insert task into semaphore
  • remove task from ready
  • call xTaskResumeAll (returns false)
  • insert task into semaphore

The resumeAll is trying to switch to another task, but there are no others but this one at this priority. Then xQueueSemaphoreTake goes around the for loop again, and re-inserts the task into the queue.

Is there something I have misconfigured here? This all works fine if there is another task to take up the yield, but in some cases there will not be.

Specifics: FreeRTOS 10.3.1 STM32 cortex-M4 gcc

That’s strange. Normally there is always the mandatory Idle task.
Without creating any application task and just starting the scheduler you could verify that the Idle task is running at the lowest prio (usually 0).
Do you also have configASSERT defined and enabled stack overflow checking ?

The idle task is present, and can run, but is a lower priority so the YIELD is not taking the scheduler there.

I had entered a critical section, so the SVC to reschedule did not happen.