2021-12-07 12:57 AM
Hello,
I'm using the Zephyr RTOS on a STM32F091 and have recently started working on implementing some low-power states (sleep and STOP). The system is fed by the PLL (48MHz) which is in turn fed by a HSE (20MHz).
I'm using the RTC peripheral to manage wake-ups, I simply set ALARMA at ~500ms before going to sleep.
What I see after waking up from STOP mode, is a bunch of garbage characters on the UART output and the whole system seemed to have slowed down significantly. A blinking LED for example, is now blinking much slower.
This is the code I use to enter the STOP mode:
//Switch to HSI clock before entering stop mode, needed so we can turn HSE off before entering (page 87 of RM)
/* Enable HSI if not enabled */
if (LL_RCC_HSI_IsReady() != 1) {
/* Enable HSI */
LL_RCC_HSI_Enable();
while (LL_RCC_HSI_IsReady() != 1) {
/* Wait for HSI ready */
}
}
/* Set HSI as SYSCLCK source */
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSI);
while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI) {
}
//Disable the HSE now that the HSI is enabled
LL_RCC_HSE_Disable();
LL_RCC_PLL_Disable();
LL_PWR_SetPowerMode(LL_PWR_MODE_STOP_MAINREGU);
LL_LPM_EnableDeepSleep();
//Disable SysTick interrupts so we don't immediately wake up
LL_SYSTICK_DisableIT();
//This calls __WFI();
k_cpu_idle();
Then this is called whenever the STOP mode is exited:
LL_LPM_DisableSleepOnExit();
//Restore clock configuration
stm32_clock_control_init(NULL);
//Re-enable the systick interrupt
LL_SYSTICK_EnableIT();
irq_unlock(0);
The stm32_clock_control_init(NULL) does the following in sequence:
I've verified that this does what it is supposed to do by checking the peripherals in a debug session, after this function, the RCC configuration is the same after exiting STOP as before entering STOP. Other users of Zephyr with the STM32 platform have used this function with success in the same use case as me.
Then however, a couple of instructions later, the RCC configuration is reset back to exit STOP conditions, i.e. HSI on, HSE and PLL off, HSI as system clock. This seems to happen asynchronously and I can't pinpoint why it happens.
This does not happen when I enter/exit sleep mode, only STOP.
I've verified that the Clock Security System is off.
Any help with this would be greatly appreciated, as I am grasping at straws at this point.
Thank you.
Solved! Go to Solution.
2021-12-08 10:12 AM
Thanks for coming back with the solution.
Please select your post as Best so that the thread is marked as solved.
JW
2021-12-09 12:09 AM
All done, thanks for your help!