From 3370329751a21130c97f2b0c621ad8a75dd449b7 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 11 May 2017 10:48:16 -0400 Subject: [PATCH] Fix broken EEPROM save/load --- Marlin/configuration_store.cpp | 14 ++++++++------ Marlin/configuration_store.h | 4 ++-- Marlin/utility.cpp | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Marlin/configuration_store.cpp b/Marlin/configuration_store.cpp index 4ea56ff6f..a6a330616 100644 --- a/Marlin/configuration_store.cpp +++ b/Marlin/configuration_store.cpp @@ -625,15 +625,18 @@ void MarlinSettings::postprocess() { if (!eeprom_error) { const int eeprom_size = eeprom_index; + const uint16_t tcrc = working_crc; + // Write the EEPROM header eeprom_index = EEPROM_OFFSET; + EEPROM_WRITE(version); - EEPROM_WRITE(working_crc); + EEPROM_WRITE(tcrc); // Report storage size SERIAL_ECHO_START; SERIAL_ECHOPAIR("Settings Stored (", eeprom_size - (EEPROM_OFFSET)); - SERIAL_ECHOPAIR(" bytes; crc ", working_crc); + SERIAL_ECHOPAIR(" bytes; crc ", tcrc); SERIAL_ECHOLNPGM(")"); } @@ -982,11 +985,11 @@ void MarlinSettings::postprocess() { } else { SERIAL_ERROR_START; - SERIAL_ERRORPGM("EEPROM checksum mismatch - (stored CRC)"); + SERIAL_ERRORPGM("EEPROM CRC mismatch - (stored) "); SERIAL_ERROR(stored_crc); SERIAL_ERRORPGM(" != "); SERIAL_ERROR(working_crc); - SERIAL_ERRORLNPGM(" (calculated CRC)!"); + SERIAL_ERRORLNPGM(" (calculated)!"); reset(); } @@ -1027,7 +1030,6 @@ void MarlinSettings::postprocess() { return !eeprom_error; } - #if ENABLED(AUTO_BED_LEVELING_UBL) void ubl_invalid_slot(const int s) { @@ -1051,7 +1053,7 @@ void MarlinSettings::postprocess() { if (!WITHIN(slot, 0, a - 1)) { ubl_invalid_slot(a); SERIAL_PROTOCOLPAIR("E2END=", E2END); - SERIAL_PROTOCOLPAIR(" meshes_end=", (int)meshes_end); + SERIAL_PROTOCOLPAIR(" meshes_end=", meshes_end); SERIAL_PROTOCOLLNPAIR(" slot=", slot); SERIAL_EOL; return; diff --git a/Marlin/configuration_store.h b/Marlin/configuration_store.h index 1166ed29e..23a716a94 100644 --- a/Marlin/configuration_store.h +++ b/Marlin/configuration_store.h @@ -67,8 +67,8 @@ class MarlinSettings { #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system // That can store is enabled static int meshes_begin; - const static int mat_end = E2END; // Mesh allocation table; this may not end up being necessary - const static int meshes_end = mat_end - 128; // 128 is a placeholder for the size of the MAT + const static int meshes_end = E2END - 128; // 128 is a placeholder for the size of the MAT; the MAT will always + // live at the very end of the eeprom #endif diff --git a/Marlin/utility.cpp b/Marlin/utility.cpp index 43544106e..15378fb62 100644 --- a/Marlin/utility.cpp +++ b/Marlin/utility.cpp @@ -37,8 +37,8 @@ void safe_delay(millis_t ms) { #if ENABLED(EEPROM_SETTINGS) void crc16(uint16_t *crc, const void * const data, uint16_t cnt) { - uint8_t *ptr = (uint8_t*)data; - while (cnt-- > 0) { + uint8_t *ptr = (uint8_t *)data; + while (cnt--) { *crc = (uint16_t)(*crc ^ (uint16_t)(((uint16_t)*ptr++) << 8)); for (uint8_t x = 0; x < 8; x++) *crc = (uint16_t)((*crc & 0x8000) ? ((uint16_t)(*crc << 1) ^ 0x1021) : (*crc << 1));