@@ -81,8 +81,8 @@ Methods
81
81
The data is stored together with a magic word to detect that the RTC memory is valid.
82
82
An uninitialized or cleared RTC memory has no magic word and will deliver ``b'' ``.
83
83
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
+
86
86
Example::
87
87
88
88
import machine
@@ -94,9 +94,63 @@ Methods
94
94
95
95
Availability: ESP8266, ESP32
96
96
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
+
97
137
Constants
98
138
---------
99
139
100
140
.. data :: RTC.ALARM0
101
141
102
142
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