Fix initial baudrate

Fix initial baudrate (#7447)
This commit is contained in:
Theo Arends 2020-12-07 15:33:09 +01:00
parent d7ed311587
commit b9a3fd4342
4 changed files with 31 additions and 20 deletions

View File

@ -683,17 +683,18 @@ typedef struct {
uint16_t valid; // 290 (RTC memory offset 100)
uint8_t oswatch_blocked_loop; // 292
uint8_t ota_loader; // 293
unsigned long energy_kWhtoday; // 294
unsigned long energy_kWhtotal; // 298
unsigned long energy_kWhtoday; // 294
unsigned long energy_kWhtotal; // 298
volatile unsigned long pulse_counter[MAX_COUNTERS]; // 29C - See #9521 why volatile
power_t power; // 2AC
EnergyUsage energy_usage; // 2B0
unsigned long nextwakeup; // 2C8
uint8_t free_004[4]; // 2CC
uint32_t baudrate; // 2CC
uint32_t ultradeepsleep; // 2D0
uint16_t deepsleep_slip; // 2D4
uint8_t free_022[22]; // 2D6
uint8_t free_2d6[22]; // 2D6
// 2EC - 2FF free locations
} TRtcSettings;
TRtcSettings RtcSettings;

View File

@ -38,6 +38,7 @@ uint32_t GetRtcSettingsCrc(void)
void RtcSettingsSave(void)
{
RtcSettings.baudrate = Settings.baudrate * 300;
if (GetRtcSettingsCrc() != rtc_settings_crc) {
RtcSettings.valid = RTC_MEM_VALID;
#ifdef ESP8266
@ -50,8 +51,8 @@ void RtcSettingsSave(void)
}
}
void RtcSettingsLoad(void)
{
bool RtcSettingsLoad(void) {
bool was_read_valid = true;
#ifdef ESP8266
ESP.rtcUserMemoryRead(100, (uint32_t*)&RtcSettings, sizeof(RtcSettings)); // 0x290
#endif // ESP8266
@ -59,6 +60,7 @@ void RtcSettingsLoad(void)
RtcSettings = RtcDataSettings;
#endif // ESP32
if (RtcSettings.valid != RTC_MEM_VALID) {
was_read_valid = false;
memset(&RtcSettings, 0, sizeof(RtcSettings));
RtcSettings.valid = RTC_MEM_VALID;
RtcSettings.energy_kWhtoday = Settings.energy_kWhtoday;
@ -68,9 +70,12 @@ void RtcSettingsLoad(void)
RtcSettings.pulse_counter[i] = Settings.pulse_counter[i];
}
RtcSettings.power = Settings.power;
// RtcSettings.baudrate = Settings.baudrate * 300;
RtcSettings.baudrate = APP_BAUDRATE;
RtcSettingsSave();
}
rtc_settings_crc = GetRtcSettingsCrc();
return was_read_valid;
}
bool RtcSettingsValid(void)

View File

@ -1495,13 +1495,6 @@ void GpioInit(void)
}
SetModuleType();
TasmotaGlobal.module_changed = (Settings.module != Settings.last_module);
if (TasmotaGlobal.module_changed) {
Settings.baudrate = APP_BAUDRATE / 300;
Settings.serial_config = TS_SERIAL_8N1;
SetSerialBegin();
}
// AddLog_P(LOG_LEVEL_DEBUG, PSTR("DBG: Used GPIOs %d"), GPIO_SENSOR_END);
#ifdef ESP8266

View File

@ -215,22 +215,27 @@ void setup(void) {
#endif
RtcRebootSave();
if (RtcSettingsLoad()) {
uint32_t baudrate = (RtcSettings.baudrate / 300) * 300; // Make it a valid baudrate
if (baudrate) { TasmotaGlobal.baudrate = baudrate; }
}
Serial.begin(TasmotaGlobal.baudrate);
Serial.println();
// Serial.setRxBufferSize(INPUT_BUFFER_SIZE); // Default is 256 chars
TasmotaGlobal.seriallog_level = LOG_LEVEL_INFO; // Allow specific serial messages until config loaded
snprintf_P(TasmotaGlobal.version, sizeof(TasmotaGlobal.version), PSTR("%d.%d.%d"), VERSION >> 24 & 0xff, VERSION >> 16 & 0xff, VERSION >> 8 & 0xff); // Release version 6.3.0
if (VERSION & 0xff) { // Development or patched version 6.3.0.10
snprintf_P(TasmotaGlobal.version, sizeof(TasmotaGlobal.version), PSTR("%s.%d"), TasmotaGlobal.version, VERSION & 0xff);
}
// Thehackbox inserts "release" or "commit number" before compiling using sed -i -e 's/PSTR("(%s)")/PSTR("(85cff52-%s)")/g' tasmota.ino
snprintf_P(TasmotaGlobal.image_name, sizeof(TasmotaGlobal.image_name), PSTR("(%s)"), CODE_IMAGE_STR); // Results in (85cff52-tasmota) or (release-tasmota)
SettingsLoad();
SettingsDelta();
OsWatchInit();
TasmotaGlobal.module_changed = (Settings.module != Settings.last_module);
if (TasmotaGlobal.module_changed) {
Settings.baudrate = APP_BAUDRATE / 300;
Settings.serial_config = TS_SERIAL_8N1;
}
SetSerialBegin();
if (1 == RtcReboot.fast_reboot_count) { // Allow setting override only when all is well
UpdateQuickPowerCycle(true);
}
@ -281,6 +286,13 @@ void setup(void) {
}
}
snprintf_P(TasmotaGlobal.version, sizeof(TasmotaGlobal.version), PSTR("%d.%d.%d"), VERSION >> 24 & 0xff, VERSION >> 16 & 0xff, VERSION >> 8 & 0xff); // Release version 6.3.0
if (VERSION & 0xff) { // Development or patched version 6.3.0.10
snprintf_P(TasmotaGlobal.version, sizeof(TasmotaGlobal.version), PSTR("%s.%d"), TasmotaGlobal.version, VERSION & 0xff);
}
// Thehackbox inserts "release" or "commit number" before compiling using sed -i -e 's/PSTR("(%s)")/PSTR("(85cff52-%s)")/g' tasmota.ino
snprintf_P(TasmotaGlobal.image_name, sizeof(TasmotaGlobal.image_name), PSTR("(%s)"), CODE_IMAGE_STR); // Results in (85cff52-tasmota) or (release-tasmota)
Format(TasmotaGlobal.mqtt_client, SettingsText(SET_MQTT_CLIENT), sizeof(TasmotaGlobal.mqtt_client));
Format(TasmotaGlobal.mqtt_topic, SettingsText(SET_MQTT_TOPIC), sizeof(TasmotaGlobal.mqtt_topic));
if (strchr(SettingsText(SET_HOSTNAME), '%') != nullptr) {