rp2: Keep machine.RTC ticking while in lightsleep(). - #19694
projectgus wants to merge 1 commit into
Conversation
39e6f4d to
50bed79
Compare
|
Code size report: |
|
Thanks for working on this! It's a nice and simple fix, easy to understand. I tested with RPI_PICO2. In RISCV mode I find that the test passes on master, and with this PR. So that CPU is doing something differently... On RPI_PICO2 in ARM mode, indeed the test added here fails on master, and passes with this PR. |
Octoprobe PR report
Failures |
Regression since v1.23 (exact commit unknown). Adds a unit test that fails without this fix, and succeeds with it. (Test is added in extmod_hardware but currently doesn't pass on any other ports that I have access to...) This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
50bed79 to
ea6844a
Compare
Ah, thanks. I always forget about the RISCV mode, that's interesting. |
dpgeorge
left a comment
There was a problem hiding this comment.
Looks good.
Would be nice to eventually get the new test running on other ports, but I suspect that's quite difficult especially for those with native USB.
I think one big reason for the current behaviour (returning on interrupt) was so something like Also, |
Good point. I guess one possibility would be to set a timer and call |
|
Possibly related to this is that always-on timer continues to tick in some circumstances, but it unconditionally reset upon boot. See: Lines 141 to 145 in 52b5fbc I have a downstream change that guards this with |

Summary
Closes #16519. This is a regression since v1.23 (exact commit unknown) - the RTC is frozen during lightsleep.
This work was funded through GitHub Sponsors.
Testing
extmod_hardware/machine_rtc_sleep.pyis added in this PR that fails on RPI_PICO_W and RPI_PICO2_W without this fix, and passes with this fix.New test & other ports
I've added the test under
extmod_hardwarebecause in theory the behaviour ofmachine.RTCandmachine.lightsleepare hardware agnostic.In my quick testing, none of the other boards I tested could pass it:
machine.lightsleep()raisesNotImplementedError. The method should probably be removed.To avoid adding a known broken test on other ports I've added a check that currently skips unless the port is rp2, but there's a comment encouraging other ports to be added if/when they work.
Trade-offs and Alternatives
machine.lightsleep()behaviour - in "non-exclusive" mode the low_power APIs will wake to process interrupts but continue to go back to sleep until the timeout expires. By comparison,machine.lightsleep()is documented to return immediately after the next interrupt arrives. Arguably the pico-sdk low_power behaviour is more useful and more likely to be what someone expects, but I think it'd have to be something we change in MicroPython 2.0.Generative AI
I did not use generative AI tools when creating this PR.