From 0aaeab07dbb715c27a201dc6760bd12e76f69d0f Mon Sep 17 00:00:00 2001 From: Mark Wilhelm Date: Fri, 6 Nov 2026 13:09:01 -0500 Subject: [PATCH] fix: suspend SysTick in LowPower_stop() Like LowPower_sleep(), suspend the tick before entering Stop mode. With DBGMCU DBG_STOP set, the core clock and SysTick keep running in Stop mode and the pending tick interrupt wakes WFI despite PRIMASK, so deepSleep() returned almost immediately. The tick is enabled again on wake-up by SystemClock_ConfigFromStop() (HAL_RCC_ClockConfig() -> HAL_InitTick()), before the existing HAL_Delay(10). Fixes #135 Co-Authored-By: Claude Opus 5.5 --- src/low_power.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/low_power.c b/src/low_power.c index 73c7ca4..0961dea 100644 --- a/src/low_power.c +++ b/src/low_power.c @@ -763,6 +763,16 @@ void LowPower_stop(serial_t *obj) { __disable_irq(); + /* + * Suspend Tick increment to prevent wakeup by Systick interrupt, as in + * LowPower_sleep(). In Stop mode SysTick normally halts with the core clock, + * but with DBGMCU DBG_STOP set (debugging) the clock keeps running and the + * 1 ms tick ends Stop mode immediately (a pending interrupt wakes WFI even + * with PRIMASK set). The tick is enabled again by + * SystemClock_ConfigFromStop() (HAL_RCC_ClockConfig() -> HAL_InitTick()). + */ + HAL_SuspendTick(); + #if defined(UART_WKUP_SUPPORT) if (WakeUpUart != NULL) { HAL_UARTEx_EnableStopMode(WakeUpUart);