Skip to main content
Philipp Legrum
Visitor II
July 17, 2019
Question

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

  • July 17, 2019
  • 1 reply
  • 761 views

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.

This topic has been closed for replies.

1 reply

Bob S
Super User
July 17, 2019

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.