cancel
Showing results for 
Search instead for 
Did you mean: 

How do I change the initialization order to avoid a race condition (ISR vs. FreeRTOS init) during initialization?

Philipp Legrum
Associate II

CubeMX generates the main.c like this:

int main(void)

{

...

 MX_GPIO_Init();

 MX_RTC_Init();

 MX_NVIC_Init();

 MX_FREERTOS_Init();

...

}

We observe a sporadic crash during boot which we traced to an GPIO interrupt whose ISR calls into the FreeRTOS API (xQueueSendToBackFromISR) before MX_FREERTOS_Init(); has been called.

Moving MX_NVIC_Init(); below MX_FREERTOS_Init(); reliably fixes the situation for us. How can we tell CubeMX to generate the init code persistently in that order. As of now, we must manually change the init order after each code regeneration.

1 REPLY 1
Bob S
Principal

Tell CubeMX not to enable that GPIO interrupt (EXTIx), then add your own code either at the end of MX_FREERTOS_Init() or later in main() to manually enable the interrupt, Same goes for ANY interrupt that could possible call RTOS functions - don't enable them until the RTOS is configured.