cancel
Showing results for 
Search instead for 
Did you mean: 

FreeRTOS + SystemClock Behavior

ma-hara
Associate II

Hello,

I am using STM32L4A6VGTxP with CubeIDE and want to create a system with FreeRTOS.
However, I am having the following problem when running the system under FreeRTOS while changing the SystemClock.
Is there a solution?


Configuration
・Custom boards using the STM32L4A6VGTxP microcontroller
・Using STM32CubeIDE v1.9.0
・Firmware Package STM32Cude FW_L4 V1.17.2
・FreeRTOS v10.3.1 with CMSIS v2

Problem Description
FreeRTOS is initialized with the system clock set at HSI 16MHz at microcontroller startup.
If the system clock is subsequently changed, the OS time remains set at 16MHz.
How can I synchronize the OS time when the system clock is changed?

For example
(1) If you change the system clock from HSI 16MHz to HSI 80MHz
-> osDelay(1000), the Delay time will be 250ms
  Execute osEventFlagsWait(ef_id, flags, options, 1000), the timeout time will be 250ms
  When HAL_Delay(1000) is executed, Delay time becomes 1000ms.

(2) When changing from HSI 16MHz to MSI 4MHz
→When osDelay(1000) is executed, Delay time becomes 4000ms
  When osEventFlagsWait(ef_id, flags, options, 1000) is executed, timeout time becomes 4000ms
  Execute HAL_Delay(1000), Delay time will be 1000ms

Thank you.

 

4 REPLIES 4
ma-hara
Associate II

There was a mistake in the description of the example.
The following is the correct execution result.

For example
(1) If you change the system clock from HSI 16MHz to HSI 80MHz
→osDelay(1000), the Delay time will be 200ms
  Execute osEventFlagsWait(ef_id, flags, options, 1000), the timeout time will be 200ms
  When HAL_Delay(1000) is executed, Delay time becomes 1000ms.

(2) When changing from HSI 16MHz to MSI 4MHz
→When osDelay(1000) is executed, Delay time becomes 4000ms
  When osEventFlagsWait(ef_id, flags, options, 1000) is executed, timeout time becomes 4000ms
  Execute HAL_Delay(1000), Delay time will be 1000ms

Thank you.

 

Piranha
Chief II

Isn't it obvious? Reconfigure the timer, on which the OS ticks are based!

Thank you for your answer.

Let me explain in more detail.

When SystemClock is changed from 16MHz to 80MHz,
If we use Systick for Timebase Source,
Delay time for HAL_Delay(1000) and osDelay(1000) is the same at 1000ms.

However, when TIM6 is used for Timebase Source,
Delay time for HAL_Delay(1000) is 1000ms, but Delay time for osDelay(1000) is 200ms.

When using RTOS with STM32CubeIDE, it is strongly recommended to use a HAL timebase source other than Systick.

I do not understand why there is a difference in delay time between HAL_Delay and osDelay when Timebase is set to TIM6.
I would also like to know what kind of reconfiguration would maintain 1Tick=1ms.
Thank you in advance for your help.

Thanks.

When using RTOS with STM32CubeIDE, it is strongly recommended to use a HAL timebase source other than Systick.


Because the RTOS uses SysTick for it's ticks and sets it to the lowest interrupt priority, but the HAL design requires the HAL timebase ticks to be incremented in the highest priority interrupt. So in the end, because of ST's code design, you have two tick timers. If you change the system clock, you have to readjust both of them.

Edited by moderators to adhere to community guidelines.