2025-01-21 12:42 AM - last edited on 2025-01-21 01:31 AM by Andrew Neil
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?
2025-01-21 12:48 AM
Set flags in your interrupt handlers which indicate which one occurred.
What STM32L4, exactly, are you using?
2025-01-21 01:12 AM
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.
2025-01-21 01:20 AM
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
2025-01-21 01:27 AM
Thanks a lot for the explanation, I will test it, will come back later