Commit 752e9520 authored by Damien George's avatar Damien George
Browse files

esp8266/rtc: Set RTC user memory length to 0 on first boot.

So that RTC.memory() returns b'' on power up if it was never set.

Fixes issue #2138.
parent 4f3fbf09
...@@ -64,6 +64,8 @@ void mp_hal_rtc_init(void) { ...@@ -64,6 +64,8 @@ void mp_hal_rtc_init(void) {
int64_t delta = 0; int64_t delta = 0;
system_rtc_mem_write(MEM_CAL_ADDR, &cal, sizeof(cal)); system_rtc_mem_write(MEM_CAL_ADDR, &cal, sizeof(cal));
system_rtc_mem_write(MEM_DELTA_ADDR, &delta, sizeof(delta)); system_rtc_mem_write(MEM_DELTA_ADDR, &delta, sizeof(delta));
uint32_t len = 0;
system_rtc_mem_write(MEM_USER_LEN_ADDR, &len, sizeof(len));
} }
// reset ALARM0 state // reset ALARM0 state
...@@ -145,20 +147,17 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_datetime_obj, 1, 2, pyb_rtc_d ...@@ -145,20 +147,17 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_datetime_obj, 1, 2, pyb_rtc_d
STATIC mp_obj_t pyb_rtc_memory(mp_uint_t n_args, const mp_obj_t *args) { STATIC mp_obj_t pyb_rtc_memory(mp_uint_t n_args, const mp_obj_t *args) {
uint8_t rtcram[MEM_USER_MAXLEN]; uint8_t rtcram[MEM_USER_MAXLEN];
uint32_t len; uint32_t len;
uint32_t magic;
if (n_args == 1) { if (n_args == 1) {
// read RTC memory
system_rtc_mem_read(MEM_USER_MAGIC_ADDR, &magic, sizeof(magic));
if (magic != MEM_MAGIC) {
return mp_const_none;
}
system_rtc_mem_read(MEM_USER_LEN_ADDR, &len, sizeof(len)); system_rtc_mem_read(MEM_USER_LEN_ADDR, &len, sizeof(len));
system_rtc_mem_read(MEM_USER_DATA_ADDR, rtcram, len + (4 - len % 4)); system_rtc_mem_read(MEM_USER_DATA_ADDR, rtcram, len + (4 - len % 4));
return mp_obj_new_bytes(rtcram, len); return mp_obj_new_bytes(rtcram, len);
} else { } else {
// write RTC memory
mp_buffer_info_t bufinfo; mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ); mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ);
...@@ -167,8 +166,6 @@ STATIC mp_obj_t pyb_rtc_memory(mp_uint_t n_args, const mp_obj_t *args) { ...@@ -167,8 +166,6 @@ STATIC mp_obj_t pyb_rtc_memory(mp_uint_t n_args, const mp_obj_t *args) {
"buffer too long")); "buffer too long"));
} }
magic = MEM_MAGIC;
system_rtc_mem_write(MEM_USER_MAGIC_ADDR, &magic, sizeof(magic));
len = bufinfo.len; len = bufinfo.len;
system_rtc_mem_write(MEM_USER_LEN_ADDR, &len, sizeof(len)); system_rtc_mem_write(MEM_USER_LEN_ADDR, &len, sizeof(len));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment