Skip to main content
LMenc.1
Associate II
November 14, 2022
Solved

STM32U5 Can't exit STOP2 mode with LPTIM

  • November 14, 2022
  • 3 replies
  • 3059 views

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?

This topic has been closed for replies.
Best answer by Piranha

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.

3 replies

ST Technical Moderator
November 14, 2022

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

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
LMenc.1
LMenc.1Author
Associate II
November 17, 2022

Hello @Imen DAHMEN​,

I already checked the errata.

Thank you for the advice!

Piranha
PiranhaBest answer
Principal III
November 19, 2022

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.

EC.3
Associate III
November 17, 2023

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
November 17, 2023

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.