Skip to content

ports/rp2/modmachine.c: Fix lightsleep watchdog interactions. #17232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cpottle9
Copy link
Contributor

@cpottle9 cpottle9 commented May 1, 2025

Summary

Aside: I am a little hesitant to propose these changes. If the maintainers decide to reject this pull request I will understand.
Lightsleep on rp2 is gradually getting more complex and these changes would contribute to that complexity.

Fixes RP2040 issue #17228 and RP2350 issue #17229.

RP2040 issue is when watchdog timer expires while lightsleep is running the RP2040 will lock up during power-on startup.
This occurs because the power-on state machine is configured to not re-initialize the ROSC and lightsleep stopped the ROSC.

RP2350 issue is the watchdog timer does not decrement while lightsleep is running.
Once lightsleep returns the timer will start decrementing again. This occurs because lightsleep clears the bit
CLOCKS_SLEEP_EN1_CLK_SYS_WATCHDOG_BITS while sleeping.

Testing

I ran the reproduction methods from the two issues.
I also ran tests/port/rp2/rp2_lightsleep.py.

Trade-offs and Alternatives

General alternative. Document that lightsleep and watchdog don't play well together and leave the code as is.

Alternatives for RP2040 issue #17228:

  • Raise issue for pico-sdk. Get them to change function _watchdog_enable() so the ROSC and XOSC do get reset on a watchdog timeout. The existing behavior in _watchdog_enable() has been there from day one. There might not be a good reason for it. Disadvantage: a possible long wait for a new pico-sdk release.
  • Modify lightsleep to not stop the ROSC. I measure 4.96 milli-amps when lightsleep disables ROSC and 5.09 milli-amps when it does not. This is a small power increase.

Alternatives for the RP2350 issue #17229:

  • I don't have any :-).

Aside: I am a little hesitant to propose these changes.
If the maintainers decide to reject this pull request
I will understand.
Lightsleep on rp2 is gradually getting more complex
and these changes would contribute to that complexity.

Fixes RP2040 issue micropython#17228 and RP2350 issue micropython#17229.

RP2040 issue is when watchdog timer expires while
lightsleep is running the RP2040 will lock up during
power-on startup.
This occurs because the power-on state machine is configured to
not re-initialize the ROSC and lightsleep stopped the ROSC.

RP2350 issue is the watchdog timer does not decrement while
lightsleep is running.
Once lightsleep returns the timer will start decrementing again.
This occurs because lightsleep clears the bit
CLOCKS_SLEEP_EN1_CLK_SYS_WATCHDOG_BITS while sleeping.

I ran the reproduction tests from the two issues.
I also ran tests/port/rp2/rp2_lightsleep.py.

General alternative. Document that lightsleep and watchdog don't
play well together and leave the code as is.

Alternatives for RP2040 issue micropython#17228:
- Raise issue for pico-sdk.
  Get them to change function _watchdog_enable() so
  the ROSC and XOSC do get reset on a watchdog timeout.
  The existing behavior in _watchdog_enable() has been there
  from day one. There might not be a good reason for it.
  Disadvantage: a possible long wait for a new pico-sdk release.
- Modify lightsleep to not stop the ROSC.
  I measure 4.96 milli-amps when lightsleep disables ROSC and
  5.09 milli-amps when it does not. This is a small change.

Alternatives for the RP2350 issue micropython#17229:
- I don't have any :-).

Signed-off-by: Carl Pottle <cpottle9@outlook.com>
Copy link

github-actions bot commented May 1, 2025

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:   +56 +0.006% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@cpottle9 cpottle9 marked this pull request as ready for review May 1, 2025 02:59
@cpottle9 cpottle9 changed the title port/rp2/modmachine.c: Fix lightsleep watchdog interactions. ports/rp2/modmachine.c: Fix lightsleep watchdog interactions. May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant