Skip to main content
Aaron McNeil
Associate III
June 19, 2019
Solved

Low Power Timer Wake Up from Stop2 (stuck in interrupt)

  • June 19, 2019
  • 3 replies
  • 1367 views

I am using a STM32L476. I am using the counter mode on the low power timer to generate an interrupt after a given period. When I am in run mode, this interrupt works just fine. However, when I use the interrupt to try and wake the MCU from Stop2, I get stuck in the interrupt handler. It seems like the routine to clear the interrupt flags is not working properly. I tried to manually clear the interrupt flags in the IRQHandler instead of calling HAL_LPTIM_IRQHandler but this did not seem to work either.

Is this a known issue? Are there any workarounds? I really would like to make use of the LPTIM and Stop modes.

This topic has been closed for replies.
Best answer by Aaron McNeil

I found the problem I was having. I am using external SRAM in my application and before I go to sleep, I disable the SRAM. I have most things I need mapped to internal SRAM when in the sleep routine, but the hlptm1 handler is defined in my main file. So when the interrupt routine was using hlptim1 and the external SRAM wasnt reinitialized yet, it could not clear the flags.

3 replies

Mohamed Aymen HZAMI
ST Employee
June 20, 2019

Hello,

Can you please share your code ?

Best Regards,

Mohamed Aymen.

Aaron McNeil
Associate III
June 20, 2019

Yes. Here is a stripped down version of my code:

int main(void)

{

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

 HAL_Init();

  

 /* Configure the system clock */

 SystemClock_Config();

  

 init_hardware_peripherals();

 MX_RTC_Init(); 

 MX_LPTIM1_Init();

 __HAL_RCC_LPTIM1_CLK_SLEEP_ENABLE();

 create_semaphores();

 serial_start();   

 start_timer_interupts();

 create_tasks();

  

 /* Start scheduler */

 osKernelStart();

}

void enter_sleep_mode(void){

//Should generate at interrupt to wake MCU in 10 seconds.

 HAL_LPTIM_Counter_Start_IT(&hlptim1, 10240);

 deInit_peripherals();

 HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);

 SystemClock_Config();

 init_hardware_peripherals();

 start_timer_interupts();

}

static void MX_LPTIM1_Init(void)

{

 hlptim1.Instance = LPTIM1;

 hlptim1.Init.Clock.Source = LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC;

 hlptim1.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV32;

 hlptim1.Init.Trigger.Source = LPTIM_TRIGSOURCE_SOFTWARE;

 hlptim1.Init.CounterSource = LPTIM_COUNTERSOURCE_INTERNAL;

 if (HAL_LPTIM_Init(&hlptim1) != HAL_OK)

 {

  Error_Handler();

 }

}

void LPTIM1_IRQHandler(void)

{

 HAL_LPTIM_IRQHandler(&hlptim1);

}

If I use "HAL_LPTIM_Counter_Start_IT(&hlptim1, 10240);" without going into Stop mode, I successfully get an interrupt every 10 seconds. However, when I go into sleep mode, and the interrupt fires to wake up the MCU, the interrupt flags never clear and I am stuck in an endless loop inside the interrupt handler.

Aaron McNeil
Aaron McNeilAuthorBest answer
Associate III
June 20, 2019

I found the problem I was having. I am using external SRAM in my application and before I go to sleep, I disable the SRAM. I have most things I need mapped to internal SRAM when in the sleep routine, but the hlptm1 handler is defined in my main file. So when the interrupt routine was using hlptim1 and the external SRAM wasnt reinitialized yet, it could not clear the flags.