RTC memory to solve reboot issues
Posted: Sat Aug 01, 2015 1:39 pm
I don't know if this topic belongs here but since it was my last resort for dealing with reboots - well, here it is.
I have a nice sketch for a kitchen timer with web access so I can monitor and control it from my mobile. All is nice and dandy but it just reboots now and then. It can run for 8 hours straight and then get a WDT reset.. or run for 10 seconds and reboot. Now.. a kitchen timer should never loose count! or I will get overcooked pasta. I didn't find any apparent cause (power supply is OK.. code appears smooth) so I decided I need persistence between reboots. The standard RAM is cleared following reset so it's a no-go. But lo and behold! the ESP has an RTC RAM. This RAM, accessible via the "system_rtc_mem_read" and "system_rtc_mem_write" API calls can hold enough data to memorize the state of the system. Note that actual modifiable RAM starts at an offset of 28 bytes from the base address. I put a signature in the RAM, my main states and variables, and a checksum. When the "setup" code runs, it checks for the signature and a valid checksum and then modifies the boot values accordingly. My main loop just updates the RTC RAM on a regular basis so that any crash of the ESP can be survived.
These are my 2 cents for today.
I have a nice sketch for a kitchen timer with web access so I can monitor and control it from my mobile. All is nice and dandy but it just reboots now and then. It can run for 8 hours straight and then get a WDT reset.. or run for 10 seconds and reboot. Now.. a kitchen timer should never loose count! or I will get overcooked pasta. I didn't find any apparent cause (power supply is OK.. code appears smooth) so I decided I need persistence between reboots. The standard RAM is cleared following reset so it's a no-go. But lo and behold! the ESP has an RTC RAM. This RAM, accessible via the "system_rtc_mem_read" and "system_rtc_mem_write" API calls can hold enough data to memorize the state of the system. Note that actual modifiable RAM starts at an offset of 28 bytes from the base address. I put a signature in the RAM, my main states and variables, and a checksum. When the "setup" code runs, it checks for the signature and a valid checksum and then modifies the boot values accordingly. My main loop just updates the RTC RAM on a regular basis so that any crash of the ESP can be survived.
These are my 2 cents for today.