Skip to main content
Explorer II
January 21, 2025
Solved

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

  • January 21, 2025
  • 1 reply
  • 903 views

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?

    This topic has been closed for replies.
    Best answer by Andrew Neil

    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

     

    1 reply

    Super User
    January 21, 2025

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

    What STM32L4, exactly, are you using?

    hlmn7Author
    Explorer II
    January 21, 2025

    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.

    Super User
    January 21, 2025

    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