Skip to content

Commit 4b43860

Browse files
committed
Add offset parameter to rtcUserMemoryRead/Write, expose RTC_USER_MEM in esp8266_peri.h
1 parent 9e60d4d commit 4b43860

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

cores/esp8266/Esp.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,21 @@ void EspClass::deepSleep(uint32_t time_us, WakeMode mode)
112112
esp_yield();
113113
}
114114

115-
bool EspClass::rtcUserMemoryRead(uint32_t *data, size_t size)
115+
bool EspClass::rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size)
116116
{
117-
if (size > 512) {
117+
if (size + offset > 512) {
118118
return false;
119119
} else {
120-
return system_rtc_mem_read(64, data, size);
120+
return system_rtc_mem_read(64 + offset, data, size);
121121
}
122122
}
123123

124-
bool EspClass::rtcUserMemoryWrite(uint32_t *data, size_t size)
124+
bool EspClass::rtcUserMemoryWrite(uint32_t offset, uint32_t *data, size_t size)
125125
{
126-
if (size > 512) {
126+
if (size + offset > 512) {
127127
return false;
128128
} else {
129-
return system_rtc_mem_write(64, data, size);
129+
return system_rtc_mem_write(64 + offset, data, size);
130130
}
131131
}
132132

cores/esp8266/Esp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ class EspClass {
9494

9595
void deepSleep(uint32_t time_us, RFMode mode = RF_DEFAULT);
9696

97-
bool rtcUserMemoryRead(uint32_t *data, size_t size);
98-
bool rtcUserMemoryWrite(uint32_t *data, size_t size);
97+
bool rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size);
98+
bool rtcUserMemoryWrite(uint32_t offset, uint32_t *data, size_t size);
9999

100100
void reset();
101101
void restart();

cores/esp8266/esp8266_peri.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ extern uint8_t esp8266_gpioToFn[16];
169169
#define RTCIC ESP8266_REG(0x724) //RTC INT Clear
170170
#define RTCIE ESP8266_REG(0x728) //RTC INT Enable
171171

172+
#define RTC_USER_MEM ((volatile uint32_t*)0x60001200)
173+
172174
//IO SWAP Register
173175
#define IOSWAP ESP8266_DREG(0x28)
174176
#define IOSWAPU 0 //Swaps UART

doc/libraries.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ APIs related to deep sleep and watchdog timer are available in the `ESP` object,
8383

8484
`ESP.deepSleep(microseconds, mode)` will put the chip into deep sleep. `mode` is one of `WAKE_RF_DEFAULT`, `WAKE_RFCAL`, `WAKE_NO_RFCAL`, `WAKE_RF_DISABLED`. (GPIO16 needs to be tied to RST to wake from deepSleep.)
8585

86-
`ESP.rtcUserMemoryWrite(&data, sizeof(data))` and `ESP.rtcUserMemoryRead(&data, sizeof(data))` allow struct data with the maximum size of 512 bytes to be stored and retrieved from the RTC user memory of the chip respectively. The stored data can be retained between deep sleep cycles. However, the data might be lost after power cycling the chip.
86+
`ESP.rtcUserMemoryWrite(offset, &data, sizeof(data))` and `ESP.rtcUserMemoryRead(offset, &data, sizeof(data))` allow data to be stored in and retrieved from the RTC user memory of the chip respectively. Total size of RTC user memory is 512 bytes, so offset + sizeof(data) shouldn't exceed 512. Data should be 4-byte aligned. The stored data can be retained between deep sleep cycles. However, the data might be lost after power cycling the chip.
8787

8888
`ESP.restart()` restarts the CPU.
8989

0 commit comments

Comments
 (0)