From f333d36e47be8643af0872f19396aea9f9dd0735 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Sun, 9 Apr 2023 18:44:17 +0200 Subject: [PATCH] Use a different location as a kill message pending flag The old implementation would fail if the message was in progmem at address 0xffff or 0x0000 (both unlikely). It would also fail if the eeprom was initialized to some other random value, which could have been dangerous when displayed as a full screen message. --- Firmware/Marlin_main.cpp | 9 ++++++--- Firmware/eeprom.h | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 27d6e0a9b..c43e4c740 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1037,11 +1037,13 @@ static void fw_crash_init() eeprom_update_byte((uint8_t*)EEPROM_FW_CRASH_FLAG, 0xFF); } +#define KILL_PENDING_FLAG 0x42 + static void fw_kill_init() { - PGM_P kill_msg = (PGM_P)eeprom_init_default_word((uint16_t*)EEPROM_KILL_MESSAGE, 0); - if (kill_msg) { + if (eeprom_read_byte((uint8_t*)EEPROM_KILL_PENDING_FLAG) == KILL_PENDING_FLAG) { + PGM_P kill_msg = (PGM_P)eeprom_read_word((uint16_t*)EEPROM_KILL_MESSAGE); // clear pending message event - eeprom_write_word((uint16_t*)EEPROM_KILL_MESSAGE, 0); + eeprom_write_byte((uint8_t*)EEPROM_KILL_PENDING_FLAG, EEPROM_EMPTY_VALUE); // display the kill message lcd_show_fullscreen_message_and_wait_P(kill_msg); @@ -9501,6 +9503,7 @@ void kill(const char *full_screen_message) { // update eeprom with the correct kill message to be shown on startup eeprom_write_word((uint16_t*)EEPROM_KILL_MESSAGE, (uint16_t)full_screen_message); + eeprom_write_byte((uint8_t*)EEPROM_KILL_PENDING_FLAG, KILL_PENDING_FLAG); softReset(); } diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index 7cfcb89a9..674854473 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -363,6 +363,7 @@ static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEP | 0x0C99 3225 | uint16 | EEPROM_TEMP_MODEL_L | 0-2160 | ff ffh | Temp model sim. response lag (ms) | Temp model | D3 Ax0c99 C2 | 0x0C98 3224 | uint8 | EEPROM_TEMP_MODEL_VER | 0-255 | ffh | Temp model Version | Temp model | D3 Ax0c98 C1 | 0x0C96 3222 | PGM_P | EEPROM_KILL_MESSAGE | 0-65535 | ff ffh | Kill message PGM pointer | kill() | D3 Ax0c96 C2 +| 0x0C95 3221 | uint8 | EEPROM_KILL_PENDING_FLAG | 42h, ffh | ffh | Kill pending flag (0x42 magic value) | kill() | D3 Ax0c95 C1 |Address begin|Bit/Type | Name | Valid values | Default/FactoryReset | Description |Gcode/Function| Debug code | :--: | :--: | :--: | :--: | :--: | :--: | :--: | :--: @@ -599,9 +600,10 @@ static Sheets * const EEPROM_Sheets_base = (Sheets*)(EEPROM_SHEETS_BASE); #define EEPROM_TEMP_MODEL_VER (EEPROM_TEMP_MODEL_L-1) //uint8_t #define EEPROM_KILL_MESSAGE (EEPROM_TEMP_MODEL_VER-2) //PGM_P +#define EEPROM_KILL_PENDING_FLAG (EEPROM_KILL_MESSAGE-1) //uint8 //This is supposed to point to last item to allow EEPROM overrun check. Please update when adding new items. -#define EEPROM_LAST_ITEM EEPROM_KILL_MESSAGE +#define EEPROM_LAST_ITEM EEPROM_KILL_PENDING_FLAG // !!!!! // !!!!! this is end of EEPROM section ... all updates MUST BE inserted before this mark !!!!! // !!!!!