alarm.sleep_memory out of range

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
blakebr
 
Posts: 956
Joined: Tue Apr 17, 2012 6:23 pm

alarm.sleep_memory out of range

Post by blakebr »

Good morning,

I copied this code from the web site (https://learn.adafruit.com/deep-sleep-w ... eep-memory):

Code: Select all

import time
import alarm
import board
import supervisor
import microcontroller

Code: Select all

8  if not alarm.wake_alarm:
9  # Use byte 5 in sleep memory. This is just an example.
10     alarm.sleep_memory[5] = 0
11 alarm.sleep_memory[5] = (alarm.sleep_memory[5] + 1) % 256
12 print(alarm.sleep_memory[5])
13 while True: pass
I get the following error when run:

Code: Select all

Traceback (most recent call last):
  File "code.py", line 10, in <module>
IndexError: index out of range
What am I doing wrong?

Bruce
Adafruit CircuitPython 8.0.5 on 2023-03-31; Raspberry Pi Pico W with rp2040
Board ID:raspberry_pi_pico_w
UID:E6614103E719A637
MAC:28:CD:C1:00:6B:08
boot.py output:
Write to SD Card: True
Write to Flash : False
boot.py Finis

User avatar
danhalbert
 
Posts: 4649
Joined: Tue Aug 08, 2017 12:37 pm

Re: alarm.sleep_memory out of range

Post by danhalbert »

The RPI Pico and Pico W boards don't have sleep memory implemented yet, sorry.

User avatar
dastels
 
Posts: 15653
Joined: Tue Oct 20, 2015 3:22 pm

Re: alarm.sleep_memory out of range

Post by dastels »

That example was written for the ESP32-S2, not the RP2040 which accounts for the difference.

From shared-bindings/alarm/SleepMemory.c:

Code: Select all

//| class SleepMemory:
//|     """Store raw bytes in RAM that persists during deep sleep.
//|     The class acts as a ``bytearray``.
//|     If power is lost, the memory contents are lost.
//|
//|     Note that this class can't be imported and used directly. The sole
//|     instance of :class:`SleepMemory` is available at
//|     :attr:`alarm.sleep_memory`.
//|
//|     **Limitations:** Not supported on RP2040.
So you won't be able to use sleepmemory.

Dave

User avatar
blakebr
 
Posts: 956
Joined: Tue Apr 17, 2012 6:23 pm

Re: alarm.sleep_memory out of range

Post by blakebr »

Dan, Dave,

Thanks for the replies.

Dan, "yet" gives me hope.

Bruce

User avatar
danhalbert
 
Posts: 4649
Joined: Tue Aug 08, 2017 12:37 pm

Re: alarm.sleep_memory out of range

Post by danhalbert »

I am going to see if it's easy to do. How much sleep memory do you need?

User avatar
blakebr
 
Posts: 956
Joined: Tue Apr 17, 2012 6:23 pm

Re: alarm.sleep_memory out of range

Post by blakebr »

Dan,

At first blush, I would say the same as NVM, 0x1000 bytes. Any more than that would be best implemented with external FRAM or EEPROM. I would expect sleep_memory will have a life span, but better than NVM. If not so, there is not much point in sleep_menory, the user may as well go for FRAM at the start.

Bruce

FYI, I am testing an FRAM chip and am at 4,200,000 Write/reads so far.

User avatar
danhalbert
 
Posts: 4649
Joined: Tue Aug 08, 2017 12:37 pm

Re: alarm.sleep_memory out of range

Post by danhalbert »

I implemented a 256-byte sleep memory on RP2040. Here are the artifacts if you would like to test:
https://github.com/adafruit/circuitpyth ... 5040174390

On the RP2040, RAM is not powered down during sleep. So this is simply a reserved section of RAM that doesn't get zero'd out on startup.

User avatar
blakebr
 
Posts: 956
Joined: Tue Apr 17, 2012 6:23 pm

Re: alarm.sleep_memory out of range

Post by blakebr »

Dan,

WOW, that was fast. I will try it out as soon as we get home from grocery shopping.
I was never warned about this grocery thing!!!

Bruce

User avatar
blakebr
 
Posts: 956
Joined: Tue Apr 17, 2012 6:23 pm

Re: alarm.sleep_memory out of range

Post by blakebr »

Dan,

You over estimate my abilities. I don't know what to do with artifacts. I assume compile the OS with them. I have not jumped into that puddle yet. Will the feature appear in an upcoming Alpha version?

Bruce

User avatar
danhalbert
 
Posts: 4649
Joined: Tue Aug 08, 2017 12:37 pm

Re: alarm.sleep_memory out of range

Post by danhalbert »

Just download the .zip file for your board and unzip it. Inside is a .UF2 you can test.

User avatar
blakebr
 
Posts: 956
Joined: Tue Apr 17, 2012 6:23 pm

Re: alarm.sleep_memory out of range

Post by blakebr »

Dan,

Thank you, works as described.
Is the reserved 256 bytes going to be a permanent part of the CP 8.1.x build from now on?
Can the reservation of those 256 bytes be turned off to recover those bytes?

Bruce

User avatar
danhalbert
 
Posts: 4649
Joined: Tue Aug 08, 2017 12:37 pm

Re: alarm.sleep_memory out of range

Post by danhalbert »

It will be in all RP2040 builds after 8.1.0. A custom build could be made to turn it off. I made it only 256 bytes to not affect the RAM usage materially.

User avatar
blakebr
 
Posts: 956
Joined: Tue Apr 17, 2012 6:23 pm

Re: alarm.sleep_memory out of range

Post by blakebr »

Dan,

After 8.1.0... Good choice on size.

Bruce

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”