cancel
Showing results for 
Search instead for 
Did you mean: 

differentiate wake-up reason between two interrupts: RTC & GPIO_EXTI ?

hlmn7
Associate

In my system, I initialised two interrupts for wake-up from STOP2 mode, after exiting STOP2 mode, how do I know that the system is waking up by RTC timer or interrupt pin? Is there any variable that I can check after waking up to find the reason why the system is wake?

4 REPLIES 4

Set flags in your interrupt handlers which indicate which one occurred.

What STM32L4, exactly, are you using?

I am using STM32L476RG, actually I don't get it, I already tried to check flag before and after using this code:

  if (__HAL_RTC_WAKEUPTIMER_GET_FLAG(&hrtc, RTC_FLAG_WUTF) != RESET)
  {
    // Wake-up event detected, clear the flag
    __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF);

    // Your code to turn on the LED or perform other actions
    printf("Wake-up event detected, clear the flag\n");
  }
  // Check GPIO 7 interrupt pin Flag
  if(__HAL_GPIO_EXTI_GET_FLAG(GPIO_PIN_7) != RESET)
  {
    // Wake-up event detected, clear the flag
    __HAL_GPIO_EXTI_CLEAR_FLAG(GPIO_PIN_7);

    // Your code to turn on the LED or perform other actions
    printf("Wake-up event detected by interrupt pin, clear the flag\n");
  }

 However, both states are in RESET and the reason not printed out.

I mean you create your own flags in your software - the hardware interrupt flags will have been cleared by the handlers.

volatile bool rtc_interrupt_occurred;
volatile bool exti_interrupt_occurred;

Using HAL, you could set them in the callback; eg,

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  /* Prevent unused argument(s) compilation warning */
  UNUSED(GPIO_Pin);

  exti_interrupt_occurred = true;
}

and then test in your main-line code

 

Thanks a lot for the explanation, I will test it, will come back later