cancel
Showing results for 
Search instead for 
Did you mean: 

Best method for returning to STOP Mode after Interrupt (STM32L0)

videojames
Associate III

Hello,

So I have a project which uses STOP mode with RTC+EINT pins for wakeup. However I have a situation where I want one of the interrupts to not wake up the device- just set a flag and return to STOP mode.

I know there is HAL_PWR_EnableSleepOnExit() but I believe this will put the processor into SLEEP mode instead of the desired STOP mode.

I thought using:

HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFE);

Would mean that I need to trigger an event after an interrupt to cause the wakeup but I don't believe that is the case- after the interrupt is finished it seems to return to the main loop instead of going back into STOP mode?

What I'm doing:

Enter Sleep:

/* Setup RTC wakeup */
 
HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, sleepDuration, RTC_WAKEUPCLOCK_CK_SPRE_16BITS);
 
 /* Power Control clock */
 
_RCC_PWR_CLK_ENABLE();
 
 /* Ultra low power mode */
 
_PWREx_EnableUltraLowPower();
 
 /* Before entering STOPMode function, it is important to ensure that the WUF wakeup flag is cleared */
 
_PWR_CLEAR_FLAG(PWR_FLAG_WU);
 
 /* Stop Mode */
 
_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFE);
 

RTC CallBack:

void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc) {
     /*  Wake Up Flag */
     _PWR_CLEAR_FLAG(PWR_FLAG_WU);
}

GPIO Call Back:

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  /* ALS wakeup line interrupt detected (Here is where I DON'T want the processor to return to Main Loop) */
  if (GPIO_Pin == Light_PA6_Pin && enableLight)
  {
    lightWakeup = 1;
  }
 
  /* Mag wakeup line interrupt detected (Wakeup- return to main loop) */
  if (GPIO_Pin == Hall_PB7_Pin && enableHall)
  {
    magWakeup = 1;
    
    /* Clear Wake Up Flag */
    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
  }
 
  /* Switch wakeup line interrupt detected (Wakeup- return to main loop)*/
 
  if (GPIO_Pin == Switch_PB15_Pin && enableSwitch)
  {
    switchWakeup = 1;
 
    /* Clear Wake Up Flag */
    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
  }
}

3 REPLIES 3
Uwe Bonnes
Principal II

In your startup, check the reset reason and act appropriate. After stop, a lot of things need reinitialization.

Sorry: Wrong answer

videojames
Associate III

Ok, I had a feeling that would be the answer- I was just hoping there might be some way to achieve the same result as "HAL_PWR_EnableSleepOnExit".

But it does make sense that that is not the case considering how much is turned off during stop.

videojames
Associate III

Actually, your answer is interesting.

"Check the reset reason"- When I come out of sleep I return to top of the loop, so is it really a reset?