cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U5 Can't exit STOP2 mode with LPTIM

LMenc.1
Associate

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Piranha
Chief II

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.

View solution in original post

5 REPLIES 5
Imen.D
ST Employee

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

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
LMenc.1
Associate

Hello @Imen DAHMEN​,

I already checked the errata.

Thank you for the advice!

Piranha
Chief II

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.

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

EC.3
Associate III

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.