Skip to main content
dtpnilsson
Associate II
March 25, 2020
Question

STM32L051 Stop Mode and LPTIM interrupt

  • March 25, 2020
  • 1 reply
  • 1000 views

I use HAL to go to STOP mode with interrupt (WFI), but the microcontroller immediately exits stop mode.

I have LPTIM setup with HAL_LPTIM_Counter_Start_IT() to give interrupt after a few seconds, but even without setting up LPTIM I can't get the microcontroller to stay in STOP mode.

Perhaps some interrupt keeps it from going to STOP mode? Where do I look? I don't have enough experience debugging, any help appreciated.

HAL_SuspendTick(); // avoid systick interrupt waking up core from stop mode
 
HAL_LPTIM_Counter_Start_IT(&hlptim1, (uint32_t)(4*1156));
__HAL_LPTIM_CLEAR_FLAG(&hlptim1,LPTIM_IER_ARROKIE);
__HAL_LPTIM_CLEAR_FLAG(&hlptim1,LPTIM_IER_CMPMIE);
__HAL_LPTIM_DISABLE_IT(&hlptim1,LPTIM_IT_ARROK);
__HAL_LPTIM_DISABLE_IT(&hlptim1,LPTIM_IT_CMPM);
 
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); // says to run this before entering stop mode
	HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); // enter stop mode
 
HAL_LPTIM_Counter_Stop_IT(&hlptim1); // stop timer
// Exit Stop mode
SystemClock_Config(); // setup clocks after sleep
 
 
HAL_ResumeTick(); // resume systick interrupt

0693W000000Uh88QAC.png

This topic has been closed for replies.

1 reply

dtpnilsson
Associate II
April 1, 2020

It magically works now, I don't know why.

Thanks.