2021-06-09 04:19 PM
Im attempting to put the cpu to sleep between ticks of timer 15 on a stm32L432, The LED flashs without the Sleep code however it never wakes up from the timer interupt
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef * htim) {
HAL_ResumeTick();
if (htim -> Instance == TIM15) {
HAL_GPIO_TogglePin(GPIOB, LD5_Pin);
HAL_SuspendTick();
HAL_PWR_EnableSleepOnExit ();
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
}
}
2021-06-09 05:23 PM
Fairly sure WFI should be called from the main loop and not the interrupt. Enabling sleep on exit is something you only need to do once, before the WFI instruction. It will go back to sleep when it exits the handler.
Not sure what you're trying to do with the ticks by resuming and then immediately suspending them again. I would imagine you'll need to do something else. Or just leave them suspended. Or call HAL_IncTick manually within the timer update.
2023-09-12 04:26 AM
I would suggest to trigger start your Sleep Entry in the while(1) loop. When the timer interrupt occurs the uC will wake. On the next while(1) execution the uC will enter sleep mode again. The awakening will be done on the timer interrupt. And so on.