Problem to give semaphore with xSemaphoreGiveFromISR()

Hello everybody,

I am currently working on a STM32F446RE project and use as
Operating system FreeRTOS. With FreeRTOS I am still a bit new and
I’d like to acquire the know-how.

With the Timer2 I have created an interrupt which is generated every 10s
is coming. The interrupt works so far so well (Tested with LED Pin

Now I have created an Event Task in which the whole
Main program after the init of the peripherals should run.
void event_handler_task(void *pvParameters)
SemaphoreHandle_t init_synchronization = (SemaphoreHandle_t) pvParameters;

MX_TIM2_Init(); //Timer 2 init
HAL_TIM_Base_Start_IT(&htim2); //Timer 2 start interrupt

event_binary = xSemaphoreCreateBinary();


for (;:wink:
if (xSemaphoreTake(event_binary, portMAX_DELAY) == pdTRUE)
sprintf(debug_string, “We are in the Event Task!”);

vTaskDelay(1000 / portTICK_RATE_MS);


The BinarySemaphore for this I have created Global in the same file:
static SemaphoreHandle_t event_binary = NULL;

The interrupt function looks like this:
void TIM2_IRQHandler(void)
static BaseType_t xHigherPriorityTaskWoken = pdFALSE;

xSemaphoreGiveFromISR(event_binary, &xHigherPriorityTaskWoken);

if( xHigherPriorityTaskWoken == pdTRUE)



My problem now is that if I leave all the debugging to the
controller at xSemaphoreGiveFromISR. The code is only written up to
of this function and when I stop the debugger I am in
the following function:
configASSERT( pxQueue );

Behind the configASSERT there is an infinite life if the value of
is passed is 0.

My question now, am I using the wrong function or have I used it
incorrectly initialized?

Seems that the interrupt/TIM2 kicks in before event_handler_task is created resp. created the semaphore.
I‘d propose that peripheral handler tasks should init and start the peripheral(s) they‘re dealing with by itself at the right point to avoid additional synchronization and get better encapsulation, too.

Thanks, the first interrupt was before creating the semaphore. Now it works! :slightly_smiling_face:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.