bootoptions: use NVRAM instead of wearing out flash for crash detection in esp32
This commit is contained in:
parent
ae3abc3aa3
commit
160cbc5ea9
@ -1,9 +1,11 @@
|
|||||||
#include "BootOptions.h"
|
#include "BootOptions.h"
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
|
#include <EEPROM.h>
|
||||||
|
|
||||||
#ifdef BOARD_ESP8266
|
#ifdef BOARD_ESP8266
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#endif
|
#endif
|
||||||
#include <EEPROM.h>
|
|
||||||
#include "Config.h"
|
|
||||||
|
|
||||||
#ifdef PLATFORM_PHOTON
|
#ifdef PLATFORM_PHOTON
|
||||||
LEDStatus serialStatus = LEDStatus(RGB_COLOR_ORANGE, LED_PATTERN_FADE, LED_SPEED_FAST, LED_PRIORITY_BACKGROUND);
|
LEDStatus serialStatus = LEDStatus(RGB_COLOR_ORANGE, LED_PATTERN_FADE, LED_SPEED_FAST, LED_PRIORITY_BACKGROUND);
|
||||||
@ -12,6 +14,10 @@ retained bool LAST_BOOT_WAS_FLASH;
|
|||||||
retained bool LAST_BOOT_WAS_SERIAL;
|
retained bool LAST_BOOT_WAS_SERIAL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef BOARD_ESP32
|
||||||
|
__NOINIT_ATTR uint8_t s_rebootCount = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
BootOptions::initPins()
|
BootOptions::initPins()
|
||||||
{
|
{
|
||||||
@ -36,9 +42,24 @@ BootOptions::BootOptions()
|
|||||||
configStatus.setActive(isSetup);
|
configStatus.setActive(isSetup);
|
||||||
serialStatus.setActive(isSerial);
|
serialStatus.setActive(isSerial);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef BOARD_ESP32
|
||||||
|
resetReason = esp_reset_reason();
|
||||||
|
crashCount = s_rebootCount;
|
||||||
|
if (resetReason >= 4) { // TODO: These values are defined in
|
||||||
|
// esp32/rom/rtc.h, but not sure if that's included
|
||||||
|
// on platformio builds
|
||||||
|
if (crashCount++ >= 3) {
|
||||||
|
// Boot into safe mode if the watchdog reset us three times in a row.
|
||||||
|
isSafeMode = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
crashCount = 0;
|
||||||
|
}
|
||||||
|
s_rebootCount = crashCount;
|
||||||
|
#endif
|
||||||
#ifdef BOARD_ESP8266
|
#ifdef BOARD_ESP8266
|
||||||
struct rst_info resetInfo = *ESP.getResetInfoPtr();
|
struct rst_info resetInfo = *ESP.getResetInfoPtr();
|
||||||
uint8_t crashCount;
|
resetReason = resetInfo.reason;
|
||||||
EEPROM.begin(sizeof(crashCount));
|
EEPROM.begin(sizeof(crashCount));
|
||||||
EEPROM.get(sizeof(HardwareConfig) + 32, crashCount);
|
EEPROM.get(sizeof(HardwareConfig) + 32, crashCount);
|
||||||
EEPROM.end();
|
EEPROM.end();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
struct BootOptions {
|
struct BootOptions {
|
||||||
static void initPins();
|
static void initPins();
|
||||||
@ -12,4 +13,6 @@ struct BootOptions {
|
|||||||
bool isFlash = false;
|
bool isFlash = false;
|
||||||
bool lastBootWasFlash = false;
|
bool lastBootWasFlash = false;
|
||||||
bool isSafeMode = false;
|
bool isSafeMode = false;
|
||||||
|
uint8_t crashCount = 0;
|
||||||
|
uint8_t resetReason = 0;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user