Skip to main content
Associate II
Jan 21, 2025 8:42 AM UTC
Solved

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

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.
Andrew Neil
Andrew NeilBest answer
Super User
Jan 21, 2025 9:20 AM UTC

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

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.

4 replies

Andrew Neil
Super User
Jan 21, 2025 8:48 AM UTC

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

What STM32L4, exactly, are you using?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
hlmn7Author
Associate II
Jan 21, 2025 9:12 AM UTC

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.

Andrew Neil
Andrew NeilBest answer
Super User
Jan 21, 2025 9:20 AM UTC

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

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.