diff --git a/lib_standalone/Arduino.h b/lib_standalone/Arduino.h index 1ac2aea3b..d13411c24 100644 --- a/lib_standalone/Arduino.h +++ b/lib_standalone/Arduino.h @@ -76,6 +76,10 @@ void ledcWrite(uint8_t chan, uint32_t duty); void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val); void rgbLedWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val); +inline int rtc_get_reset_reason(int cpu_no) { + return 0; +} + #define PROGMEM #define PGM_P const char * diff --git a/src/core/emsesp.cpp b/src/core/emsesp.cpp index f74c9d32e..faa88331d 100644 --- a/src/core/emsesp.cpp +++ b/src/core/emsesp.cpp @@ -20,6 +20,7 @@ #ifndef EMSESP_STANDALONE #include "esp_ota_ops.h" +#include "rom/rtc.h" #endif static_assert(uuid::thread_safe, "uuid-common must be thread-safe"); @@ -1721,15 +1722,31 @@ void EMSESP::start() { LOG_INFO("EMS-ESP version %s", EMSESP_APP_VERSION); #endif + LOG_DEBUG("System is running in Debug mode"); + // check if the firmware is fresh, i.e. a new install or a new version has been uploaded // this is set in UploadFileService::uploadComplete() // and reset in System::set_partition_install_date() - if (!EMSESP::nvs_.getBool(EMSESP_NVS_BOOT_NEW_FIRMWARE)) { - LOG_DEBUG("Firmware is fresh install"); + if (EMSESP::nvs_.getBool(EMSESP_NVS_BOOT_NEW_FIRMWARE)) { + LOG_DEBUG("Firmware is a new install"); + } else { +// check if the firmware has been uploaded via Serial/USB +#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) + if (rtc_get_reset_reason(0) == 11) { // ESP_RST_USB (Reset by USB peripheral, on CPU 0 only +#else + if ((rtc_get_reset_reason(0) == 14 || rtc_get_reset_reason(1) == 14)) { // APP CPU reset by PRO CPU, can be either CPUs +#endif + LOG_DEBUG("Firmware is a new install, uploaded via Serial/USB"); + EMSESP::nvs_.putBool(emsesp::EMSESP_NVS_BOOT_NEW_FIRMWARE, true); // set flag so it's picked up later to set the install date + } } - LOG_DEBUG("System is running in Debug mode"); +// S2 are C3 are both single core +#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) + LOG_INFO("Last system reset reason Core0: %s", system_.reset_reason(0).c_str()); +#else LOG_INFO("Last system reset reason Core0: %s, Core1: %s", system_.reset_reason(0).c_str(), system_.reset_reason(1).c_str()); +#endif // see if we're restoring a settings file #ifndef EMSESP_STANDALONE