Fix RTC related power on sequence

This commit is contained in:
Theo Arends 2021-01-05 11:49:13 +01:00
parent 9d36dbe0c5
commit c7545d93dc
2 changed files with 21 additions and 19 deletions

View File

@ -51,16 +51,17 @@ void RtcSettingsSave(void)
} }
} }
bool RtcSettingsLoad(void) { bool RtcSettingsLoad(uint32_t update) {
bool was_read_valid = true;
#ifdef ESP8266 #ifdef ESP8266
ESP.rtcUserMemoryRead(100, (uint32_t*)&RtcSettings, sizeof(RtcSettings)); // 0x290 ESP.rtcUserMemoryRead(100, (uint32_t*)&RtcSettings, sizeof(RtcSettings)); // 0x290
#endif // ESP8266 #endif // ESP8266
#ifdef ESP32 #ifdef ESP32
RtcSettings = RtcDataSettings; RtcSettings = RtcDataSettings;
#endif // ESP32 #endif // ESP32
if (RtcSettings.valid != RTC_MEM_VALID) {
was_read_valid = false; bool read_valid = (RTC_MEM_VALID == RtcSettings.valid);
if (update) {
if (!read_valid) {
memset(&RtcSettings, 0, sizeof(RtcSettings)); memset(&RtcSettings, 0, sizeof(RtcSettings));
RtcSettings.valid = RTC_MEM_VALID; RtcSettings.valid = RTC_MEM_VALID;
RtcSettings.energy_kWhtoday = Settings.energy_kWhtoday; RtcSettings.energy_kWhtoday = Settings.energy_kWhtoday;
@ -75,7 +76,8 @@ bool RtcSettingsLoad(void) {
RtcSettingsSave(); RtcSettingsSave();
} }
rtc_settings_crc = GetRtcSettingsCrc(); rtc_settings_crc = GetRtcSettingsCrc();
return was_read_valid; }
return read_valid;
} }
bool RtcSettingsValid(void) bool RtcSettingsValid(void)
@ -571,7 +573,7 @@ void SettingsLoad(void) {
settings_crc32 = GetSettingsCrc32(); settings_crc32 = GetSettingsCrc32();
#endif // FIRMWARE_MINIMAL #endif // FIRMWARE_MINIMAL
RtcSettingsLoad(); RtcSettingsLoad(1);
} }
// Used in TLS - returns the timestamp of the last Flash settings write // Used in TLS - returns the timestamp of the last Flash settings write

View File

@ -220,7 +220,7 @@ void setup(void) {
#endif #endif
RtcRebootSave(); RtcRebootSave();
if (RtcSettingsLoad()) { if (RtcSettingsLoad(0)) {
uint32_t baudrate = (RtcSettings.baudrate / 300) * 300; // Make it a valid baudrate uint32_t baudrate = (RtcSettings.baudrate / 300) * 300; // Make it a valid baudrate
if (baudrate) { TasmotaGlobal.baudrate = baudrate; } if (baudrate) { TasmotaGlobal.baudrate = baudrate; }
} }