2022-11-14 03:23 AM
Hi everyone,
I'm trying to enter STOP2 mode with a STM32U575 and exit from it with a LPTIM1 compare match. LPTIM1 is clocked with LSE, so it should be still working in STOP2 mode.
Here is part of my code in the main funtion:
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_LPTIM1_Init();
lptim_single(1024); //Around 2s, checked already
/* Infinite loop */
while (1)
{
/* Enter in Stop mode */
/* Set STOP2 mode when CPU enters deep sleep */
LL_PWR_SetPowerMode(LL_PWR_STOP2_MODE);
/* Set SLEEPDEEP bit of Cortex System Control Register */
LL_LPM_EnableDeepSleep();
__WFI();
LL_GPIO_TogglePin(GPIOH, LL_GPIO_PIN_0);
}
The function lptim_single:
bool lptim_single(int32_t t)
{
/* Set prescaler */
LL_LPTIM_Enable(LPTIM1);
LL_LPTIM_SetAutoReload(LPTIM1, t);
LL_LPTIM_OC_SetCompareCH1(LPTIM1, t/2);
LL_LPTIM_EnableIT_CC1(LPTIM1);
LL_LPTIM_EnableIT_ARRM(LPTIM1);
LL_LPTIM_StartCounter(LPTIM1, LL_LPTIM_OPERATING_MODE_ONESHOT);
return true;
}
It seems to enter in STOP2 mode but then it never exit unless I suspend the esecution with the debugger. Any suggestion?
Solved! Go to Solution.
2022-11-18 07:22 PM
For the timer to run in Stop mode, the LPBAM (low-power background autonomous mode) must be configured. And, for the WFI instruction to wake up the CPU from interrupt, it must be enabled in the NVIC.
2022-11-14 02:09 PM
Hello @Community member and welcome to the Community :)
Please have a look at the STM32U575xx STM32U585xx errata sheet and check if you have the same behavior as described in the errata for the device limitation.
When your question is answered, please close this topic by choosing Select as Best.
Imen
2022-11-17 01:22 AM
Hello @Imen DAHMEN,
I already checked the errata.
Thank you for the advice!
2022-11-18 07:22 PM
For the timer to run in Stop mode, the LPBAM (low-power background autonomous mode) must be configured. And, for the WFI instruction to wake up the CPU from interrupt, it must be enabled in the NVIC.
2023-11-17 11:28 AM
Hi @Piranha ,
Where can I find info on configuring LPBAM to support wakeup from LPTIM autoreload match? I came across an5816-how-to-build-stm32-lpbam-application-using-stm32cubemx-stmicroelectronics.pdf , but that seems like it's for more involved use cases involving continuous data transfer. Is there a more straightforward example for this?
Thanks
2023-11-17 01:13 PM
It seems for the basic case of LPTIM timed wakeup from STOP2, the general solution provided in this post works. In this context, use __HAL_RCC_LPTIMx_CLKAM_ENABLE(), where x can be 1, 3, or 4. LPTIM2 doesn't work in STOP2.