From 5f8fc64a32b450e2cae845eddcf471bbff75cfc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 18 Mar 2023 15:34:47 +0000 Subject: [PATCH 01/11] Restore previous Z-lift in M701/M702 Previously when the firmware called M701/M702 manually there was no Z lift. But after we added support for the Z parameter we set the default to 50mm. Change strings "M701" to "M701 Z0" and "M702" to "M702 Z0" to restore the previous behavior from before 3.13. Also pulled the gcodes into PROGMEM in message.cpp along with M83 and M84 to save memory. Change in memory: Flash: -34 bytes SRAM: 0 bytes --- Firmware/Marlin_main.cpp | 6 +++--- Firmware/first_lay_cal.cpp | 13 +++++-------- Firmware/messages.cpp | 6 ++++++ Firmware/messages.h | 6 ++++++ Firmware/ultralcd.cpp | 14 +++++++------- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index b82105d9072f..65933485ad94 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2082,7 +2082,7 @@ bool check_commands() { while (buflen) { - if ((code_seen_P(PSTR("M84"))) || (code_seen_P(PSTR("M 84")))) end_command_found = true; + if ((code_seen_P(MSG_M84)) || (code_seen_P(PSTR("M 84")))) end_command_found = true; if (!cmdbuffer_front_already_processed) cmdqueue_pop_front(); cmdbuffer_front_already_processed = false; @@ -10783,7 +10783,7 @@ void recover_print(uint8_t automatic) { sprintf_P(cmd, PSTR("M109 S%d"), target_temperature[active_extruder]); enquecommand(cmd); - enquecommand_P(PSTR("M83")); //E axis relative mode + enquecommand_P(MSG_M83); //E axis relative mode // If not automatically recoreverd (long power loss) if(automatic == 0){ @@ -11150,7 +11150,7 @@ void stop_and_save_print_to_ram(float z_move, float e_move) { // First unretract (relative extrusion) if(!saved_extruder_relative_mode){ - enquecommand(PSTR("M83"), true); + enquecommand_P(MSG_M83); } //retract 45mm/s // A single sprintf may not be faster, but is definitely 20B shorter diff --git a/Firmware/first_lay_cal.cpp b/Firmware/first_lay_cal.cpp index 980af8b52831..cc186dbd6360 100644 --- a/Firmware/first_lay_cal.cpp +++ b/Firmware/first_lay_cal.cpp @@ -62,7 +62,7 @@ bool lay1cal_load_filament(char *cmd_buffer, uint8_t filament) { if (MMU2::mmu2.Enabled()) { - enquecommand_P(PSTR("M83")); + enquecommand_P(MSG_M83); enquecommand_P(PSTR("G1 Y-3 F1000")); enquecommand_P(PSTR("G1 Z0.4 F1000")); @@ -72,7 +72,7 @@ bool lay1cal_load_filament(char *cmd_buffer, uint8_t filament) return false; } else if( currentTool != (uint8_t)MMU2::FILAMENT_UNKNOWN){ // some other slot is loaded, perform an unload first - enquecommand_P(PSTR("M702")); + enquecommand_P(MSG_M702_NO_LIFT); } // perform a toolchange // sprintf_P(cmd_buffer, PSTR("T%d"), filament); @@ -142,7 +142,6 @@ void lay1cal_before_meander() { static const char cmd_pre_meander_1[] PROGMEM = "G21"; //set units to millimeters TODO unsupported command static const char cmd_pre_meander_2[] PROGMEM = "G90"; //use absolute coordinates - static const char cmd_pre_meander_3[] PROGMEM = "M83"; //use relative distances for extrusion TODO: duplicate static const char cmd_pre_meander_4[] PROGMEM = "G1 E-1.5 F2100"; static const char cmd_pre_meander_5[] PROGMEM = "G1 Z5 F7200"; static const char cmd_pre_meander_6[] PROGMEM = "M204 S1000"; //set acceleration @@ -153,7 +152,7 @@ void lay1cal_before_meander() zero_extrusion, cmd_pre_meander_1, cmd_pre_meander_2, - cmd_pre_meander_3, + MSG_M83, // use relative distances for extrusion cmd_pre_meander_4, cmd_pre_meander_5, cmd_pre_meander_6, @@ -254,8 +253,6 @@ void lay1cal_finish(bool mmu_enabled) static const char cmd_cal_finish_3[] PROGMEM = "M140 S0"; // turn off heatbed static const char cmd_cal_finish_4[] PROGMEM = "G1 Z10 F1300"; //lift Z static const char cmd_cal_finish_5[] PROGMEM = "G1 X10 Y180 F4000"; //Go to parking position - static const char cmd_cal_finish_6[] PROGMEM = "M702"; //unload from nozzle - static const char cmd_cal_finish_7[] PROGMEM = "M84";// disable motors static const char * const cmd_cal_finish[] PROGMEM = { @@ -272,6 +269,6 @@ void lay1cal_finish(bool mmu_enabled) enquecommand_P(static_cast(pgm_read_ptr(&cmd_cal_finish[i]))); } - if (mmu_enabled) enquecommand_P(cmd_cal_finish_6); //unload from nozzle - enquecommand_P(cmd_cal_finish_7);// disable motors + if (mmu_enabled) enquecommand_P(MSG_M702_NO_LIFT); //unload from nozzle + enquecommand_P(MSG_M84);// disable motors } diff --git a/Firmware/messages.cpp b/Firmware/messages.cpp index ed8dd4ad5d2c..b42a97e8f309 100644 --- a/Firmware/messages.cpp +++ b/Firmware/messages.cpp @@ -228,3 +228,9 @@ const char MSG_ADVANCE_K[] PROGMEM_N1 = "Advance K:"; ////c=13 const char MSG_POWERPANIC_DETECTED[] PROGMEM_N1 = "POWER PANIC DETECTED"; ////c=20 const char MSG_LCD_STATUS_CHANGED[] PROGMEM_N1 = "LCD status changed"; const char MSG_UNKNOWN_CODE[] PROGMEM_N1 = "Unknown %c code: %s\n"; + +// Common G-gcodes +const char MSG_M701_NO_LIFT[] PROGMEM_N1 = "M701 Z0"; +const char MSG_M702_NO_LIFT[] PROGMEM_N1 = "M702 Z0"; +const char MSG_M83[] PROGMEM_N1 = "M83"; +const char MSG_M84[] PROGMEM_N1 = "M84"; diff --git a/Firmware/messages.h b/Firmware/messages.h index 276bab0a757f..54ab8466faad 100644 --- a/Firmware/messages.h +++ b/Firmware/messages.h @@ -235,6 +235,12 @@ extern const char MSG_POWERPANIC_DETECTED[]; extern const char MSG_LCD_STATUS_CHANGED[]; extern const char MSG_UNKNOWN_CODE[]; +// Common G-gcodes +extern const char MSG_M701_NO_LIFT[]; +extern const char MSG_M702_NO_LIFT[]; +extern const char MSG_M83[]; +extern const char MSG_M84[]; + #if defined(__cplusplus) } #endif //defined(__cplusplus) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index f327fbdc161c..710a6a1a8dd7 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -1847,10 +1847,10 @@ switch(eFilamentAction) // FALLTHRU case FilamentAction::Load: loading_flag=true; - enquecommand_P(PSTR("M701")); // load filament + enquecommand_P(MSG_M701_NO_LIFT); // load filament break; case FilamentAction::UnLoad: - enquecommand_P(PSTR("M702")); // unload filament + enquecommand_P(MSG_M702_NO_LIFT); // unload filament break; case FilamentAction::MmuLoad: case FilamentAction::MmuLoadingTest: @@ -1908,11 +1908,11 @@ void mFilamentItem(uint16_t nTemp, uint16_t nTempBed) if ((eFilamentAction == FilamentAction::Load) || (eFilamentAction == FilamentAction::AutoLoad)) { loading_flag = true; - enquecommand_P(PSTR("M701")); // load filament + enquecommand_P(MSG_M701_NO_LIFT); // load filament if (eFilamentAction == FilamentAction::AutoLoad) eFilamentAction = FilamentAction::None; // i.e. non-autoLoad } if (eFilamentAction == FilamentAction::UnLoad) - enquecommand_P(PSTR("M702")); // unload filament + enquecommand_P(MSG_M702_NO_LIFT); // unload filament } break; case FilamentAction::MmuLoad: @@ -3804,7 +3804,7 @@ static void lcd_wizard_load() { loading_flag = true; } gcode_M701(FILAMENTCHANGE_FIRSTFEED, 0); - //enquecommand_P(PSTR("M701")); + //enquecommand_P(MSG_M701_NO_LIFT); // is enqueuecommand_P safe here? } static void wizard_lay1cal_message(bool cold) @@ -4593,7 +4593,7 @@ static void lcd_settings_menu() if (!printer_active() || isPrintPaused) { MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_axis);////MSG_MOVE_AXIS c=18 - MENU_ITEM_GCODE_P(_i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS c=18 + MENU_ITEM_GCODE_P(_i("Disable steppers"), MSG_M84);////MSG_DISABLE_STEPPERS c=18 } #ifdef FILAMENT_SENSOR @@ -6363,7 +6363,7 @@ bool lcd_selftest() _progress = lcd_selftest_screen(TestScreen::Failed, _progress, 3, true, 5000); } lcd_reset_alert_level(); - enquecommand_P(PSTR("M84")); + enquecommand_P(MSG_M84); lcd_update_enable(true); if (_result) From 7c0ead7bc280448667f315f3f510742748839131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 18 Mar 2023 16:15:10 +0000 Subject: [PATCH 02/11] Add M24 into PROGMEM Change in memory: Flash: -8 bytes SRAM: 0 bytes --- Firmware/Marlin_main.cpp | 2 +- Firmware/cardreader.cpp | 2 +- Firmware/messages.cpp | 1 + Firmware/messages.h | 1 + Firmware/ultralcd.cpp | 2 +- 5 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 65933485ad94..6e3d3402e685 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -4182,7 +4182,7 @@ void process_commands() } else if (code_seen_P(PSTR("uvlo"))) { // PRUSA uvlo eeprom_update_byte((uint8_t*)EEPROM_UVLO,0); - enquecommand_P(PSTR("M24")); + enquecommand_P(MSG_M24); } else if (code_seen_P(PSTR("MMURES"))) // PRUSA MMURES { diff --git a/Firmware/cardreader.cpp b/Firmware/cardreader.cpp index 4f8ee6c58aed..bc54e24af99c 100644 --- a/Firmware/cardreader.cpp +++ b/Firmware/cardreader.cpp @@ -654,7 +654,7 @@ void CardReader::checkautostart(bool force) sprintf_P(cmd, PSTR("M23 %s"), autoname); enquecommand(cmd); // M24: Start/resume SD print - enquecommand_P(PSTR("M24")); + enquecommand_P(MSG_M24); found=true; } } diff --git a/Firmware/messages.cpp b/Firmware/messages.cpp index b42a97e8f309..0d5c0b84feb4 100644 --- a/Firmware/messages.cpp +++ b/Firmware/messages.cpp @@ -232,5 +232,6 @@ const char MSG_UNKNOWN_CODE[] PROGMEM_N1 = "Unknown %c code: %s\n"; // Common G-gcodes const char MSG_M701_NO_LIFT[] PROGMEM_N1 = "M701 Z0"; const char MSG_M702_NO_LIFT[] PROGMEM_N1 = "M702 Z0"; +const char MSG_M24[] PROGMEM_N1 = "M24"; const char MSG_M83[] PROGMEM_N1 = "M83"; const char MSG_M84[] PROGMEM_N1 = "M84"; diff --git a/Firmware/messages.h b/Firmware/messages.h index 54ab8466faad..847e21cd0e79 100644 --- a/Firmware/messages.h +++ b/Firmware/messages.h @@ -238,6 +238,7 @@ extern const char MSG_UNKNOWN_CODE[]; // Common G-gcodes extern const char MSG_M701_NO_LIFT[]; extern const char MSG_M702_NO_LIFT[]; +extern const char MSG_M24[]; extern const char MSG_M83[]; extern const char MSG_M84[]; diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 710a6a1a8dd7..df26ccf51707 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7304,7 +7304,7 @@ static void menu_action_sdfile(const char* filename) } if (result) { enquecommand(cmd); - enquecommand_P(PSTR("M24")); + enquecommand_P(MSG_M24); } lcd_return_to_status(); From 129cc18cbfac303d01d144ad1381351527752d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 18 Mar 2023 16:18:05 +0000 Subject: [PATCH 03/11] Add M23 %s into PROGMEM Change in memory: Flash: -14 bytes SRAM: 0 bytes --- Firmware/Marlin_main.cpp | 2 +- Firmware/cardreader.cpp | 2 +- Firmware/messages.cpp | 1 + Firmware/messages.h | 1 + Firmware/ultralcd.cpp | 2 +- 5 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 6e3d3402e685..61ba0f2bc560 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -10915,7 +10915,7 @@ void restore_print_from_eeprom(bool mbl_was_active) { MYSERIAL.print(filename); strcat_P(filename, PSTR(".gco")); - sprintf_P(cmd, PSTR("M23 %s"), filename); + sprintf_P(cmd, MSG_M23, filename); enquecommand(cmd); uint32_t position = eeprom_read_dword((uint32_t*)(EEPROM_FILE_POSITION)); SERIAL_ECHOPGM("Position read from eeprom:"); diff --git a/Firmware/cardreader.cpp b/Firmware/cardreader.cpp index bc54e24af99c..f91f05b52fb8 100644 --- a/Firmware/cardreader.cpp +++ b/Firmware/cardreader.cpp @@ -651,7 +651,7 @@ void CardReader::checkautostart(bool force) { char cmd[30]; // M23: Select SD file - sprintf_P(cmd, PSTR("M23 %s"), autoname); + sprintf_P(cmd, MSG_M23, autoname); enquecommand(cmd); // M24: Start/resume SD print enquecommand_P(MSG_M24); diff --git a/Firmware/messages.cpp b/Firmware/messages.cpp index 0d5c0b84feb4..83e1cc766072 100644 --- a/Firmware/messages.cpp +++ b/Firmware/messages.cpp @@ -232,6 +232,7 @@ const char MSG_UNKNOWN_CODE[] PROGMEM_N1 = "Unknown %c code: %s\n"; // Common G-gcodes const char MSG_M701_NO_LIFT[] PROGMEM_N1 = "M701 Z0"; const char MSG_M702_NO_LIFT[] PROGMEM_N1 = "M702 Z0"; +const char MSG_M23[] PROGMEM_N1 = "M23 %s"; const char MSG_M24[] PROGMEM_N1 = "M24"; const char MSG_M83[] PROGMEM_N1 = "M83"; const char MSG_M84[] PROGMEM_N1 = "M84"; diff --git a/Firmware/messages.h b/Firmware/messages.h index 847e21cd0e79..1881315d816d 100644 --- a/Firmware/messages.h +++ b/Firmware/messages.h @@ -238,6 +238,7 @@ extern const char MSG_UNKNOWN_CODE[]; // Common G-gcodes extern const char MSG_M701_NO_LIFT[]; extern const char MSG_M702_NO_LIFT[]; +extern const char MSG_M23[]; extern const char MSG_M24[]; extern const char MSG_M83[]; extern const char MSG_M84[]; diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index df26ccf51707..79e4a0f41fd9 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7269,7 +7269,7 @@ static void menu_action_sdfile(const char* filename) char cmd[30]; char* c; bool result = true; - sprintf_P(cmd, PSTR("M23 %s"), filename); + sprintf_P(cmd, MSG_M23, filename); for (c = &cmd[4]; *c; c++) *c = tolower(*c); From 466a6a8fc373d73db68b3c6ab6997e151fe3d19a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 18 Mar 2023 16:33:13 +0000 Subject: [PATCH 04/11] Add M600 into PROGMEM Change in memory: Flash: -10 bytes SRAM: 0 bytes --- Firmware/Filament_sensor.cpp | 4 ++-- Firmware/messages.cpp | 5 +++-- Firmware/messages.h | 5 +++-- Firmware/mmu2.cpp | 2 +- Firmware/ultralcd.cpp | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Firmware/Filament_sensor.cpp b/Firmware/Filament_sensor.cpp index dbccf2760f85..e99ab928cea4 100644 --- a/Firmware/Filament_sensor.cpp +++ b/Firmware/Filament_sensor.cpp @@ -163,7 +163,7 @@ void Filament_sensor::filRunout() { restore_print_from_ram_and_continue(0); eeprom_increment_byte((uint8_t *)EEPROM_FERROR_COUNT); eeprom_increment_word((uint16_t *)EEPROM_FERROR_COUNT_TOT); - enquecommand_front_P((PSTR("M600"))); + enquecommand_front_P(MSG_M600); } void Filament_sensor::triggerError() { @@ -483,7 +483,7 @@ void PAT9125_sensor::filJam() { restore_print_from_ram_and_continue(0); eeprom_increment_byte((uint8_t *)EEPROM_FERROR_COUNT); eeprom_increment_word((uint16_t *)EEPROM_FERROR_COUNT_TOT); - enquecommand_front_P((PSTR("M600"))); + enquecommand_front_P(MSG_M600); } bool PAT9125_sensor::updatePAT9125() { diff --git a/Firmware/messages.cpp b/Firmware/messages.cpp index 83e1cc766072..66d35a09c004 100644 --- a/Firmware/messages.cpp +++ b/Firmware/messages.cpp @@ -230,9 +230,10 @@ const char MSG_LCD_STATUS_CHANGED[] PROGMEM_N1 = "LCD status changed"; const char MSG_UNKNOWN_CODE[] PROGMEM_N1 = "Unknown %c code: %s\n"; // Common G-gcodes -const char MSG_M701_NO_LIFT[] PROGMEM_N1 = "M701 Z0"; -const char MSG_M702_NO_LIFT[] PROGMEM_N1 = "M702 Z0"; const char MSG_M23[] PROGMEM_N1 = "M23 %s"; const char MSG_M24[] PROGMEM_N1 = "M24"; const char MSG_M83[] PROGMEM_N1 = "M83"; const char MSG_M84[] PROGMEM_N1 = "M84"; +const char MSG_M600[] PROGMEM_N1 = "M600"; +const char MSG_M701_NO_LIFT[] PROGMEM_N1 = "M701 Z0"; +const char MSG_M702_NO_LIFT[] PROGMEM_N1 = "M702 Z0"; diff --git a/Firmware/messages.h b/Firmware/messages.h index 1881315d816d..c50f9baabe8c 100644 --- a/Firmware/messages.h +++ b/Firmware/messages.h @@ -236,12 +236,13 @@ extern const char MSG_LCD_STATUS_CHANGED[]; extern const char MSG_UNKNOWN_CODE[]; // Common G-gcodes -extern const char MSG_M701_NO_LIFT[]; -extern const char MSG_M702_NO_LIFT[]; extern const char MSG_M23[]; extern const char MSG_M24[]; extern const char MSG_M83[]; extern const char MSG_M84[]; +extern const char MSG_M600[]; +extern const char MSG_M701_NO_LIFT[]; +extern const char MSG_M702_NO_LIFT[]; #if defined(__cplusplus) } diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index 46ed0d664577..62b46375e7d1 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -188,7 +188,7 @@ void MMU2::CheckFINDARunout() { if (SpoolJoin::spooljoin.isSpoolJoinEnabled() && get_current_tool() != (uint8_t)FILAMENT_UNKNOWN){ // Can't auto if F=? enquecommand_front_P(PSTR("M600 AUTO")); // save print and run M600 command } else { - enquecommand_front_P(PSTR("M600")); // save print and run M600 command + enquecommand_front_P(MSG_M600); // save print and run M600 command } } } diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 79e4a0f41fd9..2df85e00f5f6 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -5490,7 +5490,7 @@ void stepper_timer_overflow() { static void lcd_colorprint_change() { - enquecommand_P(PSTR("M600")); + enquecommand_P(MSG_M600); custom_message_type = CustomMsg::FilamentLoading; //just print status message lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS)); From 733bc874fba60b31f3094d6fe1617fcf9d6c461f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 18 Mar 2023 16:48:30 +0000 Subject: [PATCH 05/11] Move G28W0 to messages No change in memory --- Firmware/Marlin_main.cpp | 1 - Firmware/messages.cpp | 1 + Firmware/messages.h | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 61ba0f2bc560..ad4f75afcedd 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -255,7 +255,6 @@ uint8_t host_keepalive_interval = HOST_KEEPALIVE_INTERVAL; const char errormagic[] PROGMEM = "Error:"; const char echomagic[] PROGMEM = "echo:"; -const char G28W0[] PROGMEM = "G28 W0"; // Define some coordinates outside the clamp limits (making them invalid past the parsing stage) so // that they can be used later for various logical checks diff --git a/Firmware/messages.cpp b/Firmware/messages.cpp index 66d35a09c004..deeaa40f9ca8 100644 --- a/Firmware/messages.cpp +++ b/Firmware/messages.cpp @@ -230,6 +230,7 @@ const char MSG_LCD_STATUS_CHANGED[] PROGMEM_N1 = "LCD status changed"; const char MSG_UNKNOWN_CODE[] PROGMEM_N1 = "Unknown %c code: %s\n"; // Common G-gcodes +const char G28W0[] PROGMEM_N1 = "G28 W0"; const char MSG_M23[] PROGMEM_N1 = "M23 %s"; const char MSG_M24[] PROGMEM_N1 = "M24"; const char MSG_M83[] PROGMEM_N1 = "M83"; diff --git a/Firmware/messages.h b/Firmware/messages.h index c50f9baabe8c..90607198046e 100644 --- a/Firmware/messages.h +++ b/Firmware/messages.h @@ -236,6 +236,7 @@ extern const char MSG_LCD_STATUS_CHANGED[]; extern const char MSG_UNKNOWN_CODE[]; // Common G-gcodes +extern const char G28W0[]; extern const char MSG_M23[]; extern const char MSG_M24[]; extern const char MSG_M83[]; From 5ade1716bfa42f46c3b36c3b64a0466d152a71ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 18 Mar 2023 17:01:59 +0000 Subject: [PATCH 06/11] Add M500 into PROGMEM Change in memory: Flash: -6 bytes SRAM: 0 bytes --- Firmware/messages.cpp | 1 + Firmware/messages.h | 1 + Firmware/ultralcd.cpp | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Firmware/messages.cpp b/Firmware/messages.cpp index deeaa40f9ca8..6a906c34b828 100644 --- a/Firmware/messages.cpp +++ b/Firmware/messages.cpp @@ -235,6 +235,7 @@ const char MSG_M23[] PROGMEM_N1 = "M23 %s"; const char MSG_M24[] PROGMEM_N1 = "M24"; const char MSG_M83[] PROGMEM_N1 = "M83"; const char MSG_M84[] PROGMEM_N1 = "M84"; +const char MSG_M500[] PROGMEM_N1 = "M500"; const char MSG_M600[] PROGMEM_N1 = "M600"; const char MSG_M701_NO_LIFT[] PROGMEM_N1 = "M701 Z0"; const char MSG_M702_NO_LIFT[] PROGMEM_N1 = "M702 Z0"; diff --git a/Firmware/messages.h b/Firmware/messages.h index 90607198046e..ccc614a47ec2 100644 --- a/Firmware/messages.h +++ b/Firmware/messages.h @@ -241,6 +241,7 @@ extern const char MSG_M23[]; extern const char MSG_M24[]; extern const char MSG_M83[]; extern const char MSG_M84[]; +extern const char MSG_M500[]; extern const char MSG_M600[]; extern const char MSG_M701_NO_LIFT[]; extern const char MSG_M702_NO_LIFT[]; diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 2df85e00f5f6..815c1a46e543 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -916,7 +916,7 @@ void lcd_commands() if (_Kp != 0 || _Ki != 0 || _Kd != 0) { sprintf_P(cmd1, PSTR("M301 P%.2f I%.2f D%.2f"), _Kp, _Ki, _Kd); enquecommand(cmd1); - enquecommand_P(PSTR("M500")); + enquecommand_P(MSG_M500); } else { SERIAL_ECHOPGM("Invalid PID cal. results. Not stored to EEPROM."); @@ -950,7 +950,7 @@ void lcd_commands() case 2: if (temp_model_autotune_result()) - enquecommand_P(PSTR("M500")); + enquecommand_P(MSG_M500); lcd_commands_step = 1; break; From 00515a975d8071af46d900bbac60763b62d1f222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 18 Mar 2023 17:05:35 +0000 Subject: [PATCH 07/11] Add M107 into PROGMEM Change in memory: Flash: -4 bytes SRAM: 0 bytes --- Firmware/first_lay_cal.cpp | 5 ++--- Firmware/messages.cpp | 1 + Firmware/messages.h | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Firmware/first_lay_cal.cpp b/Firmware/first_lay_cal.cpp index cc186dbd6360..d3baf5134970 100644 --- a/Firmware/first_lay_cal.cpp +++ b/Firmware/first_lay_cal.cpp @@ -41,7 +41,7 @@ void lay1cal_wait_preheat() { const char * const preheat_cmd[] = { - PSTR("M107"), + MSG_M107, PSTR("M190"), PSTR("M109"), PSTR("G28"), @@ -247,7 +247,6 @@ void lay1cal_square(uint8_t step, float layer_height, float extrusion_width) void lay1cal_finish(bool mmu_enabled) { - static const char cmd_cal_finish_0[] PROGMEM = "M107"; //turn off printer fan static const char cmd_cal_finish_1[] PROGMEM = "G1 E-0.075 F2100"; //retract static const char cmd_cal_finish_2[] PROGMEM = "M104 S0"; // turn off temperature static const char cmd_cal_finish_3[] PROGMEM = "M140 S0"; // turn off heatbed @@ -256,7 +255,7 @@ void lay1cal_finish(bool mmu_enabled) static const char * const cmd_cal_finish[] PROGMEM = { - cmd_cal_finish_0, + MSG_M107, // turn off printer fan cmd_cal_finish_1, cmd_cal_finish_2, cmd_cal_finish_3, diff --git a/Firmware/messages.cpp b/Firmware/messages.cpp index 6a906c34b828..3b88702d867a 100644 --- a/Firmware/messages.cpp +++ b/Firmware/messages.cpp @@ -235,6 +235,7 @@ const char MSG_M23[] PROGMEM_N1 = "M23 %s"; const char MSG_M24[] PROGMEM_N1 = "M24"; const char MSG_M83[] PROGMEM_N1 = "M83"; const char MSG_M84[] PROGMEM_N1 = "M84"; +const char MSG_M107[] PROGMEM_N1 = "M107"; const char MSG_M500[] PROGMEM_N1 = "M500"; const char MSG_M600[] PROGMEM_N1 = "M600"; const char MSG_M701_NO_LIFT[] PROGMEM_N1 = "M701 Z0"; diff --git a/Firmware/messages.h b/Firmware/messages.h index ccc614a47ec2..6d6fa63e95f4 100644 --- a/Firmware/messages.h +++ b/Firmware/messages.h @@ -241,6 +241,7 @@ extern const char MSG_M23[]; extern const char MSG_M24[]; extern const char MSG_M83[]; extern const char MSG_M84[]; +extern const char MSG_M107[]; extern const char MSG_M500[]; extern const char MSG_M600[]; extern const char MSG_M701_NO_LIFT[]; From 6edd8b0719f7c99c6c25e9607356ffdf637ee957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 18 Mar 2023 17:09:43 +0000 Subject: [PATCH 08/11] Add M220 into PROGMEM Change in memory: Flash: -10 bytes SRAM: 0 bytes --- Firmware/Marlin_main.cpp | 4 ++-- Firmware/messages.cpp | 1 + Firmware/messages.h | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index ad4f75afcedd..80fbb0e7f639 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3584,7 +3584,7 @@ static void gcode_M600(bool automatic, float x_position, float y_position, float // Recover feed rate feedmultiply = feedmultiplyBckp; char cmd[9]; - sprintf_P(cmd, PSTR("M220 S%i"), feedmultiplyBckp); + sprintf_P(cmd, MSG_M220, feedmultiplyBckp); enquecommand(cmd); } @@ -10957,7 +10957,7 @@ void restore_print_from_eeprom(bool mbl_was_active) { // Set the feedrates saved at the power panic. sprintf_P(cmd, PSTR("G1 F%d"), feedrate_rec); enquecommand(cmd); - sprintf_P(cmd, PSTR("M220 S%d"), feedmultiply_rec); + sprintf_P(cmd, MSG_M220, feedmultiply_rec); enquecommand(cmd); // Set the fan speed saved at the power panic. sprintf_P(cmd, PSTR("M106 S%u"), fan_speed_rec); diff --git a/Firmware/messages.cpp b/Firmware/messages.cpp index 3b88702d867a..577570439251 100644 --- a/Firmware/messages.cpp +++ b/Firmware/messages.cpp @@ -236,6 +236,7 @@ const char MSG_M24[] PROGMEM_N1 = "M24"; const char MSG_M83[] PROGMEM_N1 = "M83"; const char MSG_M84[] PROGMEM_N1 = "M84"; const char MSG_M107[] PROGMEM_N1 = "M107"; +const char MSG_M220[] PROGMEM_N1 = "M220 S%d"; const char MSG_M500[] PROGMEM_N1 = "M500"; const char MSG_M600[] PROGMEM_N1 = "M600"; const char MSG_M701_NO_LIFT[] PROGMEM_N1 = "M701 Z0"; diff --git a/Firmware/messages.h b/Firmware/messages.h index 6d6fa63e95f4..d6b67e05e6c5 100644 --- a/Firmware/messages.h +++ b/Firmware/messages.h @@ -242,6 +242,7 @@ extern const char MSG_M24[]; extern const char MSG_M83[]; extern const char MSG_M84[]; extern const char MSG_M107[]; +extern const char MSG_M220[]; extern const char MSG_M500[]; extern const char MSG_M600[]; extern const char MSG_M701_NO_LIFT[]; From f296b3f8267384ee6f4206d55dda2a70d33056a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 18 Mar 2023 17:23:01 +0000 Subject: [PATCH 09/11] G21 is not implemented, don't queue it It's just a single 'break', will likely not be implemented Change in memory: Flash: -6 bytes SRAM: 0 bytes --- Firmware/first_lay_cal.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Firmware/first_lay_cal.cpp b/Firmware/first_lay_cal.cpp index d3baf5134970..87d94c55cc23 100644 --- a/Firmware/first_lay_cal.cpp +++ b/Firmware/first_lay_cal.cpp @@ -140,7 +140,6 @@ void lay1cal_intro_line(bool extraPurgeNeeded, float layer_height, float extrusi //! @brief Setup for printing meander void lay1cal_before_meander() { - static const char cmd_pre_meander_1[] PROGMEM = "G21"; //set units to millimeters TODO unsupported command static const char cmd_pre_meander_2[] PROGMEM = "G90"; //use absolute coordinates static const char cmd_pre_meander_4[] PROGMEM = "G1 E-1.5 F2100"; static const char cmd_pre_meander_5[] PROGMEM = "G1 Z5 F7200"; @@ -150,7 +149,6 @@ void lay1cal_before_meander() static const char * const cmd_pre_meander[] PROGMEM = { zero_extrusion, - cmd_pre_meander_1, cmd_pre_meander_2, MSG_M83, // use relative distances for extrusion cmd_pre_meander_4, From bc27b7172929ff0bd73527d27d6e55cfbce331da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 18 Mar 2023 17:37:27 +0000 Subject: [PATCH 10/11] Pull one common G1 gcode into PROGMEM Change in memory: Flash: -32 bytes SRAM: 0 bytes --- Firmware/Marlin_main.cpp | 6 +++--- Firmware/messages.cpp | 1 + Firmware/messages.h | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 80fbb0e7f639..3cee10a554a9 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -10789,7 +10789,7 @@ void recover_print(uint8_t automatic) { //Extrude some filament to stabilize the pressure enquecommand_P(PSTR("G1 E5 F120")); // Retract to be consistent with a short pause - sprintf_P(cmd, PSTR("G1 E%-0.3f F2700"), default_retraction); + sprintf_P(cmd, G1_E_F2700, default_retraction); enquecommand(cmd); } @@ -10946,7 +10946,7 @@ void restore_print_from_eeprom(bool mbl_was_active) { enquecommand(cmd); // Unretract. - sprintf_P(cmd, PSTR("G1 E%0.3f F2700"), default_retraction); + sprintf_P(cmd, G1_E_F2700, default_retraction); enquecommand(cmd); // Recover final E axis position and mode float pos_e = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E)); @@ -11157,7 +11157,7 @@ void stop_and_save_print_to_ram(float z_move, float e_move) // A snprintf would have been a safer call, but since it is not used // in the whole program, its implementation would bring more bytes to the total size // The behavior of dtostrf 8,3 should be roughly the same as %-0.3 - sprintf_P(buf, PSTR("G1 E%-0.3f F2700"), e_move); + sprintf_P(buf, G1_E_F2700, e_move); enquecommand(buf, false); } diff --git a/Firmware/messages.cpp b/Firmware/messages.cpp index 577570439251..988a00d0c160 100644 --- a/Firmware/messages.cpp +++ b/Firmware/messages.cpp @@ -230,6 +230,7 @@ const char MSG_LCD_STATUS_CHANGED[] PROGMEM_N1 = "LCD status changed"; const char MSG_UNKNOWN_CODE[] PROGMEM_N1 = "Unknown %c code: %s\n"; // Common G-gcodes +const char G1_E_F2700[] PROGMEM_N1 = "G1 E%-0.3f F2700"; const char G28W0[] PROGMEM_N1 = "G28 W0"; const char MSG_M23[] PROGMEM_N1 = "M23 %s"; const char MSG_M24[] PROGMEM_N1 = "M24"; diff --git a/Firmware/messages.h b/Firmware/messages.h index d6b67e05e6c5..81ba55bd86a0 100644 --- a/Firmware/messages.h +++ b/Firmware/messages.h @@ -236,6 +236,7 @@ extern const char MSG_LCD_STATUS_CHANGED[]; extern const char MSG_UNKNOWN_CODE[]; // Common G-gcodes +extern const char G1_E_F2700[]; extern const char G28W0[]; extern const char MSG_M23[]; extern const char MSG_M24[]; From 7e0bf88431e864f11569f00ae7df01c3b77cd721 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Wed, 22 Mar 2023 12:30:16 +0100 Subject: [PATCH 11/11] Use `G28 W` only --- Firmware/Marlin_main.cpp | 10 +++++----- Firmware/messages.cpp | 2 +- Firmware/messages.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 3cee10a554a9..554d3f6ca059 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2809,7 +2809,7 @@ static void gcode_G80() // Push the commands to the front of the message queue in the reverse order! // There shall be always enough space reserved for these commands. repeatcommand_front(); // repeat G80 with all its parameters - enquecommand_front_P(G28W0); + enquecommand_front_P(G28W); return; } @@ -2842,7 +2842,7 @@ static void gcode_G80() temp_compensation_start(); run = true; repeatcommand_front(); // repeat G80 with all its parameters - enquecommand_front_P(G28W0); + enquecommand_front_P(G28W); return; } run = false; @@ -4736,7 +4736,7 @@ void process_commands() // Push the commands to the front of the message queue in the reverse order! // There shall be always enough space reserved for these commands. repeatcommand_front(); // repeat G76 with all its parameters - enquecommand_front_P(G28W0); + enquecommand_front_P(G28W); break; } lcd_show_fullscreen_message_and_wait_P(_i("Stable ambient temperature 21-26C is needed a rigid stand is required."));////MSG_TEMP_CAL_WARNING c=20 r=4 @@ -4881,7 +4881,7 @@ void process_commands() // Push the commands to the front of the message queue in the reverse order! // There shall be always enough space reserved for these commands. repeatcommand_front(); // repeat G76 with all its parameters - enquecommand_front_P(G28W0); + enquecommand_front_P(G28W); break; } puts_P(_N("PINDA probe calibration start")); @@ -10101,7 +10101,7 @@ void bed_analysis(float x_dimension, float y_dimension, int x_points_num, int y_ // There shall be always enough space reserved for these commands. repeatcommand_front(); // repeat G80 with all its parameters - enquecommand_front_P(G28W0); + enquecommand_front_P(G28W); enquecommand_front_P((PSTR("G1 Z5"))); return; } diff --git a/Firmware/messages.cpp b/Firmware/messages.cpp index 988a00d0c160..ad9b2b2f3582 100644 --- a/Firmware/messages.cpp +++ b/Firmware/messages.cpp @@ -231,7 +231,7 @@ const char MSG_UNKNOWN_CODE[] PROGMEM_N1 = "Unknown %c code: %s\n"; // Common G-gcodes const char G1_E_F2700[] PROGMEM_N1 = "G1 E%-0.3f F2700"; -const char G28W0[] PROGMEM_N1 = "G28 W0"; +const char G28W[] PROGMEM_N1 = "G28 W"; const char MSG_M23[] PROGMEM_N1 = "M23 %s"; const char MSG_M24[] PROGMEM_N1 = "M24"; const char MSG_M83[] PROGMEM_N1 = "M83"; diff --git a/Firmware/messages.h b/Firmware/messages.h index 81ba55bd86a0..d7a1bc99734a 100644 --- a/Firmware/messages.h +++ b/Firmware/messages.h @@ -237,7 +237,7 @@ extern const char MSG_UNKNOWN_CODE[]; // Common G-gcodes extern const char G1_E_F2700[]; -extern const char G28W0[]; +extern const char G28W[]; extern const char MSG_M23[]; extern const char MSG_M24[]; extern const char MSG_M83[];