cancel
Showing results for 
Search instead for 
Did you mean: 

ThreadX systick code generation

EmbDev
Senior

For my project I'm using an STM32L476 MCU with CubeIDE 1.15.1 and CubeMX 6.11.1
In this project I'm using ThreadX / Azure RTOS.

For a new feature I doubled the speed of the MSI, which doubles the system clock, but the HCLK stays the same (by changing the prescaler).
Now when I click regenerate code in CubeMX, the values for the systick are doubled in the tx_initialize_low_level.s
So as an overview

 Old valueNew value
MSI1 MHz2 MHz
SysClk1 MHz2 MHz
HClk1 MHz1 MHz
SYSTEM_CLOCK var in tx_initialize_low_level.s1 MHz2 MHz

The SYSTEM_CLOCK var in tx_initialize_low_level.s is used to configure the SysTick.
To me this looks like a bug in the generator as the System clock does not affect the SysTick (the HClk does)?

4 REPLIES 4
Sarra.S
ST Employee

Hello @EmbDev

As indicated in the tx_initialize_low_level.s description, the _tx_initialize_low_level function is responsible for configuring the SysTick timer to generate periodic interrupts. the SYSTEM_CLOCK must correspond to the system clock

If you want to change the ThreadX tick, you can always change SYSTICK_CYCLES definition in tx_initialize_low_level.S : SYSTICK_CYCLES = ((SYSTEM_CLOCK / 1000) -1), of course, TX_TIMER_TICK_PER_SECOND must also be updated.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Thanks Sarra, for me it's confusing to calculate / configure the SysTick timer using the System Clock instead of the Hardware clock.
The SysTick is directly driven by the Hardware Clock, so the calculation is done with an irrelevant value/clock.

When the System Clock is used in the calculation, I can indeed use the TX_TIMER_TICK_PER_SECOND variable to change the division for the SYSTICK_CYCLES (the division is generated by CubeMX so should not be manually changed). The TX_TIMER_TICK_PER_SECOND value (in the CubeMx configuration) is used for both the variable (in the tx_user.h) and the calculation (the value 1000 in the example above). In this case I have a value that is related to the system clock, so I cannot use this variable (TX_TIMER_TICK_PER_SECOND) anywhere else as it is incorrect.

Example:

System Clock 2 MHz, Hardware Clock 1 MHz
To get 1000 ticks per second, TX_TIMER_TICK_PER_SECOND is set to 2000 (2MHz / 2000 = 1000)
The actual value of TX_TIMER_TICK_PER_SECOND should be 1000 as the Hardware Clock is 1 MHz.

What am I missing here? What is the reason to use the completely irrelevant System Clock in this calculation?

EmbDev
Senior

Can anyone explain / help me with this issue ( @Sarra.S ) ?

Sarra.S
ST Employee

Hello @EmbDev

Sorry for the confusion, you are right! 

I tested it first with a nucleoU575 having it onboard, this issue wasn't reproduced 

but with STM32L476 MCU I can confirm this issue, systick should be driven by the hardware clock HCLK, but in this case, it's driven by sysclk when AHB>1 

I've reported this issue to the CubeMX team (Internal ticket number: 185523), I will keep you updated! 

Thank you!

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.