From 9225c5e28bf59db1437cc58e48d607c9777ce150 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Mon, 15 Aug 2022 16:18:17 +0300 Subject: [PATCH 01/10] Show firmware version on splash screen --- 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 f5199ed41..8de0e8692 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -798,7 +798,7 @@ int uart_putchar(char c, FILE *) void lcd_splash() { lcd_clear(); // clears display and homes screen - lcd_puts_P(PSTR("\n Original Prusa i3\n Prusa Research")); + lcd_printf_P(PSTR("\n Original Prusa i3\n Prusa Research\n%20.20S"), PSTR(FW_VERSION)); } From 336c41ffe37297faf4326fc5dc4156faf165358c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 17 Sep 2022 08:53:36 +0000 Subject: [PATCH 02/10] Initialise status line message in setup() Fixes #3581 --- Firmware/ultralcd.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 18efd1278..86b51ef13 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7518,6 +7518,9 @@ void ultralcd_init() lcd_oldcardstatus = IS_SD_INSERTED; #endif//(SDCARDDETECT > 0) lcd_encoder_diff = 0; + + // Initialise status line + lcd_setstatuspgm(MSG_WELCOME); } void lcd_ignore_click(bool b) From 540ce31082cfc83284b60101c0599f6c35782c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 17 Sep 2022 08:57:30 +0000 Subject: [PATCH 03/10] Don't initialise lcd status message in definition static variables are automatically zero initialised. Now that the status line message is initialised in ultralcd_init(), we don't need to set the variable in global scope. Saves 22 bytes of flash and 1 byte of SRAM --- Firmware/ultralcd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 86b51ef13..91972153e 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -94,7 +94,7 @@ static float manual_feedrate[] = MANUAL_FEEDRATE; /* LCD message status */ static LongTimer lcd_status_message_timeout; static uint8_t lcd_status_message_level; -static char lcd_status_message[LCD_WIDTH + 1] = WELCOME_MSG; +static char lcd_status_message[LCD_WIDTH + 1]; /* !Configuration settings */ From 33495d7516b977177bee20c23d6408b858d42473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 17 Sep 2022 09:13:07 +0000 Subject: [PATCH 04/10] Remove redundant for-loop Now that lcd_status_message is now initialised correctly at boot-up, this for-loop is no longer required. Now lcd_status_message is only set in lcd_updatestatus() which always calls lcd_finishstatus() lcd_finishstatus() makes sure the message does not exceed 20 characters Saves 34 bytes of flash --- Firmware/ultralcd.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 91972153e..cd322b126 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -669,11 +669,6 @@ void lcdui_print_status_line(void) break; } } - - // Fill the rest of line to have nice and clean output - for(uint8_t fillspace = 0; fillspace < LCD_WIDTH; fillspace++) - if ((lcd_status_message[fillspace] <= 31 )) - lcd_print(' '); } //! @brief Show Status Screen From b2530eeb13b6f941887c221e4868e3ecf01113dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sun, 18 Sep 2022 10:18:09 +0000 Subject: [PATCH 05/10] Optimisation: Remove duplicated code in cmdqueue_could_enqueue_back() Code is 28 lines shorter :) Change in memory: Flash: -42 bytes SRAM: 0 bytes --- Firmware/cmdqueue.cpp | 82 ++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 55 deletions(-) diff --git a/Firmware/cmdqueue.cpp b/Firmware/cmdqueue.cpp index 687f9cabc..c8f91d477 100755 --- a/Firmware/cmdqueue.cpp +++ b/Firmware/cmdqueue.cpp @@ -165,61 +165,33 @@ static bool cmdqueue_could_enqueue_back(size_t len_asked, bool atomic_update = f // Full buffer. return false; - if (serial_count > 0) { - // If there is some data stored starting at bufindw, len_asked is certainly smaller than - // the allocated data buffer. Try to reserve a new buffer and to move the already received - // serial data. - // How much memory to reserve for the commands pushed to the front? - // End of the queue, when pushing to the end. - size_t endw = bufindw + len_asked + (1 + CMDHDRSIZE); - if (bufindw < bufindr) - // Simple case. There is a contiguous space between the write buffer and the read buffer. - return endw + CMDBUFFER_RESERVE_FRONT <= bufindr; - // Otherwise the free space is split between the start and end. - if (// Could one fit to the end, including the reserve? - endw + CMDBUFFER_RESERVE_FRONT <= sizeof(cmdbuffer) || - // Could one fit to the end, and the reserve to the start? - (endw <= sizeof(cmdbuffer) && CMDBUFFER_RESERVE_FRONT <= bufindr)) - return true; - // Could one fit both to the start? - if (len_asked + (1 + CMDHDRSIZE) + CMDBUFFER_RESERVE_FRONT <= bufindr) { - // Mark the rest of the buffer as used. - memset(cmdbuffer+bufindw, 0, sizeof(cmdbuffer)-bufindw); - // and point to the start. - // Be careful! The bufindw needs to be changed atomically for the power panic & filament panic to work. - if (atomic_update) - cli(); - bufindw = 0; - if (atomic_update) - sei(); - return true; - } - } else { - // How much memory to reserve for the commands pushed to the front? - // End of the queue, when pushing to the end. - size_t endw = bufindw + len_asked + (1 + CMDHDRSIZE); - if (bufindw < bufindr) - // Simple case. There is a contiguous space between the write buffer and the read buffer. - return endw + CMDBUFFER_RESERVE_FRONT <= bufindr; - // Otherwise the free space is split between the start and end. - if (// Could one fit to the end, including the reserve? - endw + CMDBUFFER_RESERVE_FRONT <= sizeof(cmdbuffer) || - // Could one fit to the end, and the reserve to the start? - (endw <= sizeof(cmdbuffer) && CMDBUFFER_RESERVE_FRONT <= bufindr)) - return true; - // Could one fit both to the start? - if (len_asked + (1 + CMDHDRSIZE) + CMDBUFFER_RESERVE_FRONT <= bufindr) { - // Mark the rest of the buffer as used. - memset(cmdbuffer+bufindw, 0, sizeof(cmdbuffer)-bufindw); - // and point to the start. - // Be careful! The bufindw needs to be changed atomically for the power panic & filament panic to work. - if (atomic_update) - cli(); - bufindw = 0; - if (atomic_update) - sei(); - return true; - } + // If there is some data stored starting at bufindw, len_asked is certainly smaller than + // the allocated data buffer. Try to reserve a new buffer and to move the already received + // serial data. + // How much memory to reserve for the commands pushed to the front? + // End of the queue, when pushing to the end. + size_t endw = bufindw + len_asked + (1 + CMDHDRSIZE); + if (bufindw < bufindr) + // Simple case. There is a contiguous space between the write buffer and the read buffer. + return endw + CMDBUFFER_RESERVE_FRONT <= bufindr; + // Otherwise the free space is split between the start and end. + if (// Could one fit to the end, including the reserve? + endw + CMDBUFFER_RESERVE_FRONT <= sizeof(cmdbuffer) || + // Could one fit to the end, and the reserve to the start? + (endw <= sizeof(cmdbuffer) && CMDBUFFER_RESERVE_FRONT <= bufindr)) + return true; + // Could one fit both to the start? + if (len_asked + (1 + CMDHDRSIZE) + CMDBUFFER_RESERVE_FRONT <= bufindr) { + // Mark the rest of the buffer as used. + memset(cmdbuffer+bufindw, 0, sizeof(cmdbuffer)-bufindw); + // and point to the start. + // Be careful! The bufindw needs to be changed atomically for the power panic & filament panic to work. + if (atomic_update) + cli(); + bufindw = 0; + if (atomic_update) + sei(); + return true; } return false; } From b1bee597aafd87de7215ab0bae3b781871a3886c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Mon, 19 Sep 2022 17:54:40 +0000 Subject: [PATCH 06/10] Remove atomic_update parameter Change in memory: Flash: +24 bytes SRAM: -0 byte --- Firmware/cmdqueue.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Firmware/cmdqueue.cpp b/Firmware/cmdqueue.cpp index c8f91d477..cc7277c90 100755 --- a/Firmware/cmdqueue.cpp +++ b/Firmware/cmdqueue.cpp @@ -1,3 +1,4 @@ +#include #include "cmdqueue.h" #include "cardreader.h" #include "ultralcd.h" @@ -155,7 +156,7 @@ static bool cmdqueue_could_enqueue_front(size_t len_asked) // len_asked does not contain the zero terminator size. // This function may update bufindw, therefore for the power panic to work, this function must be called // with the interrupts disabled! -static bool cmdqueue_could_enqueue_back(size_t len_asked, bool atomic_update = false) +static bool cmdqueue_could_enqueue_back(size_t len_asked) { // MAX_CMD_SIZE has to accommodate the zero terminator. if (len_asked >= MAX_CMD_SIZE) @@ -186,11 +187,7 @@ static bool cmdqueue_could_enqueue_back(size_t len_asked, bool atomic_update = f memset(cmdbuffer+bufindw, 0, sizeof(cmdbuffer)-bufindw); // and point to the start. // Be careful! The bufindw needs to be changed atomically for the power panic & filament panic to work. - if (atomic_update) - cli(); - bufindw = 0; - if (atomic_update) - sei(); + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { bufindw = 0; } return true; } return false; @@ -343,7 +340,7 @@ void repeatcommand_front() void get_command() { // Test and reserve space for the new command string. - if (! cmdqueue_could_enqueue_back(MAX_CMD_SIZE - 1, true)) + if (! cmdqueue_could_enqueue_back(MAX_CMD_SIZE - 1)) return; if (MYSERIAL.available() == RX_BUFFER_SIZE - 1) { //compare number of chars buffered in rx buffer with rx buffer size @@ -489,7 +486,7 @@ void get_command() serial_count = 0; //clear buffer // Don't call cmdqueue_could_enqueue_back if there are no characters waiting // in the queue, as this function will reserve the memory. - if (MYSERIAL.available() == 0 || ! cmdqueue_could_enqueue_back(MAX_CMD_SIZE-1, true)) + if (MYSERIAL.available() == 0 || ! cmdqueue_could_enqueue_back(MAX_CMD_SIZE-1)) return; } // end of "end of line" processing else { @@ -587,7 +584,7 @@ void get_command() if(card.eof()) break; // The following line will reserve buffer space if available. - if (! cmdqueue_could_enqueue_back(MAX_CMD_SIZE-1, true)) + if (! cmdqueue_could_enqueue_back(MAX_CMD_SIZE-1)) return; } else From 9bff10add5a3068ce941423083683c4de50f5ec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Mon, 19 Sep 2022 18:07:55 +0000 Subject: [PATCH 07/10] Don't inline the function Change in memory: Flash: -44 bytes SRAM: 0 bytes --- Firmware/cmdqueue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/cmdqueue.cpp b/Firmware/cmdqueue.cpp index cc7277c90..202b36d42 100755 --- a/Firmware/cmdqueue.cpp +++ b/Firmware/cmdqueue.cpp @@ -156,7 +156,7 @@ static bool cmdqueue_could_enqueue_front(size_t len_asked) // len_asked does not contain the zero terminator size. // This function may update bufindw, therefore for the power panic to work, this function must be called // with the interrupts disabled! -static bool cmdqueue_could_enqueue_back(size_t len_asked) +static bool __attribute__((noinline)) cmdqueue_could_enqueue_back(size_t len_asked) { // MAX_CMD_SIZE has to accommodate the zero terminator. if (len_asked >= MAX_CMD_SIZE) From 2bd4aef23e6a3abcee22ca33a01fea50799a4fa9 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 20 Sep 2022 16:56:17 +0200 Subject: [PATCH 08/10] Temperature model: update R0 estimate Update the default R0 estimate thanks to a larger dataset. This improves the error margin during self-check. --- Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h | 2 +- Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h index ed5a1c551..ecab4565b 100644 --- a/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h @@ -422,7 +422,7 @@ #define TEMP_MODEL_C_thr 0.01 // C estimation iteration threshold #define TEMP_MODEL_C_itr 30 // C estimation iteration limit -#define TEMP_MODEL_R 29.7 // initial guess for heatblock resistance (K/W) +#define TEMP_MODEL_R 20.5 // initial guess for heatblock resistance (K/W) #define TEMP_MODEL_Rl 5 // R estimation lower limit #define TEMP_MODEL_Rh 50 // R estimation upper limit #define TEMP_MODEL_R_thr 0.01 // R estimation iteration threshold diff --git a/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h index 5b57bcec4..c1767ae10 100644 --- a/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h @@ -426,7 +426,7 @@ #define TEMP_MODEL_C_thr 0.01 // C estimation iteration threshold #define TEMP_MODEL_C_itr 30 // C estimation iteration limit -#define TEMP_MODEL_R 29.7 // initial guess for heatblock resistance (K/W) +#define TEMP_MODEL_R 20.5 // initial guess for heatblock resistance (K/W) #define TEMP_MODEL_Rl 5 // R estimation lower limit #define TEMP_MODEL_Rh 50 // R estimation upper limit #define TEMP_MODEL_R_thr 0.01 // R estimation iteration threshold From 140961290d4214a4c75a96688eaf4d9059657193 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 21 Sep 2022 10:19:16 +0200 Subject: [PATCH 09/10] Do not reset line on serial commands without N Fix regression introduced in fc10ca31466e1c58bcb5b9b90976a489239a6fde. Accept incoming serial commands without line numbers (assumed to be injected by the host), but do not reset the last line count when doing so. --- Firmware/cmdqueue.cpp | 10 ++++------ Firmware/cmdqueue.h | 1 - 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Firmware/cmdqueue.cpp b/Firmware/cmdqueue.cpp index 202b36d42..31c0cb79c 100755 --- a/Firmware/cmdqueue.cpp +++ b/Firmware/cmdqueue.cpp @@ -27,10 +27,7 @@ bool comment_mode = false; char *strchr_pointer; // just a pointer to find chars in the command string like X, Y, Z, E, etc ShortTimer serialTimeoutTimer; - -long gcode_N = 0; long gcode_LastN = 0; - uint32_t sdpos_atomic = 0; @@ -372,7 +369,7 @@ void get_command() cmdbuffer[bufindw+serial_count+CMDHDRSIZE] = 0; //terminate string if(!comment_mode){ - gcode_N = 0; + long gcode_N = -1; // Line numbers must be first in buffer @@ -459,7 +456,7 @@ void get_command() // Command is complete: store the current line into buffer, move to the next line. // Store type of entry - cmdbuffer[bufindw] = gcode_N ? CMDBUFFER_CURRENT_TYPE_USB_WITH_LINENR : CMDBUFFER_CURRENT_TYPE_USB; + cmdbuffer[bufindw] = gcode_N >= 0 ? CMDBUFFER_CURRENT_TYPE_USB_WITH_LINENR : CMDBUFFER_CURRENT_TYPE_USB; #ifdef CMDBUFFER_DEBUG SERIAL_ECHO_START; @@ -475,7 +472,8 @@ void get_command() ++ buflen; // Update the processed gcode line - gcode_LastN = gcode_N; + if (gcode_N >= 0) + gcode_LastN = gcode_N; #ifdef CMDBUFFER_DEBUG SERIAL_ECHOPGM("Number of commands in the buffer: "); diff --git a/Firmware/cmdqueue.h b/Firmware/cmdqueue.h index 5229b96b0..3573d5020 100644 --- a/Firmware/cmdqueue.h +++ b/Firmware/cmdqueue.h @@ -52,7 +52,6 @@ extern int serial_count; extern bool comment_mode; extern char *strchr_pointer; -extern long gcode_N; extern long gcode_LastN; extern bool cmdqueue_pop_front(); From 7bd9e5e06e7d6155e8813db0835eff173fbe4c99 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 21 Sep 2022 14:53:54 +0200 Subject: [PATCH 10/10] Move strings to progmem --- Firmware/Marlin_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 8de0e8692..d89800642 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -4285,11 +4285,11 @@ void process_commands() #endif //PRUSA_SN_SUPPORT else if(code_seen_P(PSTR("Fir"))){ // PRUSA Fir - SERIAL_PROTOCOLLN(FW_VERSION_FULL); + SERIAL_PROTOCOLLNPGM(FW_VERSION_FULL); } else if(code_seen_P(PSTR("Rev"))){ // PRUSA Rev - SERIAL_PROTOCOLLN(FILAMENT_SIZE "-" ELECTRONICS "-" NOZZLE_TYPE ); + SERIAL_PROTOCOLLNPGM(FILAMENT_SIZE "-" ELECTRONICS "-" NOZZLE_TYPE ); } else if(code_seen_P(PSTR("Lang"))) { // PRUSA Lang lang_reset();