2025-05-10 11:01 PM - edited 2025-05-10 11:09 PM
The HAL tick timer interrupts the MCU every 1 ms. When using FreeRTOS it is best to set the HAL Tick source to a timer rather than the system tick interrupt. Delays in freeRTOS are created using vTaskDelay() or vTaskDelayUntil() and don't use the HAL tick The HAL tick is only used by HAL drivers or in code before the scheduler is started.
For low power processors running at low clock speeds the HAL Tick if left enabled adds significantly to interrupt overhead with an interrupt every millisecond. To avoid this, once the HAL tick isn't required any more suspend it.
You can do this in the first task started by FreeRTOS viz:
/**
* @brief Function implementing the monitorTaskHnd thread.
* argument: Not used
* @retval None
*/
void monitorTask(void *argument)
{
HAL_SuspendTick();
...
while(1) // Task loop
{
...
}
}
You can also do it before the scheduler is started.
If you have to use a HAL driver that uses HAL_Delay() within a task, resume the HAL tick using HAL_ResumeTick() function, execute the HAL driver and then suspend the HAL tick.
There might be a "gotcha" when turning off the HAL tick. If a HAL Interrupt handler that you are using uses HAL_Delay in timeout loops you may need to turn the tick on before calling the handler and off on the return from the HAL IRQ handler. So check the HAL IRQ handlers you are using just in case.
Suspending the hal tick is not limited to projects using FreeRTOS, you can do it in programs using simple loops.
Moral of the story if you don't need to tick - turn it off.
Enjoy!