2025-02-08 08:44 AM - edited 2025-02-08 08:57 AM
Hi, I want to go to sleep/stop mode with STM32 and wake on interrupt. After last interrupt it should wait for 10sec and go back to sleep. But I see an edge case where interrupt could occur just before going to sleep/stop mode.
How do I handle interrupt just before going to sleep/stop mode (cancel sleep/stop mode)?
Basically force WAKE from sleep/stop mode even if STM32 is not yet in sleep/stop mode?
#define STAY_WAKE_FOR_TICK 10000
static volatile uint32_t GoToSleepAfterTick;
void main(void)
{
//...
while (1)
{
HAL_SuspendTick();
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
HAL_ResumeTick();
while (HAL_GetTick() < GoToSleepAfterTick)
{
//...
}
// interupt could occure here???
}
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if (GPIO_Pin == CALL_Pin)
{
GoToSleepAfterTick = HAL_GetTick() + STAY_WAKE_FOR_TICK;
}
}