Skip to content

rp2/modmachine: Implement lightsleep() with optional sleep period. #8832

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

Merged
merged 1 commit into from
Jun 30, 2022

Conversation

dpgeorge
Copy link
Member

This gets basic machine.lightsleep([n]) working on the rp2 port.

It supports:

  • Calling lightsleep without a specified period, in which case it uses xosc dormant mode. There's currently no way to wake it up from this state, unless you write to raw registers to enable a GPIO wake up source.
  • Calling lightsleep with a period n in milliseconds. This period must be less than about 72 minutes and uses timer alarm3 to wake it up.

The RTC continues to run during lightsleep, but other peripherals have their clock turned off during the sleep.

It doesn't yet support:

  • Longer periods than 72 minutes (could use the RTC for this).
  • Wake up from GPIO IRQ.

Fixes issue #8770.

@peterhinch
Copy link
Contributor

This works well, and it keeps the ticks_ms timer going which supports my tests of low power uasyncio applications #8771. I haven't yet done a proper power measurement but my cheap USB meter suggests about 1mA on the Pico.

@dpgeorge
Copy link
Member Author

Thanks for testing, that is very helpful.

I measured about 1.55mA when doing machine.lightsleep(5000), and about 0.9mA when doing machine.lightsleep() (which uses the dormant mode). This is on a PICO board. I'm not sure what the RP2040 itself can get down to, but I suspect a lot of that 0.9mA is consumed by the board itself, not the MCU.

@peterhinch
Copy link
Contributor

I've now done a proper measurement with machine.lightsleep(5000). My Pico sample draws 990μA supplying 5V on Vsys and nothing connected to USB. Some unit to unit variation is to be expected.

@dpgeorge dpgeorge force-pushed the rp2-machine-lightsleep branch from d0177fb to 3aa69fb Compare June 30, 2022 01:24
This gets basic machine.lightsleep([n]) behaviour working on the rp2 port.
It supports:

- Calling lightsleep without a specified period, in which case it uses xosc
  dormant mode.  There's currently no way to wake it up from this state,
  unless you write to raw registers to enable a GPIO wake up source.

- Calling lightsleep with a period n in milliseconds.  This period must be
  less than about 72 minutes and uses timer alarm3 to wake it up.

The RTC continues to run during lightsleep, but other peripherals have
their clock turned off during the sleep.

It doesn't yet support longer periods than 72 minutes, or waking up from
GPIO IRQ.

Measured current consumption from the USB port on a PICO board is about
1.5mA when doing machine.lightsleep(5000), and about 0.9mA when doing
machine.lightsleep().

Addresses issue micropython#8770.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge force-pushed the rp2-machine-lightsleep branch from 3aa69fb to b004e7e Compare June 30, 2022 01:40
@dpgeorge dpgeorge merged commit b004e7e into micropython:master Jun 30, 2022
@dpgeorge dpgeorge deleted the rp2-machine-lightsleep branch June 30, 2022 01:46
@guillochon
Copy link

guillochon commented Aug 1, 2022

I've given this a try in a program and the Pico never wakes up after the sleep 😞 (the program behaves normally with a time.sleep but...that's not low power).

I was using the nightly build for the Pico W, this one in particular: https://micropython.org/resources/firmware/rp2-pico-w-20220729-unstable-v1.19.1-223-g963e599ec.uf2

Does lightsleep support the W?

@mikerr
Copy link

mikerr commented Aug 1, 2022

Tried with the same build as above on Pico W

Unfortuneately any value other than 1 never returns

machine.lightsleep(1) works but way too quick

machine.lightsleep() halts using < 1mA

@henley-regatta
Copy link

Tried with build [v1.19.1-428-gb41aaaa8a (2022-09-19) .uf2 on a Pico W and having the same issue @guillochon and @mikerr report - machine.lightsleep(6000) never returns.

@jimmo
Copy link
Member

jimmo commented Oct 1, 2022

See #9438 for a fix for the lightsleep-on-pico-w issues reported here.

@CrabbyPete
Copy link

I am having a problem with reading a UART after it comes out of lightsleep. Is there something I need to do to make it work?

@robert-hh
Copy link
Contributor

robert-hh commented Mar 12, 2023

Which board, firmware version and UART configuration do you use?
And which kind of problem do you have. No data, wrong data, loss of data?

@CrabbyPete
Copy link

I figured out whats happening. The other device was writing before it came out of lightsleep mode. If I read the uart with an interrupt will that kick it out of lightsleep mode?

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

Successfully merging this pull request may close these issues.

8 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy