Startup FreeRTOS 9.0.0, STM32F4, interrupt before starting scheduler – hang

Using FreeRTOS 9.0.0, when I start my program on a STM32F407 MCU, it will hang in the interrupt routine (crash, in xTaskIncrementTick(), on this line: ~~~ xItemValue = listGETLISTITEM_VALUE( &( pxTCB->xStateListItem ) ); ~~~ All elements in pxTCB are 0. This happens before the vTaskStartScheduler() is called (during the creation of the tasks / hardware etc) To “solve” this I do ~~~ static int freeRTOSstarted = 0; … main(){ HALInit(); HALResumeTick(); // Initialize hardware, starting tasks, and do other initialization…. freeRTOSstarted = 1; vTaskStartScheduler(); } void SysTickHandler(void) { HALIncTick(); HALSYSTICKIRQHandler(); if (freeRTOSstarted) { xPortSysTickHandler(); } } ~~~ But is this the right way? Or did I overlook something?

Startup FreeRTOS 9.0.0, STM32F4, interrupt before starting scheduler – hang

This happens before the vTaskStartScheduler() is called (during the creation of the tasks / hardware etc)
You should not allow tick interrupts to execute until the scheduler has started. If they are executing then something else is enabling the SysTick interrupt. Simply calling taskENTER_CRITICAL() will prevent that happening (assuming all interrupt priorities are set correctly) – the critical section will be exited when the scheduler starts. You need to find why the SysTick interrupt, which executes the tick interrupt, is executing before you have started the scheduler.

Startup FreeRTOS 9.0.0, STM32F4, interrupt before starting scheduler – hang

Thanks, that is what I wanted to know. The HALResumeTick() is starting the ticks (is needed in hardware initialization). For now I will do it like I did specify, with a flag (in my example: freeRTOSstarted) Will look at your suggestion with taskENTERCRITICAL() later as well.