@@ -67,8 +67,8 @@ Methods
67
67
The data is stored together with a magic word to detect that the RTC memory is valid.
68
68
An uninitialized or cleared RTC memory has no magic word and will deliver ``b'' ``.
69
69
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
+
72
72
Example::
73
73
74
74
import machine
@@ -80,9 +80,57 @@ Methods
80
80
81
81
Availability: ESP8266, ESP32
82
82
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
+
83
119
Constants
84
120
---------
85
121
86
122
.. data :: RTC.ALARM0
87
123
88
124
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