From 670bca47dae81f47e64db486cafd05c0825359c4 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 21 Dec 2022 17:11:58 +0100 Subject: [PATCH] Simplify FW eeprom version checks - Generalize force_selftest_if_fw_version() so we can check when upgrading between arbitrary FW versions. - Do not call update_current_firmware_version_to_eeprom() prematurely when forcing self-test (if a reset happens before self-test completes, the check would be incorrectly skipped on the next run). --- Firmware/Marlin_main.cpp | 3 +-- Firmware/util.cpp | 35 +++++++++++++---------------------- Firmware/util.h | 7 +++---- 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 1590e231..16185e17 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1569,9 +1569,8 @@ void setup() } #if !defined (DEBUG_DISABLE_FORCE_SELFTEST) && defined (TMC2130) - if (force_selftest_if_fw_version() && calibration_status() < CALIBRATION_STATUS_ASSEMBLED) { + if (eeprom_fw_version_older_than({3, 2, 0, 4}) && calibration_status() < CALIBRATION_STATUS_ASSEMBLED) { lcd_show_fullscreen_message_and_wait_P(_i("Selftest will be run to calibrate accurate sensorless rehoming."));////MSG_FORCE_SELFTEST c=20 r=8 - update_current_firmware_version_to_eeprom(); lcd_selftest(); } #endif //TMC2130 && !DEBUG_DISABLE_FORCE_SELFTEST diff --git a/Firmware/util.cpp b/Firmware/util.cpp index 9d7bca97..1fefbd35 100644 --- a/Firmware/util.cpp +++ b/Firmware/util.cpp @@ -181,32 +181,23 @@ inline int8_t is_provided_version_newer(const char *version_string) return 0; } -bool force_selftest_if_fw_version() +bool eeprom_fw_version_older_than(const uint16_t (&ver_req)[4]) { - //if fw version used before flashing new firmware (fw version currently stored in eeprom) is lower then 3.1.2-RC2, function returns true to force selftest + uint16_t ver_eeprom[4]; - uint16_t ver_eeprom[4]; - uint16_t ver_with_calibration[4] = {3, 1, 2, 4}; //hardcoded 3.1.2-RC2 version - bool force_selftest = false; + ver_eeprom[0] = eeprom_read_word((uint16_t*)EEPROM_FIRMWARE_VERSION_MAJOR); + ver_eeprom[1] = eeprom_read_word((uint16_t*)EEPROM_FIRMWARE_VERSION_MINOR); + ver_eeprom[2] = eeprom_read_word((uint16_t*)EEPROM_FIRMWARE_VERSION_REVISION); + ver_eeprom[3] = eeprom_read_word((uint16_t*)EEPROM_FIRMWARE_VERSION_FLAVOR); - ver_eeprom[0] = eeprom_read_word((uint16_t*)EEPROM_FIRMWARE_VERSION_MAJOR); - ver_eeprom[1] = eeprom_read_word((uint16_t*)EEPROM_FIRMWARE_VERSION_MINOR); - ver_eeprom[2] = eeprom_read_word((uint16_t*)EEPROM_FIRMWARE_VERSION_REVISION); - ver_eeprom[3] = eeprom_read_word((uint16_t*)EEPROM_FIRMWARE_VERSION_FLAVOR); + for (uint8_t i = 0; i < 4; ++i) { + if (ver_req[i] > ver_eeprom[i]) + return true; + else if (ver_req[i] < ver_eeprom[i]) + break; + } - for (uint8_t i = 0; i < 4; ++i) { - if (ver_with_calibration[i] > ver_eeprom[i]) { - force_selftest = true; - break; - } - else if (ver_with_calibration[i] < ver_eeprom[i]) - break; - } - - //force selftest also in case that version used before flashing new firmware was 3.2.0-RC1 - if ((ver_eeprom[0] == 3) && (ver_eeprom[1] == 2) && (ver_eeprom[2] == 0) && (ver_eeprom[3] == 3)) force_selftest = true; - - return force_selftest; + return false; } bool show_upgrade_dialog_if_version_newer(const char *version_string) diff --git a/Firmware/util.h b/Firmware/util.h index 206fdcd1..7481a455 100644 --- a/Firmware/util.h +++ b/Firmware/util.h @@ -16,10 +16,9 @@ enum FirmwareRevisionFlavorType : uint16_t { FIRMWARE_REVISION_RC = 0x0020 }; -extern bool show_upgrade_dialog_if_version_newer(const char *version_string); -extern bool force_selftest_if_fw_version(); - -extern void update_current_firmware_version_to_eeprom(); +bool show_upgrade_dialog_if_version_newer(const char *version_string); +bool eeprom_fw_version_older_than(const uint16_t (&req_ver)[4]); +void update_current_firmware_version_to_eeprom();