From e3d83f62ef00f72cd4e802c3c5de5e480eb0dd4e Mon Sep 17 00:00:00 2001 From: GMagician <3684609+GMagician@users.noreply.github.com> Date: Sat, 15 Apr 2023 11:33:40 +0200 Subject: [PATCH 1/2] Fix M503C --- Marlin/src/gcode/eeprom/M500-M504.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Marlin/src/gcode/eeprom/M500-M504.cpp b/Marlin/src/gcode/eeprom/M500-M504.cpp index 6da1d1cbd73b..d63d1fc9a774 100644 --- a/Marlin/src/gcode/eeprom/M500-M504.cpp +++ b/Marlin/src/gcode/eeprom/M500-M504.cpp @@ -66,11 +66,20 @@ void GcodeSuite::M502() { #if ENABLED(CONFIGURATION_EMBEDDING) if (parser.seen_test('C')) { - SdBaseFile file; - const uint16_t size = sizeof(mc_zip); + MediaFile file; + // Need to create the config size on the SD card - if (file.open(card.getroot(), "mc.zip", O_WRITE|O_CREAT) && file.write(pgm_read_ptr(mc_zip), size) != -1 && file.close()) - SERIAL_ECHO_MSG("Configuration saved as 'mc.zip'"); + MediaFile root = card.getroot(); + if (file.open(&root, "mc.zip", O_WRITE|O_CREAT)) { + bool success = true; + for (uint16_t i; success && i < sizeof(mc_zip); ++i) { + const uint8_t c = pgm_read_byte(&mc_zip[i]); + file.write(c); + } + success = file.close() & success; + + if (success) SERIAL_ECHO_MSG("Configuration saved as 'mc.zip'"); + } } #endif } From f1f2dffdf8335e190f19ffb45deec47f5b0351b1 Mon Sep 17 00:00:00 2001 From: GMagician <3684609+GMagician@users.noreply.github.com> Date: Sat, 15 Apr 2023 11:37:25 +0200 Subject: [PATCH 2/2] Add missing & --- Marlin/src/gcode/eeprom/M500-M504.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/gcode/eeprom/M500-M504.cpp b/Marlin/src/gcode/eeprom/M500-M504.cpp index d63d1fc9a774..a8ffb5fa7d8a 100644 --- a/Marlin/src/gcode/eeprom/M500-M504.cpp +++ b/Marlin/src/gcode/eeprom/M500-M504.cpp @@ -76,7 +76,7 @@ void GcodeSuite::M502() { const uint8_t c = pgm_read_byte(&mc_zip[i]); file.write(c); } - success = file.close() & success; + success = file.close() && success; if (success) SERIAL_ECHO_MSG("Configuration saved as 'mc.zip'"); }