From 76d8416a41e16ad8cf577c7d6744d08cc83cd679 Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Thu, 12 Jan 2023 20:21:34 +0100 Subject: [PATCH] Added eeprom emulation to store reset info --- firmware/config.h | 2 +- firmware/datastore.ino | 20 ++++++++++++++++++++ firmware/firmware.ino | 25 +++++++++++++++++++++++-- 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 firmware/datastore.ino diff --git a/firmware/config.h b/firmware/config.h index 1899885..f02b78e 100644 --- a/firmware/config.h +++ b/firmware/config.h @@ -46,6 +46,6 @@ #define SERIAL_BAUD_RATE 115200 -#define WEB_UPDATER_HTTP_PORT 8080 +#define WEB_UPDATER_HTTP_PORT 8080 #endif diff --git a/firmware/datastore.ino b/firmware/datastore.ino new file mode 100644 index 0000000..f6e9320 --- /dev/null +++ b/firmware/datastore.ino @@ -0,0 +1,20 @@ + +#include + +#define EEPROM_SIZE 512 + +int eeprom_read(int addr) { + int ret = -255; + EEPROM.begin(EEPROM_SIZE); + EEPROM.get(addr, ret); + EEPROM.commit(); + EEPROM.end(); + return ret; +} + +void eeprom_write(int addr, int data) { + EEPROM.begin(EEPROM_SIZE); + EEPROM.put(addr, data); + EEPROM.commit(); + EEPROM.end(); +} diff --git a/firmware/firmware.ino b/firmware/firmware.ino index e412213..d99ac1d 100644 --- a/firmware/firmware.ino +++ b/firmware/firmware.ino @@ -4,7 +4,7 @@ #include #include - +#include #include // WiFiClient // Project includes @@ -84,10 +84,14 @@ void setup() { //wdt_disable(); #endif -#if defined(DEBUG) || defined(SERIAL_FEATURE) +#if defined(DEBUG) || defined(SERIAL_FEATURE) || defined(DEBUG_RESET_REASON) Serial.begin(SERIAL_BAUD_RATE); #endif +#ifdef DEBUG_RESET_REASON + debugResetReason(); +#endif + // Pin settings pinMode(BAT_CHARGED_PIN, INPUT); pinMode(BAT_CHARGING_PIN, INPUT); @@ -783,3 +787,20 @@ void http_call_send_json_data() } #endif + +#ifdef DEBUG_RESET_REASON +void debugResetReason() { + + rst_info *resetInfo; + + // 1. read eeprom reset reason + //int eep_reset_reason = eeprom_read(0); + //debug("EEPROM reset reason " + String(eep_reset_reason)); + + // 2. read real reset reason + int reset_reason = resetInfo->reason; + + debug("New reset reason " + String(reset_reason)); + //eeprom_write(0, reset_reason); +} +#endif