2019-07-17 06:07 AM
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.
2019-07-17 08:05 AM
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.