Changing the HSI clock speed before and after entering the sleep mode
Hello,
We are working on low-power product using STM32G030K8 MCU that has maximum HSI 16 MHz.
We are trying to decrease the power consumption using several ways.
One of them is to decrease the HSI clock speed before entering the sleep mode and then increase it again after exiting the sleep mode by changing the HSI clock divider as attached, but the application doesn't work well after that.
Does the code have any problems that make the application doesn't work well?
If it has, what is the correct way to change the clock speed at runtime before entering the sleep mode and after exiting?
void EnterSleepMode(void)
{
__HAL_RCC_HSI_CONFIG(RCC_HSI_DIV8);
__HAL_TIM_SET_PRESCALER(&htim1, 1);
__HAL_TIM_SET_PRESCALER(&htim3, 1);
HAL_SuspendTick();
HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);
HAL_ResumeTick();
__HAL_RCC_HSI_CONFIG(RCC_HSI_DIV1);
__HAL_TIM_SET_PRESCALER(&htim1, 15);
__HAL_TIM_SET_PRESCALER(&htim3, 15);
}
