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

**URL:** <https://forums.freertos.org/t/startup-freertos-9-0-0-stm32f4-interrupt-before-starting-scheduler-hang/7105>\
**Category:** Kernel\
**Created:** [April 4, 2018, 5:38pm UTC](https://forums.freertos.org/t/startup-freertos-9-0-0-stm32f4-interrupt-before-starting-scheduler-hang/7105 "2018-04-04T17:38:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 4, 2018, 5:38pm UTC](https://forums.freertos.org/t/startup-freertos-9-0-0-stm32f4-interrupt-before-starting-scheduler-hang/7105/1 "2018-04-04T17:38:36Z")

</div>

**[digdas](https://sourceforge.net/u/digdas/)** wrote on [Wednesday, April 04, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/ef1fa876/#c214):

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:

```auto
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

```auto
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?

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [April 4, 2018, 6:23pm UTC](https://forums.freertos.org/t/startup-freertos-9-0-0-stm32f4-interrupt-before-starting-scheduler-hang/7105/2 "2018-04-04T18:23:41Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Wednesday, April 04, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/ef1fa876/#c214/40d8):

> 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.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 5, 2018, 6:33pm UTC](https://forums.freertos.org/t/startup-freertos-9-0-0-stm32f4-interrupt-before-starting-scheduler-hang/7105/3 "2018-04-05T18:33:43Z")

</div>

**[digdas](https://sourceforge.net/u/digdas/)** wrote on [Thursday, April 05, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/ef1fa876/#620f):

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.
