cancel
Showing results for 
Search instead for 
Did you mean: 

Low power timer and interrupt

iot999
Associate

Hello everyone, 

I'm currently working with an STM32 MCU and STM32CubeIDE. I'm encountering difficulties with a Low Power Timer (LPTIM) and sleep mode implementation. In my design, I need the MCU to go into a low-power sleep mode and wake up when a certain interrupt is triggered (EXTI) or after a specific time duration.

The general idea is to have two different conditions:

  1. If an EXTI interrupt hasn't been triggered, I need the MCU to reset after 15 LPTIM interrupts.
  2. If the EXTI interrupt is triggered, I need the MCU to reset after 3 LPTIM interrupts.

My main problem is that the MCU doesn't seem to re-enter the LPTIM interrupt handler after waking up from the first interrupt. I've tried managing the counter inside the interrupt handlers and restarting the LPTIM there, but it didn't solve the issue. I also attempted to use a flag to monitor the MCU's state and decide when to enter sleep mode.

The main loop and the sleep function setup are as follows:

while (b_wkup)
{
// ... some code ...

b_wkup = false;


SetLowPowerMode();
}

void SetLowPowerMode(void)
{
// ... setup code ...

HAL_LPTIM_TimeOut_Start_IT(&hlptim1, 0xFFFF, 2500);
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
}

I've confirmed that the interrupt configurations are correct and that the handlers are correctly called for the first interrupt. However, it appears that the MCU doesn't re-enter the interrupt handler after waking up from the sleep mode. These are my interrupt handlers : 

void EXTI15_10_IRQHandler(void)
{
/* USER CODE BEGIN EXTI15_10_IRQn 0 */

/* USER CODE END EXTI15_10_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(INT2_Pin);
/* USER CODE BEGIN EXTI15_10_IRQn 1 */
b_movement = true;

/* USER CODE END EXTI15_10_IRQn 1 */
}

/**
* @brief This function handles LPTIM1 global interrupt.
*/
void LPTIM1_IRQHandler(void)
{
/* USER CODE BEGIN LPTIM1_IRQn 0 */

/* USER CODE END LPTIM1_IRQn 0 */
HAL_LPTIM_IRQHandler(&hlptim1);
/* USER CODE BEGIN LPTIM1_IRQn 1 */

if (true==b_movement) {
timeout_mov++;}
if(timeout_mov >= 3) {
b_movement = false;
timeout_mov = 0;
HAL_NVIC_SystemReset();
}

else if (false==b_movement) {
timeout++;}
if (timeout >= 15) {
timeout = 0;
HAL_NVIC_SystemReset();
}
HAL_LPTIM_TimeOut_Start_IT(&hlptim1, 0xFFFF, 2500);
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);

 

/* USER CODE END LPTIM1_IRQn 1 */
}

thank you for your help

1 REPLY 1
iot999
Associate

Please let me know if you need any further explanation. thanks