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

digdas wrote on Wednesday, April 04, 2018:

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 = listGET_LIST_ITEM_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(){
	HAL_Init();
	HAL_ResumeTick();
// Initialize hardware, starting tasks, and do other initialization....
	freeRTOSstarted = 1;
	vTaskStartScheduler();
}
void SysTick_Handler(void) {
	HAL_IncTick();
	HAL_SYSTICK_IRQHandler();
	if (freeRTOSstarted) {
		xPortSysTickHandler();
	}
}

But is this the right way? Or did I overlook something?

rtel wrote on Wednesday, April 04, 2018:

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.

digdas wrote on Thursday, April 05, 2018:

Thanks, that is what I wanted to know. The HAL_ResumeTick() 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 taskENTER_CRITICAL() later as well.