Skip to content

Third sleep option: RAM-preserving "deep" sleep #9521

Open
@Sola85

Description

@Sola85

CircuitPython currently supports two sleep modes: Light sleep and deep sleep. Given the specification of the two existing sleep modes, and the capabilities of many microcontrollers supported by CP, I think there is room for one more sleep mode, which would have a clear benefit. Here is my rationale:

  • Light sleep promises to keep background tasks such as WIFI, BLE, audio playback, etc alive. These promises make it hard to actually save any power with light sleep. This is even stated in the CP documentation.
  • Deep sleep is the lowest power mode of a given microcontroller that still allows timer and pin interrupts. Since some microcontroller reset after waking from deep sleep (I think esp's are the main culprit here), this behaviour is forced onto all ports (and rightly so, for consistency).

But (as far as i can tell) all non-esp microcontrollers that are supported by CP and have the alarm module implemented, have options to preserve RAM contents during deep sleep at the cost of at most a few microamps. Some ports even preserve RAM contents during deep sleep today, but add an artificial reset upon wake. Below is an attempt to summarize the current state of CP regarding this topic.

The benefit would be instant wake, since python code would not have to be re-interpreted after wake. IMO, slow start and wake times are one of the most annoying drawbacks of micropython/circuitpython, and this could be solved by the proposed change.

There are a few options for how the API could look, e.g.:

  • alarm.deep_sleep_until_alarms() (in contrast to alarm.exit_and_deep_sleep_until_alarms()).
  • alarm.exit_and_deep_sleep_until_alarms(skip_reset=True)
  • ...

Current state of CP and proposed behaviour in the new sleep mode (for all ports that currently implement the alarm module):

Port Current deep sleep behaviour Proposed behaviour in new sleep mode Estimated increase in sleep current over deep-sleep (according to datasheet)
nordic artificial reset after wake same as current deep sleep, but skip artificial reset 0
stm HAL_PWR_EnterSTANDYMode() HAL_PWR_EnterSTOPMode() 2-5µA -> 9-100 µA (depending on exact config)
raspberrypi* artificial reset after wake same as current deep sleep, but skip artificial reset 0
atmel-samd PM_SLEEPCFG_SLEEPMODE_BACKUP PM_SLEEPCFG_SLEEPMODE_STANDBY 2-10µA -> 22-50µA (depending on exact config)
espressif esp_deep_sleep_start() esp_light_sleep_start() or NotImplementedError

If there is interest in such a feature, I would be willling to implement it (at least for nordic, raspi and esp, as those are the ones I'm personally interested in).

*Note: I think the new RP2350 series also has low power ram retaining sleep, and could therefore also benefit from this feature.

Similar Issue: #8771

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions