Content-Length: 269886 | pFad | http://github.com/micropython/micropython/issues/17229

68 RP2350 Watchdog and lightsleep issue · Issue #17229 · micropython/micropython · GitHub
Skip to content

RP2350 Watchdog and lightsleep issue #17229

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
cpottle9 opened this issue Apr 30, 2025 · 4 comments
Open

RP2350 Watchdog and lightsleep issue #17229

cpottle9 opened this issue Apr 30, 2025 · 4 comments
Labels

Comments

@cpottle9
Copy link
Contributor

cpottle9 commented Apr 30, 2025

Port, board and/or hardware

Raspberry Pi Pico2

MicroPython version

MicroPython v1.25.0 on 2025-04-15; Raspberry Pi Pico2 with RP2350

Reproduction

Copy the following into wdt_lightsleep_2350.py.

from machine import lightsleep, WDT
from time import sleep_ms

wdt = WDT(timeout=5000)

lightsleep(3000)

sleep_ms(3000)
print('Should not print')
sleep_ms(3000)

Do 'mpremote run wdt_lightsleep_2350.py'.

Expected behaviour

Expect the same behavior seen when the lightsleep is replaced with sleep_ms.
File wdt_sleep_ms_2350.py

from machine import lightsleep, WDT
from time import sleep_ms

wdt = WDT(timeout=5000)

sleep_ms(3000)

sleep_ms(3000)
print('Should not print')
sleep_ms(3000)
>> mpremote run wdt_sleep_ms_2350.py
Traceback (most recent call last):
  File "/home/picompute/.local/bin/mpremote", line 8, in <module>
    sys.exit(main())

Note: most of traceback removed.
This time the print did not execute because the watchdog timer triggered during the second sleep_ms(3000).

Observed behaviour

The print statement does execute and the watchdog timer triggers during the last sleep_ms(3000).

>> mpremote run wdt_lightsleep_2350.py
Should not print
Traceback (most recent call last):
  File "/home/picompute/.local/bin/mpremote", line 8, in <module>
    sys.exit(main())

Note: most of traceback removed.

Additional Information

I have changes to lightsleep in modmachine.c which fix this problem.
I will prepare a pull request with this fix.

The root cause is the watchdog timer does not count down while lightsleep() is running.

This problem is RP2350 specific and is not seen on RP2040.

Code of Conduct

Yes, I agree

@cpottle9 cpottle9 added the bug label Apr 30, 2025
cpottle9 added a commit to cpottle9/micropython that referenced this issue May 1, 2025
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>
@alke
Copy link

alke commented May 4, 2025

in RP2350 lightsleep is not working it just pass with no sleep

from machine import lightsleep
from time import sleep_ms
led = machine.Pin("LED", machine.Pin.OUT)
while True:
led.on()
lightsleep(3000)

sleep_ms(3000)

led.off()
sleep_ms(3000)

@alke
Copy link

alke commented May 4, 2025

sorry for the hashtag this is the code with no remark
from machine import lightsleep
from time import sleep_ms
led = machine.Pin("LED", machine.Pin.OUT)
while True:
led.on()
lightsleep(3000)
led.off()
sleep_ms(3000)

@cpottle9
Copy link
Contributor Author

cpottle9 commented May 4, 2025

@alke lightsleep works fine on a Pico 2.
The problem you mention is on the Pico 2 W (wireless) only.

I just ran your code on a Pico 2 with micropython 1.25.0 and it worked.

@alke
Copy link

alke commented May 5, 2025

Sorry, yes you are right it is not working on Pico 2 W
:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/micropython/micropython/issues/17229

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy