Question
STM32CubeF4 FreeRTOS Examples don't work correctly with HAL GetTick
Posted on May 26, 2014 at 23:29
In the STM32CubeF4 FreeRTOS Application examples, any HAL functions that internally use the HAL_GetTick() function for timeout operations will not work correctly because the SysTick ISR has been assigned to the FreeRTOS xPortSysTickHandler() function without regard to HAL operations.
I think this can be corrected by calling HAL_IncTick() before calling xPortSysTickHandler() in SysTick_Handler() similar to as follows:void SysTick_Handler(void)
{
HAL_IncTick();
// for internal HAL function HAL_GetTick() use
// *must* be called last or a Hard Fault will be generated
xPortSysTickHandler();
}
Note: For some reason, if the xPortSysTickHandler() function is not called last in SysTick_Handler(), a Hard Fault exception will occur! Also note, it is quite confusing to see multiple instances of SysTick being initialized in these examples:
- in HAL_Init()
- in SystemClock_Config()
- in vTaskStartScheduler()
