Skip to content

fix: suspend SysTick in LowPower_stop() - #137

Merged
fpistm merged 1 commit into
stm32duino:mainfrom
M4rkWilhelm:fix-stop-suspend-systick
Nov 9, 2026
Merged

fpistm merged 1 commit into
stm32duino:mainfrom
M4rkWilhelm:fix-stop-suspend-systick

Conversation

@M4rkWilhelm

Copy link
Copy Markdown
Contributor

Summary

Suspend the SysTick interrupt in LowPower_stop(), as LowPower_sleep() already does.

This PR fixes/implements the following bugs/features

Motivation

With DBG_STOP set, the core clock keeps running in Stop mode (on STM32L0 per RM0367, DBGMCU_CR), so SysTick keeps counting and its pending interrupt ends WFI even with PRIMASK set. deepSleep(2000) then returns about 40 times per second. DBG_STOP survives every reset except power-on, so once set by debug code or a debug session, deep sleep stays broken until a power cycle. This isn't specific to STM32F1: any series where DBG_STOP keeps the core clock running in Stop is affected. When DBG_STOP is clear, suspending the tick changes nothing.

No explicit HAL_ResumeTick() is added: on wake-up SystemClock_ConfigFromStop() reconfigures the clocks through HAL_RCC_ClockConfig(), which calls HAL_InitTick() and re-enables the SysTick interrupt before the existing HAL_Delay(10).

The same change was proposed in #102 (closed unmerged by its author) for a related debug case (RTC frozen during debug).

Validation

Tested on an AcSiP S76S (STM32L073RZ, variant ACSIP_S76S) with the repro sketch from #135:

DBG_STOP set DBG_STOP clear
Before deepSleep(2000) returns ~40 times/s sleeps 2 s
After sleeps 2 s (5 LED changes in 10 s, sampled over SWD); no hang after wake-up, so the tick is restored sleeps 2 s

Code formatting

Checked locally with AStyle 3.6.12 and extras/.astylerc: no changes.

Closing issues

Fixes #135

🤖 Generated with Claude Code

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 stm32duino#135

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fpistm

fpistm commented Nov 7, 2026

Copy link
Copy Markdown
Member

Thanks for the PR.

@fpistm fpistm added the fix 🩹 Bug fix label Nov 9, 2026
@fpistm fpistm added this to the 2.0.1/2.1.0 milestone Nov 9, 2026
@github-project-automation github-project-automation Bot moved this to Reviewer approved in STM32duino libraries Nov 9, 2026

@fpistm fpistm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks.

@fpistm
fpistm merged commit 3c38503 into stm32duino:main Nov 9, 2026
2 of 3 checks passed
@github-project-automation github-project-automation Bot moved this from Reviewer approved to Done in STM32duino libraries Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix 🩹 Bug fix

Projects

Development

Successfully merging this pull request may close these issues.

deepSleep() returns immediately when DBGMCU DBG_STOP is set: LowPower_stop() doesn't suspend SysTick

2 participants