EEPROM Checksum

This commit is contained in:
Scott Lahteine 2016-06-29 18:12:23 -07:00
parent bf216bd78f
commit 5e370006fc

View File

@ -36,88 +36,89 @@
* *
*/ */
#define EEPROM_VERSION "V23" #define EEPROM_VERSION "V24"
/** /**
* V23 EEPROM Layout: * V24 EEPROM Layout:
* *
* 100 Version (char x4) * 100 Version (char x4)
* 104 EEPROM Checksum (uint16_t)
* *
* 104 M92 XYZE planner.axis_steps_per_mm (float x4) * 106 M92 XYZE planner.axis_steps_per_mm (float x4)
* 120 M203 XYZE planner.max_feedrate (float x4) * 122 M203 XYZE planner.max_feedrate (float x4)
* 136 M201 XYZE planner.max_acceleration_mm_per_s2 (uint32_t x4) * 138 M201 XYZE planner.max_acceleration_mm_per_s2 (uint32_t x4)
* 152 M204 P planner.acceleration (float) * 154 M204 P planner.acceleration (float)
* 156 M204 R planner.retract_acceleration (float) * 158 M204 R planner.retract_acceleration (float)
* 160 M204 T planner.travel_acceleration (float) * 162 M204 T planner.travel_acceleration (float)
* 164 M205 S planner.min_feedrate (float) * 166 M205 S planner.min_feedrate (float)
* 168 M205 T planner.min_travel_feedrate (float) * 170 M205 T planner.min_travel_feedrate (float)
* 172 M205 B planner.min_segment_time (ulong) * 174 M205 B planner.min_segment_time (ulong)
* 176 M205 X planner.max_xy_jerk (float) * 178 M205 X planner.max_xy_jerk (float)
* 180 M205 Z planner.max_z_jerk (float) * 182 M205 Z planner.max_z_jerk (float)
* 184 M205 E planner.max_e_jerk (float) * 186 M205 E planner.max_e_jerk (float)
* 188 M206 XYZ home_offset (float x3) * 190 M206 XYZ home_offset (float x3)
* *
* Mesh bed leveling: * Mesh bed leveling:
* 200 M420 S status (uint8) * 202 M420 S status (uint8)
* 201 z_offset (float) * 203 z_offset (float)
* 205 mesh_num_x (uint8 as set in firmware) * 207 mesh_num_x (uint8 as set in firmware)
* 206 mesh_num_y (uint8 as set in firmware) * 208 mesh_num_y (uint8 as set in firmware)
* 207 G29 S3 XYZ z_values[][] (float x9, by default) * 209 G29 S3 XYZ z_values[][] (float x9, by default)
* *
* AUTO BED LEVELING * AUTO BED LEVELING
* 243 M851 zprobe_zoffset (float) * 245 M851 zprobe_zoffset (float)
* *
* DELTA: * DELTA:
* 247 M666 XYZ endstop_adj (float x3) * 249 M666 XYZ endstop_adj (float x3)
* 259 M665 R delta_radius (float) * 261 M665 R delta_radius (float)
* 263 M665 L delta_diagonal_rod (float) * 265 M665 L delta_diagonal_rod (float)
* 267 M665 S delta_segments_per_second (float) * 269 M665 S delta_segments_per_second (float)
* 271 M665 A delta_diagonal_rod_trim_tower_1 (float) * 273 M665 A delta_diagonal_rod_trim_tower_1 (float)
* 275 M665 B delta_diagonal_rod_trim_tower_2 (float) * 277 M665 B delta_diagonal_rod_trim_tower_2 (float)
* 279 M665 C delta_diagonal_rod_trim_tower_3 (float) * 281 M665 C delta_diagonal_rod_trim_tower_3 (float)
* *
* Z_DUAL_ENDSTOPS: * Z_DUAL_ENDSTOPS:
* 283 M666 Z z_endstop_adj (float) * 285 M666 Z z_endstop_adj (float)
* *
* ULTIPANEL: * ULTIPANEL:
* 287 M145 S0 H plaPreheatHotendTemp (int) * 289 M145 S0 H plaPreheatHotendTemp (int)
* 289 M145 S0 B plaPreheatHPBTemp (int) * 291 M145 S0 B plaPreheatHPBTemp (int)
* 291 M145 S0 F plaPreheatFanSpeed (int) * 293 M145 S0 F plaPreheatFanSpeed (int)
* 293 M145 S1 H absPreheatHotendTemp (int) * 295 M145 S1 H absPreheatHotendTemp (int)
* 295 M145 S1 B absPreheatHPBTemp (int) * 297 M145 S1 B absPreheatHPBTemp (int)
* 297 M145 S1 F absPreheatFanSpeed (int) * 299 M145 S1 F absPreheatFanSpeed (int)
* *
* PIDTEMP: * PIDTEMP:
* 299 M301 E0 PIDC Kp[0], Ki[0], Kd[0], Kc[0] (float x4) * 301 M301 E0 PIDC Kp[0], Ki[0], Kd[0], Kc[0] (float x4)
* 315 M301 E1 PIDC Kp[1], Ki[1], Kd[1], Kc[1] (float x4) * 317 M301 E1 PIDC Kp[1], Ki[1], Kd[1], Kc[1] (float x4)
* 331 M301 E2 PIDC Kp[2], Ki[2], Kd[2], Kc[2] (float x4) * 333 M301 E2 PIDC Kp[2], Ki[2], Kd[2], Kc[2] (float x4)
* 347 M301 E3 PIDC Kp[3], Ki[3], Kd[3], Kc[3] (float x4) * 349 M301 E3 PIDC Kp[3], Ki[3], Kd[3], Kc[3] (float x4)
* 363 M301 L lpq_len (int) * 365 M301 L lpq_len (int)
* *
* PIDTEMPBED: * PIDTEMPBED:
* 365 M304 PID thermalManager.bedKp, thermalManager.bedKi, thermalManager.bedKd (float x3) * 367 M304 PID thermalManager.bedKp, thermalManager.bedKi, thermalManager.bedKd (float x3)
* *
* DOGLCD: * DOGLCD:
* 377 M250 C lcd_contrast (int) * 379 M250 C lcd_contrast (int)
* *
* SCARA: * SCARA:
* 379 M365 XYZ axis_scaling (float x3) * 381 M365 XYZ axis_scaling (float x3)
* *
* FWRETRACT: * FWRETRACT:
* 391 M209 S autoretract_enabled (bool) * 393 M209 S autoretract_enabled (bool)
* 392 M207 S retract_length (float) * 394 M207 S retract_length (float)
* 396 M207 W retract_length_swap (float) * 398 M207 W retract_length_swap (float)
* 400 M207 F retract_feedrate_mm_s (float) * 402 M207 F retract_feedrate_mm_s (float)
* 404 M207 Z retract_zlift (float) * 406 M207 Z retract_zlift (float)
* 408 M208 S retract_recover_length (float) * 410 M208 S retract_recover_length (float)
* 412 M208 W retract_recover_length_swap (float) * 414 M208 W retract_recover_length_swap (float)
* 416 M208 F retract_recover_feedrate (float) * 418 M208 F retract_recover_feedrate (float)
* *
* Volumetric Extrusion: * Volumetric Extrusion:
* 420 M200 D volumetric_enabled (bool) * 422 M200 D volumetric_enabled (bool)
* 421 M200 T D filament_size (float x4) (T0..3) * 423 M200 T D filament_size (float x4) (T0..3)
* *
* 437 This Slot is Available! * 439 This Slot is Available!
* *
*/ */
#include "Marlin.h" #include "Marlin.h"
@ -131,6 +132,9 @@
#include "mesh_bed_leveling.h" #include "mesh_bed_leveling.h"
#endif #endif
uint16_t eeprom_checksum;
const char version[4] = EEPROM_VERSION;
void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size) { void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size) {
uint8_t c; uint8_t c;
while (size--) { while (size--) {
@ -140,13 +144,16 @@ void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size) {
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOLNPGM(MSG_ERR_EEPROM_WRITE); SERIAL_ECHOLNPGM(MSG_ERR_EEPROM_WRITE);
} }
eeprom_checksum += c;
pos++; pos++;
value++; value++;
}; };
} }
void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size) { void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size) {
do { do {
*value = eeprom_read_byte((unsigned char*)pos); uint8_t c = eeprom_read_byte((unsigned char*)pos);
*value = c;
eeprom_checksum += c;
pos++; pos++;
value++; value++;
} while (--size); } while (--size);
@ -172,7 +179,12 @@ void Config_StoreSettings() {
float dummy = 0.0f; float dummy = 0.0f;
char ver[4] = "000"; char ver[4] = "000";
int i = EEPROM_OFFSET; int i = EEPROM_OFFSET;
EEPROM_WRITE_VAR(i, ver); // invalidate data first
EEPROM_WRITE_VAR(i, ver); // invalidate data first
i += sizeof(eeprom_checksum); // Skip the checksum slot
eeprom_checksum = 0; // clear before first "real data"
EEPROM_WRITE_VAR(i, planner.axis_steps_per_mm); EEPROM_WRITE_VAR(i, planner.axis_steps_per_mm);
EEPROM_WRITE_VAR(i, planner.max_feedrate); EEPROM_WRITE_VAR(i, planner.max_feedrate);
EEPROM_WRITE_VAR(i, planner.max_acceleration_mm_per_s2); EEPROM_WRITE_VAR(i, planner.max_acceleration_mm_per_s2);
@ -324,9 +336,11 @@ void Config_StoreSettings() {
EEPROM_WRITE_VAR(i, dummy); EEPROM_WRITE_VAR(i, dummy);
} }
char ver2[4] = EEPROM_VERSION; uint16_t final_checksum = eeprom_checksum;
int j = EEPROM_OFFSET; int j = EEPROM_OFFSET;
EEPROM_WRITE_VAR(j, ver2); // validate data EEPROM_WRITE_VAR(j, version);
EEPROM_WRITE_VAR(j, final_checksum);
// Report storage size // Report storage size
SERIAL_ECHO_START; SERIAL_ECHO_START;
@ -342,18 +356,21 @@ void Config_RetrieveSettings() {
int i = EEPROM_OFFSET; int i = EEPROM_OFFSET;
char stored_ver[4]; char stored_ver[4];
char ver[4] = EEPROM_VERSION; uint16_t stored_checksum;
EEPROM_READ_VAR(i, stored_ver); //read stored version EEPROM_READ_VAR(i, stored_ver);
EEPROM_READ_VAR(i, stored_checksum);
// SERIAL_ECHOPAIR("Version: [", ver); // SERIAL_ECHOPAIR("Version: [", ver);
// SERIAL_ECHOPAIR("] Stored version: [", stored_ver); // SERIAL_ECHOPAIR("] Stored version: [", stored_ver);
// SERIAL_ECHOLNPGM("]"); // SERIAL_ECHOLNPGM("]");
if (strncmp(ver, stored_ver, 3) != 0) { if (strncmp(version, stored_ver, 3) != 0) {
Config_ResetDefault(); Config_ResetDefault();
} }
else { else {
float dummy = 0; float dummy = 0;
eeprom_checksum = 0; // clear before reading first "real data"
// version number match // version number match
EEPROM_READ_VAR(i, planner.axis_steps_per_mm); EEPROM_READ_VAR(i, planner.axis_steps_per_mm);
EEPROM_READ_VAR(i, planner.max_feedrate); EEPROM_READ_VAR(i, planner.max_feedrate);
@ -506,12 +523,19 @@ void Config_RetrieveSettings() {
// Call thermalManager.updatePID (similar to when we have processed M301) // Call thermalManager.updatePID (similar to when we have processed M301)
thermalManager.updatePID(); thermalManager.updatePID();
// Report settings retrieved and length if (eeprom_checksum == stored_checksum) {
SERIAL_ECHO_START; Config_Postprocess();
SERIAL_ECHO(ver); SERIAL_ECHO_START;
SERIAL_ECHOPAIR(" stored settings retrieved (", i); SERIAL_ECHO(version);
SERIAL_ECHOLNPGM(" bytes)"); SERIAL_ECHOPAIR(" stored settings retrieved (", i);
} SERIAL_ECHOLNPGM(" bytes)");
}
else {
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("EEPROM checksum mismatch");
Config_ResetDefault();
}
}
#if ENABLED(EEPROM_CHITCHAT) #if ENABLED(EEPROM_CHITCHAT)
Config_PrintSettings(); Config_PrintSettings();