Question
STM32L011 + systick + WFI problem
Hello,
my STM32L011's core is running at 32 MHz. I use systick for 1 ms interrupt. However, if i try to use the WFI inside my while loop in my delay function, the timebase changes from 1 ms to 6.28 ms. Any help is appreciated!
#include "user_systick.h"
volatile uint32_t coefficient_ms;
volatile uint32_t sys_ticks;
void SysTick_Handler(void){
sys_ticks++;
}
void user_systick_init(void){
coefficient_ms = 32000000 / 1000;
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk;
}
void user_systick_start(void){
NVIC_SetPriority(SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL);
}
void user_systick_stop(void){
SysTick->CTRL &= ~(SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk);
}
void user_systick_wait_ms(uint32_t delay_value){
SysTick->LOAD = (uint32_t)(coefficient_ms - 1UL);
SysTick->VAL = 1;
sys_ticks = 0;
SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk;
while(sys_ticks < delay_value){
//__WFI(); //If I uncomment this, I get a 6.28 ms timebase which is wrong.
}
}