From f388d8abb671ba18713f60c4bc93b7ff20682266 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Thu, 30 Mar 2023 13:50:32 +0200 Subject: [PATCH 1/6] postponed kill() message with softReset --- Firmware/Marlin.h | 2 +- Firmware/Marlin_main.cpp | 81 +++++++++++++++++++--------------------- Firmware/cardreader.cpp | 4 +- Firmware/cmdqueue.cpp | 2 +- Firmware/eeprom.h | 2 + Firmware/temperature.cpp | 2 +- 6 files changed, 45 insertions(+), 48 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index ddb758a12..28ebf9f11 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -234,7 +234,7 @@ void FlushSerialRequestResend(); void ClearToSend(); void update_currents(); -void kill(const char *full_screen_message = NULL, unsigned char id = 0); +void kill(const char *full_screen_message = NULL); void finishAndDisableSteppers(); void UnconditionalStop(); // Stop heaters, motion and clear current print status diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 155c6fd2b..e66ee6235 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1037,6 +1037,17 @@ static void fw_crash_init() eeprom_update_byte((uint8_t*)EEPROM_FW_CRASH_FLAG, 0xFF); } +static void fw_kill_init() { + PGM_P kill_msg = (PGM_P)eeprom_init_default_word((uint16_t*)EEPROM_KILL_MESSAGE, 0); + if (kill_msg) { + // clear pending message event + eeprom_write_word((uint16_t*)EEPROM_KILL_MESSAGE, 0); + + // display the kill message + lcd_show_fullscreen_message_and_wait_P(kill_msg); + } +} + static void xflash_err_msg() { @@ -1577,6 +1588,9 @@ void setup() // report crash failures fw_crash_init(); + // report kill() events + fw_kill_init(); + #ifdef UVLO_SUPPORT if (eeprom_read_byte((uint8_t*)EEPROM_UVLO) != 0) { //previous print was terminated by UVLO /* @@ -5970,7 +5984,7 @@ Sigma_Exit: It is processed much earlier as to bypass the cmdqueue. */ case 112: - kill(MSG_M112_KILL, 3); + kill(MSG_M112_KILL); break; /*! @@ -9378,7 +9392,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument s if(previous_millis_cmd.expired(max_inactive_time)) if(max_inactive_time) - kill(_n("Inactivity Shutdown"), 4); + kill(PSTR("Inactivity Shutdown")); if(stepper_inactive_time) { if(previous_millis_cmd.expired(stepper_inactive_time)) { @@ -9419,7 +9433,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument s // ---------------------------------------------------------------- if ( killCount >= KILL_DELAY) { - kill(NULL, 5); + kill(); } #endif @@ -9465,49 +9479,30 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument s host_keepalive(); } -void kill(const char *full_screen_message, unsigned char id) -{ - printf_P(_N("KILL: %d\n"), id); - //return; - cli(); // Stop interrupts - disable_heater(); +void kill(const char *full_screen_message) { + cli(); // Stop interrupts + disable_heater(); - disable_x(); -// SERIAL_ECHOLNPGM("kill - disable Y"); - disable_y(); - poweroff_z(); - disable_e0(); - disable_e1(); - disable_e2(); + disable_x(); + disable_y(); + poweroff_z(); + disable_e0(); + disable_e1(); + disable_e2(); -#if defined(PS_ON_PIN) && PS_ON_PIN > -1 - pinMode(PS_ON_PIN,INPUT); -#endif - SERIAL_ERROR_START; - SERIAL_ERRORLNRPGM(_n("Printer halted. kill() called!"));////MSG_ERR_KILLED - if (full_screen_message != NULL) { - SERIAL_ERRORLNRPGM(full_screen_message); - lcd_display_message_fullscreen_P(full_screen_message); - } else { - LCD_ALERTMESSAGERPGM(_n("KILLED. "));////MSG_KILLED - } + SERIAL_ERROR_START; + SERIAL_ERRORLNRPGM(PSTR("Printer halted. kill() called!")); - // FMC small patch to update the LCD before ending - sei(); // enable interrupts - for ( int i=5; i--; lcd_update(0)) - { - _delay(200); - } - cli(); // disable interrupts - suicide(); - while(1) - { -#ifdef WATCHDOG - wdt_reset(); -#endif //WATCHDOG - /* Intentionally left empty */ - - } // Wait for reset + if (full_screen_message != NULL) { + SERIAL_ERRORLNRPGM(full_screen_message); + } else { + full_screen_message = PSTR("KILLED."); + } + + // 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); + + softReset(); } void UnconditionalStop() diff --git a/Firmware/cardreader.cpp b/Firmware/cardreader.cpp index 8b902b703..3f437af1f 100644 --- a/Firmware/cardreader.cpp +++ b/Firmware/cardreader.cpp @@ -402,7 +402,7 @@ void CardReader::openFileReadFilteredGcode(const char* name, bool replace_curren // SERIAL_ERROR_START; // SERIAL_ERRORPGM("trying to call sub-gcode files with too many levels. MAX level is:"); // SERIAL_ERRORLN(SD_PROCEDURE_DEPTH); - kill(ofKill, 1); + kill(ofKill); return; } @@ -469,7 +469,7 @@ void CardReader::openFileWrite(const char* name) // SERIAL_ERROR_START; // SERIAL_ERRORPGM("trying to call sub-gcode files with too many levels. MAX level is:"); // SERIAL_ERRORLN(SD_PROCEDURE_DEPTH); - kill(ofKill, 1); + kill(ofKill); return; } diff --git a/Firmware/cmdqueue.cpp b/Firmware/cmdqueue.cpp index 76962dffc..6d31ab9c7 100755 --- a/Firmware/cmdqueue.cpp +++ b/Firmware/cmdqueue.cpp @@ -455,7 +455,7 @@ void get_command() // Handle KILL early, even when Stopped if(strcmp_P(cmd_start, PSTR("M112")) == 0) - kill(MSG_M112_KILL, 2); + kill(MSG_M112_KILL); // Bypass Stopped for some commands bool allow_when_stopped = false; diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index ae9185eb1..e2dc2ec9c 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -596,6 +596,8 @@ static Sheets * const EEPROM_Sheets_base = (Sheets*)(EEPROM_SHEETS_BASE); #define EEPROM_TEMP_MODEL_L (EEPROM_TEMP_MODEL_D-2) //uint16_t #define EEPROM_TEMP_MODEL_VER (EEPROM_TEMP_MODEL_L-1) //uint8_t +#define EEPROM_KILL_MESSAGE (EEPROM_TEMP_MODEL_VER-2) //PGM_P + //This is supposed to point to last item to allow EEPROM overrun check. Please update when adding new items. #define EEPROM_LAST_ITEM EEPROM_TEMP_MODEL_VER // !!!!! diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index c5ef0d5b7..5dab747bd 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -598,7 +598,7 @@ static float analog2temp(int raw, uint8_t e) { SERIAL_ERROR_START; SERIAL_ERROR((int)e); SERIAL_ERRORLNPGM(" - Invalid extruder number !"); - kill(NULL, 6); + kill(); return 0.0; } #ifdef HEATER_0_USES_MAX6675 From 2aca89d6dc5e0918ab0ab327951a9a699a3a42a6 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Thu, 30 Mar 2023 14:01:53 +0200 Subject: [PATCH 2/6] Update eeprom documentation --- Firmware/eeprom.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index e2dc2ec9c..7cfcb89a9 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -361,6 +361,8 @@ static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEP | 0x0CA1 3233 | float | EEPROM_TEMP_MODEL_V | ??? | ff ff ff ffh | Temp model linear temperature intercept (W/W) | Temp model | D3 Ax0ca1 C4 | 0x0C9D 3229 | float | EEPROM_TEMP_MODEL_D | ??? | ff ff ff ffh | Temp model sim. 1st order IIR filter factor | Temp model | D3 Ax0c9d C4 | 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 |Address begin|Bit/Type | Name | Valid values | Default/FactoryReset | Description |Gcode/Function| Debug code | :--: | :--: | :--: | :--: | :--: | :--: | :--: | :--: @@ -599,7 +601,7 @@ static Sheets * const EEPROM_Sheets_base = (Sheets*)(EEPROM_SHEETS_BASE); #define EEPROM_KILL_MESSAGE (EEPROM_TEMP_MODEL_VER-2) //PGM_P //This is supposed to point to last item to allow EEPROM overrun check. Please update when adding new items. -#define EEPROM_LAST_ITEM EEPROM_TEMP_MODEL_VER +#define EEPROM_LAST_ITEM EEPROM_KILL_MESSAGE // !!!!! // !!!!! this is end of EEPROM section ... all updates MUST BE inserted before this mark !!!!! // !!!!! From 4b65d49512a04dba2affe91383d708d80ed70498 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Sun, 9 Apr 2023 18:25:47 +0200 Subject: [PATCH 3/6] Move kill check earlier during startup --- Firmware/Marlin_main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index e66ee6235..27d6e0a9b 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1355,6 +1355,9 @@ void setup() if (!xflash_success) xflash_err_msg(); + // report kill() events + fw_kill_init(); + #ifdef FILAMENT_SENSOR fsensor.init(); #endif //FILAMENT_SENSOR @@ -1588,9 +1591,6 @@ void setup() // report crash failures fw_crash_init(); - // report kill() events - fw_kill_init(); - #ifdef UVLO_SUPPORT if (eeprom_read_byte((uint8_t*)EEPROM_UVLO) != 0) { //previous print was terminated by UVLO /* From f333d36e47be8643af0872f19396aea9f9dd0735 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Sun, 9 Apr 2023 18:44:17 +0200 Subject: [PATCH 4/6] 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 !!!!! // !!!!! From af4a3f3328fd2506ccafdf844afcb344d1fab242 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Thu, 13 Apr 2023 11:15:17 +0200 Subject: [PATCH 5/6] Reorder eeprom reads Saves 4B of flash --- Firmware/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index c43e4c740..a124c9be0 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1041,11 +1041,11 @@ static void fw_crash_init() static void fw_kill_init() { 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_byte((uint8_t*)EEPROM_KILL_PENDING_FLAG, EEPROM_EMPTY_VALUE); // display the kill message + PGM_P kill_msg = (PGM_P)eeprom_read_word((uint16_t*)EEPROM_KILL_MESSAGE); lcd_show_fullscreen_message_and_wait_P(kill_msg); } } From 41b8279805bc3b8dce1b07e8e2a7b5a77c7f0ee6 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Thu, 13 Apr 2023 11:34:18 +0200 Subject: [PATCH 6/6] Fix eeprom table addresses --- Firmware/eeprom.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index 674854473..e54984d53 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -357,13 +357,13 @@ static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEP | ^ | ^ | ^ | 20h 32 | ^ | Free bit | ^ | ^ | ^ | ^ | ^ | 40h 64 | ^ | Free bit | ^ | ^ | ^ | ^ | ^ | 80h 128 | ^ | Unknown | ^ | ^ -| 0x0CA5 3237 | float | EEPROM_TEMP_MODEL_U | ??? | ff ff ff ffh | Temp model linear temperature coefficient (W/K/W) | Temp model | D3 Ax0ca5 C4 -| 0x0CA1 3233 | float | EEPROM_TEMP_MODEL_V | ??? | ff ff ff ffh | Temp model linear temperature intercept (W/W) | Temp model | D3 Ax0ca1 C4 -| 0x0C9D 3229 | float | EEPROM_TEMP_MODEL_D | ??? | ff ff ff ffh | Temp model sim. 1st order IIR filter factor | Temp model | D3 Ax0c9d C4 -| 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 +| 0x0CA2 3234 | float | EEPROM_TEMP_MODEL_U | ??? | ff ff ff ffh | Temp model linear temperature coefficient (W/K/W) | Temp model | D3 Ax0ca2 C4 +| 0x0C9E 3230 | float | EEPROM_TEMP_MODEL_V | ??? | ff ff ff ffh | Temp model linear temperature intercept (W/W) | Temp model | D3 Ax0c9e C4 +| 0x0C9A 3226 | float | EEPROM_TEMP_MODEL_D | ??? | ff ff ff ffh | Temp model sim. 1st order IIR filter factor | Temp model | D3 Ax0c9a C4 +| 0x0C98 3224 | uint16 | EEPROM_TEMP_MODEL_L | 0-2160 | ff ffh | Temp model sim. response lag (ms) | Temp model | D3 Ax0c98 C2 +| 0x0C97 3223 | uint8 | EEPROM_TEMP_MODEL_VER | 0-255 | ffh | Temp model Version | Temp model | D3 Ax0c97 C1 +| 0x0C95 3221 | PGM_P | EEPROM_KILL_MESSAGE | 0-65535 | ff ffh | Kill message PGM pointer | kill() | D3 Ax0c95 C2 +| 0x0C94 3220 | uint8 | EEPROM_KILL_PENDING_FLAG | 42h, ffh | ffh | Kill pending flag (0x42 magic value) | kill() | D3 Ax0c94 C1 |Address begin|Bit/Type | Name | Valid values | Default/FactoryReset | Description |Gcode/Function| Debug code | :--: | :--: | :--: | :--: | :--: | :--: | :--: | :--: