AnsweredAssumed Answered

STM32CubeF4 FreeRTOS Examples don't work correctly with HAL GetTick

Question asked by Dan K. on May 26, 2014
Latest reply on May 30, 2014 by Dan K.
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

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:
  1. in HAL_Init()
  3. in SystemClock_Config()
  5. in vTaskStartScheduler()
Also, HAL code initializes and expects the SysTicks generated to be 1 mS ticks, but the FreeRTOS can easily be configured (via FreeRTOSConfig.hconfigTICK_RATE_HZ) to be another value, which would cause the HAL-related timeouts to be incorrect.