Can't update SysTick->VAL
Hi,
In my system I use STM32L476.
In order to save power once every second, when heavy processing is done, I switch to PLL 80MHz, the rest of the time I use MSI clock at 32MHz.
In order to have a stable SysTick I update the reload value of the SysTick according to the desired clock, but I need to change the value of the current SysTick counter value to the relative value after clock change.
For some reason the SysTick counter value (SysTick->VAL) is always loaded with the reload value (minus 1 or 2). I can't seem to set the desired value to the counter.
What am I missing?
Here is my relevant code segment:
static volatile float new_systick_val;
enum SystemFaultsEnum status = eSYSTEM_OK;
uint32_t systick_reload_val;
/*
Here I change the clock to either 32MHz or 80MHz
if the desired clock is 80MHz
new_systick_val = SysTick->VAL * 319999.0f / (((float)SystemCoreClock/100.0f) - 1.0f);
and if desired clock is 80MHz
new_systick_val = SysTick->VAL * 799999.0f / (((float)SystemCoreClock/100.0f) - 1.0f);
*/
SystemCoreClockUpdate();
systick_reload_val = (uint32_t)((SystemCoreClock/100) - 1UL); /* set systick to 10msec */
SysTick->LOAD = systick_reload_val;
SysTick->VAL = (uint32_t)new_systick_val;Thanks
