← index #15622Issue #17229
Related · high · value 4.207
QUERY · ISSUE

RP2350 / Pico 2 machine.lightsleep not working correctly

openby geerlingguyopened 2024-08-08updated 2025-03-03
bugport-rp2

Port, board and/or hardware

Pico 2 / RP2350

MicroPython version

MicroPython v1.24.0-preview.201.g269a0e0e1 on 2024-08-09; Raspberry Pi Pico2 with RP2350

Reproduction

  1. Install latest Firmware from https://micropython.org/download/RPI_PICO2/
  2. Implement machine.lightsleep(5000) in your code
  3. Run code.

Expected behaviour

Expected Pico 2 to enter lightsleep mode for 5 seconds, then continue to next bit of code.

Observed behaviour

lightsleep is maybe entered for a cycle or so, but code carries on and never stops executing for any time value I enter for lightsleep.

Additional Information

Complete code example:

# Lightsleep MicroPython example.
from machine import Pin
import time
led = Pin(25, Pin.OUT)

while True:
    led.toggle()
    time.sleep_ms(5000)
    led.toggle()
    machine.lightsleep(5000)

Code of Conduct

Yes, I agree

CANDIDATE · ISSUE

RP2350 the watchdog timer does not count down while lightsleep is running

openby cpottle9opened 2025-04-30updated 2025-10-03
bugport-rp2

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

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied