Browse Source

Fix broken EEPROM save/load

Brian 7 years ago
parent
commit
3370329751
3 changed files with 12 additions and 10 deletions
  1. 8
    6
      Marlin/configuration_store.cpp
  2. 2
    2
      Marlin/configuration_store.h
  3. 2
    2
      Marlin/utility.cpp

+ 8
- 6
Marlin/configuration_store.cpp View File

@@ -625,15 +625,18 @@ void MarlinSettings::postprocess() {
625 625
     if (!eeprom_error) {
626 626
       const int eeprom_size = eeprom_index;
627 627
 
628
+      const uint16_t tcrc = working_crc;
629
+
628 630
       // Write the EEPROM header
629 631
       eeprom_index = EEPROM_OFFSET;
632
+
630 633
       EEPROM_WRITE(version);
631
-      EEPROM_WRITE(working_crc);
634
+      EEPROM_WRITE(tcrc);
632 635
 
633 636
       // Report storage size
634 637
       SERIAL_ECHO_START;
635 638
       SERIAL_ECHOPAIR("Settings Stored (", eeprom_size - (EEPROM_OFFSET));
636
-      SERIAL_ECHOPAIR(" bytes; crc ", working_crc);
639
+      SERIAL_ECHOPAIR(" bytes; crc ", tcrc);
637 640
       SERIAL_ECHOLNPGM(")");
638 641
     }
639 642
 
@@ -982,11 +985,11 @@ void MarlinSettings::postprocess() {
982 985
       }
983 986
       else {
984 987
         SERIAL_ERROR_START;
985
-        SERIAL_ERRORPGM("EEPROM checksum mismatch - (stored CRC)");
988
+        SERIAL_ERRORPGM("EEPROM CRC mismatch - (stored) ");
986 989
         SERIAL_ERROR(stored_crc);
987 990
         SERIAL_ERRORPGM(" != ");
988 991
         SERIAL_ERROR(working_crc);
989
-        SERIAL_ERRORLNPGM(" (calculated CRC)!");
992
+        SERIAL_ERRORLNPGM(" (calculated)!");
990 993
         reset();
991 994
       }
992 995
 
@@ -1027,7 +1030,6 @@ void MarlinSettings::postprocess() {
1027 1030
     return !eeprom_error;
1028 1031
   }
1029 1032
 
1030
-
1031 1033
   #if ENABLED(AUTO_BED_LEVELING_UBL)
1032 1034
 
1033 1035
     void ubl_invalid_slot(const int s) {
@@ -1051,7 +1053,7 @@ void MarlinSettings::postprocess() {
1051 1053
         if (!WITHIN(slot, 0, a - 1)) {
1052 1054
           ubl_invalid_slot(a);
1053 1055
           SERIAL_PROTOCOLPAIR("E2END=", E2END);
1054
-          SERIAL_PROTOCOLPAIR(" meshes_end=", (int)meshes_end);
1056
+          SERIAL_PROTOCOLPAIR(" meshes_end=", meshes_end);
1055 1057
           SERIAL_PROTOCOLLNPAIR(" slot=", slot);
1056 1058
           SERIAL_EOL;
1057 1059
           return;

+ 2
- 2
Marlin/configuration_store.h View File

@@ -67,8 +67,8 @@ class MarlinSettings {
67 67
       #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
68 68
                                          // That can store is enabled
69 69
         static int meshes_begin;
70
-        const static int mat_end = E2END;            // Mesh allocation table; this may not end up being necessary
71
-        const static int meshes_end = mat_end - 128; // 128 is a placeholder for the size of the MAT
70
+        const static int meshes_end = E2END - 128; // 128 is a placeholder for the size of the MAT; the MAT will always
71
+                                                   // live at the very end of the eeprom
72 72
 
73 73
       #endif
74 74
 

+ 2
- 2
Marlin/utility.cpp View File

@@ -37,8 +37,8 @@ void safe_delay(millis_t ms) {
37 37
 #if ENABLED(EEPROM_SETTINGS)
38 38
 
39 39
   void crc16(uint16_t *crc, const void * const data, uint16_t cnt) {
40
-    uint8_t *ptr = (uint8_t*)data;
41
-    while (cnt-- > 0) {
40
+    uint8_t *ptr = (uint8_t *)data;
41
+    while (cnt--) {
42 42
       *crc = (uint16_t)(*crc ^ (uint16_t)(((uint16_t)*ptr++) << 8));
43 43
       for (uint8_t x = 0; x < 8; x++)
44 44
         *crc = (uint16_t)((*crc & 0x8000) ? ((uint16_t)(*crc << 1) ^ 0x1021) : (*crc << 1));

Loading…
Cancel
Save