Skip to content
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

RP2040 SleepMemory #8015

Merged
merged 1 commit into from
May 22, 2023
Merged

RP2040 SleepMemory #8015

merged 1 commit into from
May 22, 2023

Conversation

dhalbert
Copy link
Collaborator

@dhalbert dhalbert commented May 21, 2023

Implements alarm.sleep_memory on RP2040. Implementation taken from nRF. It's just a 256-byte block of RAM, since RP2040 does not power down RAM when sleeping.

Fixes #5081. That issue says other things must be done, including removing a watchdog that zeros out RAM. But I didn't do that and it still works?!

https://forums.adafruit.com/viewtopic.php?p=973288 asked about RP2040 sleep memory, and it seemed easy to implement.

Test program, tested with fake deep sleep and with power just via a 5V adapter:

import alarm
import board
import os
import time

time.sleep(1)

u = board.UART()
u.baudrate = 115200

LEN = 16

print(alarm.wake_alarm)
print("previous bytes:", alarm.sleep_memory[0:LEN])
u.write(b"previous bytes: " + str(alarm.sleep_memory[0:LEN]) + b"\r\n")

time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + 5)
b = os.urandom(LEN)
print("storing", b)
alarm.sleep_memory[0:LEN] = b

u.write(b"storing " + str(b) + b"\r\n")
time.sleep(1)

alarm.exit_and_deep_sleep_until_alarms(time_alarm)

@anecdata
Copy link
Member

alarm.sleep_memory survives supervisor.reload(), and microcontroller.reset() into NORMAL and SAFE_MODE (more extensive persistence than espressif port where alarm.sleep_memory does not survive microcontroller.reset()). Nice, thanks @dhalbert

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@tannewt tannewt merged commit 3f7e6db into adafruit:main May 22, 2023
@dhalbert dhalbert deleted the rp2040-sleep-memory branch May 22, 2023 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add SleepMemory for RP2040
3 participants