From ee924b8b305e1c0355c3615145531e9155784347 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sun, 19 May 2024 17:15:49 +0700 Subject: [PATCH] implemented entering recovery mode recovery mode itself does not work yet --- ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaProOS.cpp | 5 ++++- ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaProOS.hpp | 6 ++++++ .../lib/ESPMegaPRO/ESPMegaRecovery.cpp | 13 +++++++++++++ .../lib/ESPMegaPRO/ESPMegaRecovery.hpp | 1 + 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaProOS.cpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaProOS.cpp index 47d85b5..5db70e5 100644 --- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaProOS.cpp +++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaProOS.cpp @@ -73,7 +73,9 @@ bool ESPMegaPRO::begin() esp_restart(); } } - + // Recovery Mode + recovery.bindFRAM(&fram, 600); + recovery.begin(); return true; } @@ -89,6 +91,7 @@ void ESPMegaPRO::loop() { inputs.loop(); outputs.loop(); + recovery.loop(); for (int i = 0; i < 255; i++) { if (cardInstalled[i]) diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaProOS.hpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaProOS.hpp index b20f1ce..4b6bd14 100644 --- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaProOS.hpp +++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaProOS.hpp @@ -15,6 +15,7 @@ #include #include #include +#include // ESPMega Pro R3 Board Address #define FRAM_ADDRESS 0x56 @@ -82,6 +83,11 @@ class ESPMegaPRO { * @note You must call enableWebServer() before using this component. */ ESPMegaWebServer *webServer; + /** + * @brief This component is used to enter recovery mode when the ESPMegaPRO board is in a bootloop. + * @typedef ESPMegaRecovery + */ + ESPMegaRecovery recovery; private: bool iotEnabled = false; bool internalDisplayEnabled = false; diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaRecovery.cpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaRecovery.cpp index 863b194..0c145c4 100644 --- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaRecovery.cpp +++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaRecovery.cpp @@ -15,17 +15,29 @@ void ESPMegaRecovery::begin() { } // Inclement the bootloop counter this->inclementBootloopCounter(); + ESP_LOGV("ESPMegaRecovery", "Bootloop counter: %d", this->getBootloopCounter()); // If the bootloop counter is greater than 5, enter recovery mode if(this->getBootloopCounter() > 5) { + ESP_LOGW("ESPMegaRecovery", "Entering recovery mode"); this->enterRecoveryMode(); + // Reset the bootloop counter to prevent re-entering recovery mode + // The device might unintentionally restart multiple times + // By resetting the counter, the user can press reset once in recovery mode to exit + ESP_LOGD("ESPMegaRecovery", "Resetting bootloop counter"); + this->resetBootloopCounter(); } } void ESPMegaRecovery::loop() { // If the device is in recovery mode, block all other tasks if(this->isRecoveryMode()) { + int i = 0; while(true) { + if (i%10 == 0) + ESP_LOGV("ESPMegaRecovery", "System is in recovery mode, no tasks will be executed"); + ESP_LOGV("ESPMegaRecovery", "Please upload a new firmware to exit recovery mode"); // This code will become the new loop delay(1000); + i++; } } // Watchdog timer @@ -33,6 +45,7 @@ void ESPMegaRecovery::loop() { static uint32_t boot_time = millis(); if(!booted) { if(millis() - boot_time > RECOVERY_WATCHDOG_TIMEOUT * 1000) { + ESP_LOGI("ESPMegaRecovery", "System booted successfully, resetting bootloop counter"); this->resetBootloopCounter(); booted = true; } diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaRecovery.hpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaRecovery.hpp index 16415cf..1687017 100644 --- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaRecovery.hpp +++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaRecovery.hpp @@ -1,5 +1,6 @@ #include #include +#include /** * @brief Recovery mode for ESPMega * Recovery mode is a mode that is entered when the device is in a bootloop