Repository navigation
esp32/machine_rtc: Preserve RTC user memory over most reset causes. - #7298
Conversation
|
Obviously RTC memory will survive a power cycle only if the RTC domain is supplied by a battery. And pulling the EN pin causes a power cycle. |
|
@dpgeorge: This is now almost a year old. |
|
This change crashes the microcontroller for me when |
You are right. Obviously this is a bug coming to light when the user memory is not initialized. |
8439a9f to
1598de5
Compare
|
This is fixed by now. import machine
import time
from machine import RTC
from machine import WDT
text = {
machine.DEEPSLEEP_RESET: "DEEP_SLEEP_RESET",
machine.PWRON_RESET: "PWRON_RESET",
machine.HARD_RESET: "HARD_RESET",
machine.WDT_RESET: "WDT_RESET",
machine.SOFT_RESET: "SOFT_RESET"
}
print("Reset cause: {}".format(text.get(machine.reset_cause(), "???")) )
if machine.reset_cause() == machine.PWRON_RESET:
RTC().memory('Hello, World')
print("set RTC.memory(): {}".format(RTC().memory()) )
machine.reset()
if machine.reset_cause() == machine.HARD_RESET:
print("RTC.memory(): {}".format(RTC().memory()) )
wdt = WDT(timeout=1000) # enable it with a timeout of 1s
if machine.reset_cause() == machine.WDT_RESET:
print("RTC.memory(): {}".format(RTC().memory()) )gives me the output (edited for clarity) |
…n-main Translations update from Hosted Weblate
|
Sorry that this didn't get any attention for so long. It looks good! But how about just enabling this new behaviour by default? Ie no need for the new config option |
As far as I remember was the idea to allow the (compiling) user to enable this feature when required, so all applications relying on an empty RTC.memory() regardless of the reset cause will work like before. However, in the next 2-3 daysI I could add a |
2d47cab to
5cf1eeb
Compare
|
Now we have a new (optional) |
The user memory area - accessible by machine.RTC.memory() -- will now survive most reboot causes. A power-on reset (also caused by the EN pin on some boards) will clean the memory. When this happens, the magic number not found in the user memory will cause initialization. After other resets (triggered by watchdogs, machine.reset(), ...), the user is responsible to check and validate the contents of the user area. This new behaviour can be changed by enabling MICROPY_HW_RTC_MEM_INIT_ALWAYS: in that case the RTC memory is always cleared on boot. Signed-off-by: Thomas Wenrich <[email protected]>
5cf1eeb to
78b3fe5
Compare
|
Thanks for updating. I tested this and it works well. Merged. |
ESP32: New compile-time #define allowing to preserve the RTC slow memory during most resets.
Usage:
e.g. in port/esp32/board/XXX/mpconfigboard.h
When above is defined, the user memory area - accessible by
machine.RTC.memory()will survive most reboot causes. A power-on reset (also caused by the EN pin on some boards) will clean the memory. When this happens, the magic number not found in the user memory will cause initialization.After other resets (triggered by watchdogs,
machine.reset(), ...), the user is responsible to check and validate the contents of the user area.