Browse Source

EEPROM Checksum

Scott Lahteine 9 years ago
parent
commit
5e370006fc
1 changed files with 91 additions and 67 deletions
  1. 91
    67
      Marlin/configuration_store.cpp

+ 91
- 67
Marlin/configuration_store.cpp View File

@@ -36,88 +36,89 @@
36 36
  *
37 37
  */
38 38
 
39
-#define EEPROM_VERSION "V23"
39
+#define EEPROM_VERSION "V24"
40 40
 
41 41
 /**
42
- * V23 EEPROM Layout:
42
+ * V24 EEPROM Layout:
43 43
  *
44 44
  *  100  Version (char x4)
45
+ *  104  EEPROM Checksum (uint16_t)
45 46
  *
46
- *  104  M92 XYZE  planner.axis_steps_per_mm (float x4)
47
- *  120  M203 XYZE planner.max_feedrate (float x4)
48
- *  136  M201 XYZE planner.max_acceleration_mm_per_s2 (uint32_t x4)
49
- *  152  M204 P    planner.acceleration (float)
50
- *  156  M204 R    planner.retract_acceleration (float)
51
- *  160  M204 T    planner.travel_acceleration (float)
52
- *  164  M205 S    planner.min_feedrate (float)
53
- *  168  M205 T    planner.min_travel_feedrate (float)
54
- *  172  M205 B    planner.min_segment_time (ulong)
55
- *  176  M205 X    planner.max_xy_jerk (float)
56
- *  180  M205 Z    planner.max_z_jerk (float)
57
- *  184  M205 E    planner.max_e_jerk (float)
58
- *  188  M206 XYZ  home_offset (float x3)
47
+ *  106  M92 XYZE  planner.axis_steps_per_mm (float x4)
48
+ *  122  M203 XYZE planner.max_feedrate (float x4)
49
+ *  138  M201 XYZE planner.max_acceleration_mm_per_s2 (uint32_t x4)
50
+ *  154  M204 P    planner.acceleration (float)
51
+ *  158  M204 R    planner.retract_acceleration (float)
52
+ *  162  M204 T    planner.travel_acceleration (float)
53
+ *  166  M205 S    planner.min_feedrate (float)
54
+ *  170  M205 T    planner.min_travel_feedrate (float)
55
+ *  174  M205 B    planner.min_segment_time (ulong)
56
+ *  178  M205 X    planner.max_xy_jerk (float)
57
+ *  182  M205 Z    planner.max_z_jerk (float)
58
+ *  186  M205 E    planner.max_e_jerk (float)
59
+ *  190  M206 XYZ  home_offset (float x3)
59 60
  *
60 61
  * Mesh bed leveling:
61
- *  200  M420 S    status (uint8)
62
- *  201            z_offset (float)
63
- *  205            mesh_num_x (uint8 as set in firmware)
64
- *  206            mesh_num_y (uint8 as set in firmware)
65
- *  207 G29 S3 XYZ z_values[][] (float x9, by default)
62
+ *  202  M420 S    status (uint8)
63
+ *  203            z_offset (float)
64
+ *  207            mesh_num_x (uint8 as set in firmware)
65
+ *  208            mesh_num_y (uint8 as set in firmware)
66
+ *  209 G29 S3 XYZ z_values[][] (float x9, by default)
66 67
  *
67 68
  * AUTO BED LEVELING
68
- *  243  M851      zprobe_zoffset (float)
69
+ *  245  M851      zprobe_zoffset (float)
69 70
  *
70 71
  * DELTA:
71
- *  247  M666 XYZ  endstop_adj (float x3)
72
- *  259  M665 R    delta_radius (float)
73
- *  263  M665 L    delta_diagonal_rod (float)
74
- *  267  M665 S    delta_segments_per_second (float)
75
- *  271  M665 A    delta_diagonal_rod_trim_tower_1 (float)
76
- *  275  M665 B    delta_diagonal_rod_trim_tower_2 (float)
77
- *  279  M665 C    delta_diagonal_rod_trim_tower_3 (float)
72
+ *  249  M666 XYZ  endstop_adj (float x3)
73
+ *  261  M665 R    delta_radius (float)
74
+ *  265  M665 L    delta_diagonal_rod (float)
75
+ *  269  M665 S    delta_segments_per_second (float)
76
+ *  273  M665 A    delta_diagonal_rod_trim_tower_1 (float)
77
+ *  277  M665 B    delta_diagonal_rod_trim_tower_2 (float)
78
+ *  281  M665 C    delta_diagonal_rod_trim_tower_3 (float)
78 79
  *
79 80
  * Z_DUAL_ENDSTOPS:
80
- *  283  M666 Z    z_endstop_adj (float)
81
+ *  285  M666 Z    z_endstop_adj (float)
81 82
  *
82 83
  * ULTIPANEL:
83
- *  287  M145 S0 H plaPreheatHotendTemp (int)
84
- *  289  M145 S0 B plaPreheatHPBTemp (int)
85
- *  291  M145 S0 F plaPreheatFanSpeed (int)
86
- *  293  M145 S1 H absPreheatHotendTemp (int)
87
- *  295  M145 S1 B absPreheatHPBTemp (int)
88
- *  297  M145 S1 F absPreheatFanSpeed (int)
84
+ *  289  M145 S0 H plaPreheatHotendTemp (int)
85
+ *  291  M145 S0 B plaPreheatHPBTemp (int)
86
+ *  293  M145 S0 F plaPreheatFanSpeed (int)
87
+ *  295  M145 S1 H absPreheatHotendTemp (int)
88
+ *  297  M145 S1 B absPreheatHPBTemp (int)
89
+ *  299  M145 S1 F absPreheatFanSpeed (int)
89 90
  *
90 91
  * PIDTEMP:
91
- *  299  M301 E0 PIDC  Kp[0], Ki[0], Kd[0], Kc[0] (float x4)
92
- *  315  M301 E1 PIDC  Kp[1], Ki[1], Kd[1], Kc[1] (float x4)
93
- *  331  M301 E2 PIDC  Kp[2], Ki[2], Kd[2], Kc[2] (float x4)
94
- *  347  M301 E3 PIDC  Kp[3], Ki[3], Kd[3], Kc[3] (float x4)
95
- *  363  M301 L        lpq_len (int)
92
+ *  301  M301 E0 PIDC  Kp[0], Ki[0], Kd[0], Kc[0] (float x4)
93
+ *  317  M301 E1 PIDC  Kp[1], Ki[1], Kd[1], Kc[1] (float x4)
94
+ *  333  M301 E2 PIDC  Kp[2], Ki[2], Kd[2], Kc[2] (float x4)
95
+ *  349  M301 E3 PIDC  Kp[3], Ki[3], Kd[3], Kc[3] (float x4)
96
+ *  365  M301 L        lpq_len (int)
96 97
  *
97 98
  * PIDTEMPBED:
98
- *  365  M304 PID  thermalManager.bedKp, thermalManager.bedKi, thermalManager.bedKd (float x3)
99
+ *  367  M304 PID  thermalManager.bedKp, thermalManager.bedKi, thermalManager.bedKd (float x3)
99 100
  *
100 101
  * DOGLCD:
101
- *  377  M250 C    lcd_contrast (int)
102
+ *  379  M250 C    lcd_contrast (int)
102 103
  *
103 104
  * SCARA:
104
- *  379  M365 XYZ  axis_scaling (float x3)
105
+ *  381  M365 XYZ  axis_scaling (float x3)
105 106
  *
106 107
  * FWRETRACT:
107
- *  391  M209 S    autoretract_enabled (bool)
108
- *  392  M207 S    retract_length (float)
109
- *  396  M207 W    retract_length_swap (float)
110
- *  400  M207 F    retract_feedrate_mm_s (float)
111
- *  404  M207 Z    retract_zlift (float)
112
- *  408  M208 S    retract_recover_length (float)
113
- *  412  M208 W    retract_recover_length_swap (float)
114
- *  416  M208 F    retract_recover_feedrate (float)
108
+ *  393  M209 S    autoretract_enabled (bool)
109
+ *  394  M207 S    retract_length (float)
110
+ *  398  M207 W    retract_length_swap (float)
111
+ *  402  M207 F    retract_feedrate_mm_s (float)
112
+ *  406  M207 Z    retract_zlift (float)
113
+ *  410  M208 S    retract_recover_length (float)
114
+ *  414  M208 W    retract_recover_length_swap (float)
115
+ *  418  M208 F    retract_recover_feedrate (float)
115 116
  *
116 117
  * Volumetric Extrusion:
117
- *  420  M200 D    volumetric_enabled (bool)
118
- *  421  M200 T D  filament_size (float x4) (T0..3)
118
+ *  422  M200 D    volumetric_enabled (bool)
119
+ *  423  M200 T D  filament_size (float x4) (T0..3)
119 120
  *
120
- *  437  This Slot is Available!
121
+ *  439  This Slot is Available!
121 122
  *
122 123
  */
123 124
 #include "Marlin.h"
@@ -131,6 +132,9 @@
131 132
   #include "mesh_bed_leveling.h"
132 133
 #endif
133 134
 
135
+uint16_t eeprom_checksum;
136
+const char version[4] = EEPROM_VERSION;
137
+
134 138
 void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size) {
135 139
   uint8_t c;
136 140
   while (size--) {
@@ -140,13 +144,16 @@ void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size) {
140 144
       SERIAL_ECHO_START;
141 145
       SERIAL_ECHOLNPGM(MSG_ERR_EEPROM_WRITE);
142 146
     }
147
+    eeprom_checksum += c;
143 148
     pos++;
144 149
     value++;
145 150
   };
146 151
 }
147 152
 void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size) {
148 153
   do {
149
-    *value = eeprom_read_byte((unsigned char*)pos);
154
+    uint8_t c = eeprom_read_byte((unsigned char*)pos);
155
+    *value = c;
156
+    eeprom_checksum += c;
150 157
     pos++;
151 158
     value++;
152 159
   } while (--size);
@@ -172,7 +179,12 @@ void Config_StoreSettings()  {
172 179
   float dummy = 0.0f;
173 180
   char ver[4] = "000";
174 181
   int i = EEPROM_OFFSET;
175
-  EEPROM_WRITE_VAR(i, ver); // invalidate data first
182
+
183
+  EEPROM_WRITE_VAR(i, ver);     // invalidate data first
184
+  i += sizeof(eeprom_checksum); // Skip the checksum slot
185
+
186
+  eeprom_checksum = 0; // clear before first "real data"
187
+
176 188
   EEPROM_WRITE_VAR(i, planner.axis_steps_per_mm);
177 189
   EEPROM_WRITE_VAR(i, planner.max_feedrate);
178 190
   EEPROM_WRITE_VAR(i, planner.max_acceleration_mm_per_s2);
@@ -324,9 +336,11 @@ void Config_StoreSettings()  {
324 336
     EEPROM_WRITE_VAR(i, dummy);
325 337
   }
326 338
 
327
-  char ver2[4] = EEPROM_VERSION;
339
+  uint16_t final_checksum = eeprom_checksum;
340
+
328 341
   int j = EEPROM_OFFSET;
329
-  EEPROM_WRITE_VAR(j, ver2); // validate data
342
+  EEPROM_WRITE_VAR(j, version);
343
+  EEPROM_WRITE_VAR(j, final_checksum);
330 344
 
331 345
   // Report storage size
332 346
   SERIAL_ECHO_START;
@@ -342,18 +356,21 @@ void Config_RetrieveSettings() {
342 356
 
343 357
   int i = EEPROM_OFFSET;
344 358
   char stored_ver[4];
345
-  char ver[4] = EEPROM_VERSION;
346
-  EEPROM_READ_VAR(i, stored_ver); //read stored version
359
+  uint16_t stored_checksum;
360
+  EEPROM_READ_VAR(i, stored_ver);
361
+  EEPROM_READ_VAR(i, stored_checksum);
347 362
   //  SERIAL_ECHOPAIR("Version: [", ver);
348 363
   //  SERIAL_ECHOPAIR("] Stored version: [", stored_ver);
349 364
   //  SERIAL_ECHOLNPGM("]");
350 365
 
351
-  if (strncmp(ver, stored_ver, 3) != 0) {
366
+  if (strncmp(version, stored_ver, 3) != 0) {
352 367
     Config_ResetDefault();
353 368
   }
354 369
   else {
355 370
     float dummy = 0;
356 371
 
372
+    eeprom_checksum = 0; // clear before reading first "real data"
373
+
357 374
     // version number match
358 375
     EEPROM_READ_VAR(i, planner.axis_steps_per_mm);
359 376
     EEPROM_READ_VAR(i, planner.max_feedrate);
@@ -506,12 +523,19 @@ void Config_RetrieveSettings() {
506 523
     // Call thermalManager.updatePID (similar to when we have processed M301)
507 524
     thermalManager.updatePID();
508 525
 
509
-    // Report settings retrieved and length
510
-    SERIAL_ECHO_START;
511
-    SERIAL_ECHO(ver);
512
-    SERIAL_ECHOPAIR(" stored settings retrieved (", i);
513
-    SERIAL_ECHOLNPGM(" bytes)");
514
-  }
526
+    if (eeprom_checksum == stored_checksum) {
527
+      Config_Postprocess();
528
+      SERIAL_ECHO_START;
529
+      SERIAL_ECHO(version);
530
+      SERIAL_ECHOPAIR(" stored settings retrieved (", i);
531
+      SERIAL_ECHOLNPGM(" bytes)");
532
+    }
533
+    else {
534
+      SERIAL_ERROR_START;
535
+      SERIAL_ERRORLNPGM("EEPROM checksum mismatch");
536
+      Config_ResetDefault();
537
+    }
538
+ }
515 539
 
516 540
   #if ENABLED(EEPROM_CHITCHAT)
517 541
     Config_PrintSettings();

Loading…
Cancel
Save