Skip to content

Commit 616a1bc

Browse files
committed
docs/library/machine.RTC.rst: added description of method machine.RTC.memory.
1 parent ddb0d6f commit 616a1bc

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

docs/library/machine.RTC.rst

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ Methods
8181
The data is stored together with a magic word to detect that the RTC memory is valid.
8282
An uninitialized or cleared RTC memory has no magic word and will deliver ``b''``.
8383
Without ``data`` the method delivers the RTC memory content.
84-
In the ESP8266 are max. 492 bytes and in the ESP32 are max. 2048 Bytes storeable by this method.
85-
84+
In the ESP8266 are max. 492 bytes and in the ESP32 are max. 2048 Bytes storeable by this method.
85+
8686
Example::
8787

8888
import machine
@@ -94,9 +94,63 @@ Methods
9494

9595
Availability: ESP8266, ESP32
9696

97+
.. method:: RTC.usermem()
98+
99+
This is similar to the RTC.memory() above, but returns a bytearray object whose data
100+
gets stored directly in the user memory area.
101+
102+
**The bytearray uses the same memory area as** ``RTC.memory()``, so a little care is required when using both methods.
103+
104+
Advantages over ``RTC.memory()``:
105+
106+
- quick access to the entire available RTC slow memory user area
107+
- Python access to details of the memory area, e.g. by using ``uctypes.sizeof()``
108+
and ``uctypes.addressof()``
109+
- data loggers and similar applications don't need to copy the entire (up to 3.5k)
110+
memory area
111+
112+
The data is stored together with a magic word to detect that the RTC memory is valid.
113+
An uninitialized or cleared RTC memory has no magic word; the bytearray returned
114+
by ``RTC.usermem()`` will contain binary zeroes.
115+
116+
Example::
117+
118+
from machine import RTC
119+
import uctypes
120+
121+
RESERVED = 64 # leave a little space for RTC.memory()
122+
123+
STRUCT = {
124+
"data1": 0 | uctypes.UINT32,
125+
"data2": 0 | uctypes.UINT32,
126+
}
127+
128+
# get the RTC memory area
129+
rtc_mem = RTC().usermem()
130+
131+
data = uctypes.struct(uctypes.addressof(rtc_mem) + RESERVED, STRUCT)
132+
print(data.data1) # get data1 out of RTC memory
133+
data.data1 = 4712 # set data1 in RTC memory
134+
135+
Availability: ESP32
136+
97137
Constants
98138
---------
99139

100140
.. data:: RTC.ALARM0
101141

102142
irq trigger source
143+
144+
145+
Compile-time options
146+
--------------------
147+
148+
These can be set e.g. in ``ports/esp32/boards/XXX/mpconfigboard.h``
149+
150+
``#define MICROPY_HW_RTC_USER_MEM_MAX 2048``
151+
152+
sets the entire size of the user memory. This can be increased up to ~3500 bytes on the ESP32.
153+
154+
A value of 0 (zero) disables ``RTC.memory()`` as well as ``RTC.usermem()``
155+
156+

0 commit comments

Comments
 (0)
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