10000 docs/library/machine.RTC.rst: added description of method machine.RTC… · micropython/micropython@937a199 · GitHub
[go: up one dir, main page]

Skip to content

Commit 937a199

Browse files
committed
docs/library/machine.RTC.rst: added description of method machine.RTC.memory.
1 parent fe89561 commit 937a199

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

docs/library/machine.RTC.rst

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ Methods
6767
The data is stored together with a magic word to detect that the RTC memory is valid.
6868
An uninitialized or cleared RTC memory has no magic word and will deliver ``b''``.
6969
Without ``data`` the method delivers the RTC memory content.
70-
In the ESP8266 are max. 492 bytes and in the ESP32 are max. 2048 Bytes storeable by this method.
71-
70+
In the ESP8266 are max. 492 bytes and in the ESP32 are max. 2048 Bytes storeable by this method.
71+
7272
Example::
7373

7474
import machine
@@ -80,9 +80,57 @@ Methods
8080

8181
Availability: ESP8266, ESP32
8282

83+
.. method:: RTC.usermem()
84+
85+
This is similar to the RTC.memory() above, but returns a bytearray object whose data
86+
gets stored directly in the user memory area.
87+
88+
**The bytearray uses the same memory area as ``RTC.memory()``**, so a little care is required when using both methods.
89+
90+
Advantages over ``RTC.memory()``:
91+
92+
- Access to the entire available RTC slow memory user area
93+
- Python access to details of the memory area, e.g. by using ``uctypes.sizeof()``
94+
and ``uctypes.addressof()``
95+
- data loggers and similar applications don't need to copy the entire (up to 3.5k)
96+
memory area
97+
98+
The data is stored together with a magic word to detect that the RTC memory is valid.
99+
An uninitialized or cleared RTC memory has no magic word; the bytearray returned
100+
by ``RTC.usermem()`` will contain binary zeroes.
101+
102+
Example::
103+
104+
from machine import RTC
105+
import uctypes
106+
107+
STRUCT = {
108+
"data1": 0 | uctypes.UINT32,
109+
"data2": 0 | uctypes.UINT32,
110+
}
111+
112+
rtc_mem = RTC().usermem() # get the RTC memory area
113+
data = uctypes.struct(uctypes.addressof(rtc_mem), STRUCT)
114+
print(data.data1) # get data1 out of RTC memory
115+
data.data1 = 4712 # set data1 in RTC memory
116+
117+
Availability: ESP32
118+
83119
Constants
84120
---------
85121

86122
.. data:: RTC.ALARM0
87123

88124
irq trigger source
125+
126+
127+
Compile-time options
128+
--------------------
129+
130+
These can be set e.g. in ``ports/esp32/boards/XXX/mpconfigboard.h``
131+
132+
- ``#define MICROPY_HW_RTC_USER_MEM_MAX 2048``
133+
sets the entire size of the user memory. This can be increased up to ~3500 bytes.
134+
A value of 0 (zero) disables ``RTC.memory()`` as well as ``RTC.usermem()``
135+
136+

0 commit comments

Comments
 (0)
0