diff --git a/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.cpp b/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.cpp index 971cb2ec4..bfbf26419 100644 --- a/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.cpp +++ b/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.cpp @@ -65,42 +65,6 @@ uint32_t ESP_getBootVersion(void) return 1; } -// ESP32 RTC memory is kept ONLY on deep_sleep wake. Any other restart will erase RTC memory -// Current solution is using NVS hopig it survives many writes ;-) -bool ESP_rtcUserMemoryWrite(uint32_t offset, uint32_t *data, size_t size) -{ - char sName[16]; - snprintf_P(sName, sizeof(sName), PSTR("rtc%d"), offset); - - nvs_handle handle; - noInterrupts(); - nvs_open("tasrtc", NVS_READWRITE, &handle); - nvs_set_blob(handle, sName, data, size); - nvs_commit(handle); - nvs_close(handle); - interrupts(); - - return true; -} - -// ESP32 RTC memory is kept ONLY on deep_sleep wake. Any other restart will erase RTC memory -// Current solution is using NVS hopig it survives many writes ;-) -bool ESP_rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size) -{ - char sName[16]; - snprintf_P(sName, sizeof(sName), PSTR("rtc%d"), offset); - - nvs_handle handle; - noInterrupts(); - nvs_open("tasrtc", NVS_READONLY, &handle); - size_t tsize = size; - nvs_get_blob(handle, sName, data, &tsize); - nvs_close(handle); - interrupts(); - - return true; -} - void ESP_reset() { ESP.restart(); diff --git a/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.h b/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.h index 276772b95..3af2c12c5 100644 --- a/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.h +++ b/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.h @@ -36,8 +36,6 @@ String ESP_getResetReason(void); uint32_t ESP_ResetInfoReason(void); uint32_t ESP_getBootVersion(void); -bool ESP_rtcUserMemoryWrite(uint32_t offset, uint32_t *data, size_t size); -bool ESP_rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size); void ESP_reset(); uint32_t ESP_getFlashChipId(); uint32_t ESP_getChipId(); diff --git a/tasmota/settings.h b/tasmota/settings.h index e5b1c9f7a..5b862280e 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -551,6 +551,9 @@ typedef struct { uint8_t free_003[1]; // 283 } TRtcReboot; TRtcReboot RtcReboot; +#ifdef ESP32 +RTC_NOINIT_ATTR TRtcReboot RtcDataReboot; +#endif typedef struct { uint16_t valid; // 290 (RTC memory offset 100) @@ -570,6 +573,9 @@ typedef struct { // 2EC - 2FF free locations } TRtcSettings; TRtcSettings RtcSettings; +#ifdef ESP32 +RTC_NOINIT_ATTR TRtcSettings RtcDataSettings; +#endif struct TIME_T { uint8_t second; diff --git a/tasmota/settings.ino b/tasmota/settings.ino index 62fda63d8..cff437d67 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -40,14 +40,22 @@ void RtcSettingsSave(void) { if (GetRtcSettingsCrc() != rtc_settings_crc) { RtcSettings.valid = RTC_MEM_VALID; - ESP_rtcUserMemoryWrite(100, (uint32_t*)&RtcSettings, sizeof(RtcSettings)); +#ifdef ESP8266 + ESP.rtcUserMemoryWrite(100, (uint32_t*)&RtcSettings, sizeof(RtcSettings)); +#else + RtcDataSettings = RtcSettings; +#endif rtc_settings_crc = GetRtcSettingsCrc(); } } void RtcSettingsLoad(void) { - ESP_rtcUserMemoryRead(100, (uint32_t*)&RtcSettings, sizeof(RtcSettings)); // 0x290 +#ifdef ESP8266 + ESP.rtcUserMemoryRead(100, (uint32_t*)&RtcSettings, sizeof(RtcSettings)); // 0x290 +#else + RtcSettings = RtcDataSettings; +#endif if (RtcSettings.valid != RTC_MEM_VALID) { memset(&RtcSettings, 0, sizeof(RtcSettings)); RtcSettings.valid = RTC_MEM_VALID; @@ -87,7 +95,11 @@ void RtcRebootSave(void) { if (GetRtcRebootCrc() != rtc_reboot_crc) { RtcReboot.valid = RTC_MEM_VALID; - ESP_rtcUserMemoryWrite(100 - sizeof(RtcReboot), (uint32_t*)&RtcReboot, sizeof(RtcReboot)); +#ifdef ESP8266 + ESP.rtcUserMemoryWrite(100 - sizeof(RtcReboot), (uint32_t*)&RtcReboot, sizeof(RtcReboot)); +#else + RtcDataReboot = RtcReboot; +#endif rtc_reboot_crc = GetRtcRebootCrc(); } } @@ -100,7 +112,11 @@ void RtcRebootReset(void) void RtcRebootLoad(void) { - ESP_rtcUserMemoryRead(100 - sizeof(RtcReboot), (uint32_t*)&RtcReboot, sizeof(RtcReboot)); // 0x280 +#ifdef ESP8266 + ESP.rtcUserMemoryRead(100 - sizeof(RtcReboot), (uint32_t*)&RtcReboot, sizeof(RtcReboot)); // 0x280 +#else + RtcReboot = RtcDataReboot; +#endif if (RtcReboot.valid != RTC_MEM_VALID) { memset(&RtcReboot, 0, sizeof(RtcReboot)); RtcReboot.valid = RTC_MEM_VALID; diff --git a/tasmota/tasmota_compat.h b/tasmota/tasmota_compat.h index 839f5cef8..7ca5615b1 100644 --- a/tasmota/tasmota_compat.h +++ b/tasmota/tasmota_compat.h @@ -11,8 +11,6 @@ #ifdef ESP8266 // ESP8266 #define PACKED -#define ESP_rtcUserMemoryWrite(offset, data, size) ESP.rtcUserMemoryWrite(offset, data, size) -#define ESP_rtcUserMemoryRead(offset, data, size) ESP.rtcUserMemoryRead(offset, data, size) #define ESP_getResetReason() ESP.getResetReason() #define ESP_reset() ESP.reset() #define ESP_getBootVersion() ESP.getBootVersion()