earlephilhower / arduino-pico

Raspberry Pi Pico Arduino core, for all RP2040 and RP2350 boards
GNU Lesser General Public License v2.1
2.03k stars 421 forks source link

Feature Request: support deep sleep for the RP2350 #2528

Open sillycowvalley opened 2 weeks ago

sillycowvalley commented 2 weeks ago

I wouldn't know where to start so I asked the One Who Is Wrong With Confidence (ChatGPT) for an example and got some sample code which probably was not worth sharing (so I've deleted the noise I originally posted).

However, I figure we need an open ticket for this feature since this is one of the improvements of the RP2350 over the RP2040.

Would we want to add some RISC-V specific functionality to the RP2040 class for this? The two typical use cases for deep sleep are:

earlephilhower commented 2 weeks ago

I'm pretty sure the code sample you got isn't close to correct, but there are good examples from the RPI folks directly in the pico-examples and the SDK and datasheet docs.

I still haven't found out where my USB power monitor migrated to so don't really have the equipment to do this myself.

If someone wants to give ti a go, I'd be happy to get it in here. The interesting bit will be getting the system and core back into a consistent state after restart. Things like which clocks are on, what the USB state is, which blocks are enabled (ADC, PWM, timer, etc.). Requiring the user to assume the board is equivalent to power on (but with valid RAM) might be fine, but the core internal state will need to be updated to reflect whatever is chosen...

maxgerhardt commented 1 week ago

For the RP2350 there is at least the powman (power manager) API that can switch off certain things. And the CMSIS headers for the ARM Cortex-M33 and the RISC-V Hazard3 probably also have functions to go into a sleep state (wait for interrupt, etc.).

Also related to https://github.com/adafruit/circuitpython/issues/9491 and https://github.com/raspberrypi/pico-playground/pull/48