Add MarlinSettings::validate()

2.0.x
Scott Lahteine 7 years ago
parent 878f54c27b
commit 51e0f2bee3

@ -38,10 +38,10 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
return false; return false;
} }
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) { bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
do { do {
uint8_t c = eeprom_read_byte((unsigned char*)pos); uint8_t c = eeprom_read_byte((unsigned char*)pos);
*value = c; if (writing) *value = c;
crc16(crc, &c, 1); crc16(crc, &c, 1);
pos++; pos++;
value++; value++;

@ -43,10 +43,10 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
return false; return false;
} }
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) { bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
do { do {
uint8_t c = eeprom_read_byte((unsigned char*)pos); uint8_t c = eeprom_read_byte((unsigned char*)pos);
*value = c; if (writing) *value = c;
crc16(crc, &c, 1); crc16(crc, &c, 1);
pos++; pos++;
value++; value++;

@ -128,7 +128,7 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
return (bytes_written != size); // return true for any error return (bytes_written != size); // return true for any error
} }
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) { bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
UINT bytes_read = 0; UINT bytes_read = 0;
FRESULT s; FRESULT s;
s = f_lseek(&eeprom_file, pos); s = f_lseek(&eeprom_file, pos);
@ -140,7 +140,15 @@ bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
SERIAL_PROTOCOLLNPAIR(" f_lseek()=", (int)s); SERIAL_PROTOCOLLNPAIR(" f_lseek()=", (int)s);
return true; return true;
} }
if (writing) {
s = f_read(&eeprom_file, (void *)value, size, &bytes_read); s = f_read(&eeprom_file, (void *)value, size, &bytes_read);
crc16(crc, value, size);
}
else {
uint8_t temp[size];
s = f_read(&eeprom_file, (void *)temp, size, &bytes_read);
crc16(crc, temp, size);
}
if (s) { if (s) {
SERIAL_PROTOCOLPAIR(" read_data(", pos); // This extra chit-chat goes away soon. But it is helpful SERIAL_PROTOCOLPAIR(" read_data(", pos); // This extra chit-chat goes away soon. But it is helpful
SERIAL_PROTOCOLPAIR(",", (int)value); // right now to see errors that are happening in the SERIAL_PROTOCOLPAIR(",", (int)value); // right now to see errors that are happening in the
@ -151,7 +159,6 @@ bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
SERIAL_PROTOCOLLNPAIR("\n bytes_read=", bytes_read); SERIAL_PROTOCOLLNPAIR("\n bytes_read=", bytes_read);
return true; return true;
} }
crc16(crc, value, size);
pos = pos + size; pos = pos + size;
return bytes_read != size; // return true for any error return bytes_read != size; // return true for any error
} }

@ -93,13 +93,13 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
return true; return true;
} }
void read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) { void read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
for (uint16_t i = 0; i < size; i++) { for (uint16_t i = 0; i < size; i++) {
byte* accessPoint = (byte*)(pageBase + pos + i); byte* accessPoint = (byte*)(pageBase + pos + i);
value[i] = *accessPoint; uint8_t c = *accessPoint;
if (writing) value[i] = c;
crc16(crc, &c, 1);
} }
crc16(crc, value, size);
pos += ((size + 1) & ~1); pos += ((size + 1) & ~1);
} }

@ -62,7 +62,6 @@ bool access_start() {
return true; return true;
} }
bool access_finish(){ bool access_finish(){
if (!card.cardOK) return false; if (!card.cardOK) return false;
int16_t bytes_written = 0; int16_t bytes_written = 0;
@ -81,11 +80,12 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
return false; return false;
} }
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) { bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
value[i] = HAL_STM32F1_eeprom_content [pos + i]; uint8_t c = HAL_STM32F1_eeprom_content[pos + i];
if (writing) value[i] = c`;
crc16(crc, &c, 1);
} }
crc16(crc, value, size);
pos += size; pos += size;
return false; return false;
} }

@ -38,10 +38,10 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
return false; return false;
} }
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) { bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
do { do {
uint8_t c = eeprom_read_byte((unsigned char*)pos); uint8_t c = eeprom_read_byte((unsigned char*)pos);
*value = c; if (writing) *value = c;
crc16(crc, &c, 1); crc16(crc, &c, 1);
pos++; pos++;
value++; value++;

@ -10,7 +10,7 @@ namespace PersistentStore {
bool access_start(); bool access_start();
bool access_finish(); bool access_finish();
bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc); bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc);
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc); bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing=true);
} // PersistentStore } // PersistentStore
} // HAL } // HAL

@ -55,3 +55,15 @@ void GcodeSuite::M502() {
} }
#endif // !DISABLE_M503 #endif // !DISABLE_M503
#if ENABLED(EEPROM_SETTINGS)
/**
* M504: Validate EEPROM Contents
*/
void GcodeSuite::M504() {
if (settings.validate()) {
SERIAL_ECHO_START();
SERIAL_ECHOLNPGM("EEPROM OK");
}
}
#endif

@ -610,6 +610,9 @@ void GcodeSuite::process_parsed_command() {
#if DISABLED(DISABLE_M503) #if DISABLED(DISABLE_M503)
case 503: M503(); break; // M503: print settings currently in memory case 503: M503(); break; // M503: print settings currently in memory
#endif #endif
#if ENABLED(EEPROM_SETTINGS)
case 504: M504(); break; // M504: Validate EEPROM contents
#endif
#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
case 540: M540(); break; // M540: Set abort on endstop hit for SD printing case 540: M540(); break; // M540: Set abort on endstop hit for SD printing

@ -681,6 +681,9 @@ private:
#if DISABLED(DISABLE_M503) #if DISABLED(DISABLE_M503)
static void M503(); static void M503();
#endif #endif
#if ENABLED(EEPROM_SETTINGS)
static void M504();
#endif
#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
static void M540(); static void M540();

@ -289,12 +289,13 @@ void MarlinSettings::postprocess() {
#define EEPROM_FINISH() HAL::PersistentStore::access_finish() #define EEPROM_FINISH() HAL::PersistentStore::access_finish()
#define EEPROM_SKIP(VAR) eeprom_index += sizeof(VAR) #define EEPROM_SKIP(VAR) eeprom_index += sizeof(VAR)
#define EEPROM_WRITE(VAR) HAL::PersistentStore::write_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc) #define EEPROM_WRITE(VAR) HAL::PersistentStore::write_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
#define EEPROM_READ(VAR) HAL::PersistentStore::read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc) #define EEPROM_READ(VAR) HAL::PersistentStore::read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc, !validating)
#define EEPROM_READ_ALWAYS(VAR) HAL::PersistentStore::read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
#define EEPROM_ASSERT(TST,ERR) if (!(TST)) do{ SERIAL_ERROR_START(); SERIAL_ERRORLNPGM(ERR); eeprom_read_error = true; }while(0) #define EEPROM_ASSERT(TST,ERR) if (!(TST)) do{ SERIAL_ERROR_START(); SERIAL_ERRORLNPGM(ERR); eeprom_read_error = true; }while(0)
const char version[4] = EEPROM_VERSION; const char version[4] = EEPROM_VERSION;
bool MarlinSettings::eeprom_error; bool MarlinSettings::eeprom_error, MarlinSettings::validating;
#if ENABLED(AUTO_BED_LEVELING_UBL) #if ENABLED(AUTO_BED_LEVELING_UBL)
int16_t MarlinSettings::meshes_begin; int16_t MarlinSettings::meshes_begin;
@ -718,6 +719,9 @@ void MarlinSettings::postprocess() {
for (uint8_t q = MAX_EXTRUDERS * 2; q--;) EEPROM_WRITE(dummy); for (uint8_t q = MAX_EXTRUDERS * 2; q--;) EEPROM_WRITE(dummy);
#endif #endif
//
// Validate CRC
//
if (!eeprom_error) { if (!eeprom_error) {
#if ENABLED(EEPROM_CHITCHAT) #if ENABLED(EEPROM_CHITCHAT)
const int eeprom_size = eeprom_index; const int eeprom_size = eeprom_index;
@ -741,6 +745,9 @@ void MarlinSettings::postprocess() {
} }
EEPROM_FINISH(); EEPROM_FINISH();
//
// UBL Mesh
//
#if ENABLED(UBL_SAVE_ACTIVE_ON_M500) #if ENABLED(UBL_SAVE_ACTIVE_ON_M500)
if (ubl.storage_slot >= 0) if (ubl.storage_slot >= 0)
store_mesh(ubl.storage_slot); store_mesh(ubl.storage_slot);
@ -752,16 +759,16 @@ void MarlinSettings::postprocess() {
/** /**
* M501 - Retrieve Configuration * M501 - Retrieve Configuration
*/ */
bool MarlinSettings::load() { bool MarlinSettings::_load() {
uint16_t working_crc = 0; uint16_t working_crc = 0;
EEPROM_START(); EEPROM_START();
char stored_ver[4]; char stored_ver[4];
EEPROM_READ(stored_ver); EEPROM_READ_ALWAYS(stored_ver);
uint16_t stored_crc; uint16_t stored_crc;
EEPROM_READ(stored_crc); EEPROM_READ_ALWAYS(stored_crc);
// Version has to match or defaults are used // Version has to match or defaults are used
if (strncmp(version, stored_ver, 3) != 0) { if (strncmp(version, stored_ver, 3) != 0) {
@ -775,7 +782,8 @@ void MarlinSettings::postprocess() {
SERIAL_ECHOPAIR("(EEPROM=", stored_ver); SERIAL_ECHOPAIR("(EEPROM=", stored_ver);
SERIAL_ECHOLNPGM(" Marlin=" EEPROM_VERSION ")"); SERIAL_ECHOLNPGM(" Marlin=" EEPROM_VERSION ")");
#endif #endif
reset(); if (!validating) reset();
eeprom_error = true;
} }
else { else {
float dummy = 0; float dummy = 0;
@ -787,7 +795,7 @@ void MarlinSettings::postprocess() {
// Number of esteppers may change // Number of esteppers may change
uint8_t esteppers; uint8_t esteppers;
EEPROM_READ(esteppers); EEPROM_READ_ALWAYS(esteppers);
// //
// Planner Motion // Planner Motion
@ -802,7 +810,7 @@ void MarlinSettings::postprocess() {
EEPROM_READ(tmp1); EEPROM_READ(tmp1);
EEPROM_READ(tmp2); EEPROM_READ(tmp2);
EEPROM_READ(tmp3); EEPROM_READ(tmp3);
LOOP_XYZE_N(i) { if (!validating) LOOP_XYZE_N(i) {
planner.axis_steps_per_mm[i] = i < XYZ + esteppers ? tmp1[i] : def1[i < COUNT(def1) ? i : COUNT(def1) - 1]; planner.axis_steps_per_mm[i] = i < XYZ + esteppers ? tmp1[i] : def1[i < COUNT(def1) ? i : COUNT(def1) - 1];
planner.max_feedrate_mm_s[i] = i < XYZ + esteppers ? tmp2[i] : def2[i < COUNT(def2) ? i : COUNT(def2) - 1]; planner.max_feedrate_mm_s[i] = i < XYZ + esteppers ? tmp2[i] : def2[i < COUNT(def2) ? i : COUNT(def2) - 1];
planner.max_acceleration_mm_per_s2[i] = i < XYZ + esteppers ? tmp3[i] : def3[i < COUNT(def3) ? i : COUNT(def3) - 1]; planner.max_acceleration_mm_per_s2[i] = i < XYZ + esteppers ? tmp3[i] : def3[i < COUNT(def3) ? i : COUNT(def3) - 1];
@ -851,21 +859,23 @@ void MarlinSettings::postprocess() {
bool leveling_is_on; bool leveling_is_on;
uint8_t mesh_num_x, mesh_num_y; uint8_t mesh_num_x, mesh_num_y;
EEPROM_READ(leveling_is_on); EEPROM_READ_ALWAYS(leveling_is_on);
EEPROM_READ(dummy); EEPROM_READ(dummy);
EEPROM_READ(mesh_num_x); EEPROM_READ_ALWAYS(mesh_num_x);
EEPROM_READ(mesh_num_y); EEPROM_READ_ALWAYS(mesh_num_y);
#if ENABLED(MESH_BED_LEVELING) #if ENABLED(MESH_BED_LEVELING)
if (!validating) {
mbl.has_mesh = leveling_is_on; mbl.has_mesh = leveling_is_on;
mbl.z_offset = dummy; mbl.z_offset = dummy;
}
if (mesh_num_x == GRID_MAX_POINTS_X && mesh_num_y == GRID_MAX_POINTS_Y) { if (mesh_num_x == GRID_MAX_POINTS_X && mesh_num_y == GRID_MAX_POINTS_Y) {
// EEPROM data fits the current mesh // EEPROM data fits the current mesh
EEPROM_READ(mbl.z_values); EEPROM_READ(mbl.z_values);
} }
else { else {
// EEPROM data is stale // EEPROM data is stale
mbl.reset(); if (!validating) mbl.reset();
for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummy); for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummy);
} }
#else #else
@ -893,11 +903,11 @@ void MarlinSettings::postprocess() {
// //
uint8_t grid_max_x, grid_max_y; uint8_t grid_max_x, grid_max_y;
EEPROM_READ(grid_max_x); // 1 byte EEPROM_READ_ALWAYS(grid_max_x); // 1 byte
EEPROM_READ(grid_max_y); // 1 byte EEPROM_READ_ALWAYS(grid_max_y); // 1 byte
#if ENABLED(AUTO_BED_LEVELING_BILINEAR) #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
if (grid_max_x == GRID_MAX_POINTS_X && grid_max_y == GRID_MAX_POINTS_Y) { if (grid_max_x == GRID_MAX_POINTS_X && grid_max_y == GRID_MAX_POINTS_Y) {
set_bed_leveling_enabled(false); if (!validating) set_bed_leveling_enabled(false);
EEPROM_READ(bilinear_grid_spacing); // 2 ints EEPROM_READ(bilinear_grid_spacing); // 2 ints
EEPROM_READ(bilinear_start); // 2 ints EEPROM_READ(bilinear_start); // 2 ints
EEPROM_READ(z_values); // 9 to 256 floats EEPROM_READ(z_values); // 9 to 256 floats
@ -989,7 +999,7 @@ void MarlinSettings::postprocess() {
EEPROM_READ(dummy); // Kp EEPROM_READ(dummy); // Kp
if (e < HOTENDS && dummy != DUMMY_PID_VALUE) { if (e < HOTENDS && dummy != DUMMY_PID_VALUE) {
// do not need to scale PID values as the values in EEPROM are already scaled // do not need to scale PID values as the values in EEPROM are already scaled
PID_PARAM(Kp, e) = dummy; if (!validating) PID_PARAM(Kp, e) = dummy;
EEPROM_READ(PID_PARAM(Ki, e)); EEPROM_READ(PID_PARAM(Ki, e));
EEPROM_READ(PID_PARAM(Kd, e)); EEPROM_READ(PID_PARAM(Kd, e));
#if ENABLED(PID_EXTRUSION_SCALING) #if ENABLED(PID_EXTRUSION_SCALING)
@ -1023,7 +1033,7 @@ void MarlinSettings::postprocess() {
#if ENABLED(PIDTEMPBED) #if ENABLED(PIDTEMPBED)
EEPROM_READ(dummy); // bedKp EEPROM_READ(dummy); // bedKp
if (dummy != DUMMY_PID_VALUE) { if (dummy != DUMMY_PID_VALUE) {
thermalManager.bedKp = dummy; if (!validating) thermalManager.bedKp = dummy;
EEPROM_READ(thermalManager.bedKi); EEPROM_READ(thermalManager.bedKi);
EEPROM_READ(thermalManager.bedKd); EEPROM_READ(thermalManager.bedKd);
} }
@ -1068,7 +1078,8 @@ void MarlinSettings::postprocess() {
for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) { for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
EEPROM_READ(dummy); EEPROM_READ(dummy);
if (q < COUNT(planner.filament_size)) planner.filament_size[q] = dummy; if (!validating && q < COUNT(planner.filament_size))
planner.filament_size[q] = dummy;
} }
#else #else
@ -1081,54 +1092,47 @@ void MarlinSettings::postprocess() {
// //
// TMC2130 Stepper Current // TMC2130 Stepper Current
// //
uint16_t val;
#if HAS_TRINAMIC #if HAS_TRINAMIC
#define SET_CURR(N,Q) stepper##Q.setCurrent(val[N], R_SENSE, HOLD_MULTIPLIER)
uint16_t val[11];
EEPROM_READ(val); EEPROM_READ(val);
if (!validating) {
#if X_IS_TRINAMIC #if X_IS_TRINAMIC
stepperX.setCurrent(val, R_SENSE, HOLD_MULTIPLIER); SET_CURR(0, X);
#endif #endif
EEPROM_READ(val);
#if Y_IS_TRINAMIC #if Y_IS_TRINAMIC
stepperY.setCurrent(val, R_SENSE, HOLD_MULTIPLIER); SET_CURR(1, Y);
#endif #endif
EEPROM_READ(val);
#if Z_IS_TRINAMIC #if Z_IS_TRINAMIC
stepperZ.setCurrent(val, R_SENSE, HOLD_MULTIPLIER); SET_CURR(2, Z);
#endif #endif
EEPROM_READ(val);
#if X2_IS_TRINAMIC #if X2_IS_TRINAMIC
stepperX2.setCurrent(val, R_SENSE, HOLD_MULTIPLIER); SET_CURR(3, X2);
#endif #endif
EEPROM_READ(val);
#if Y2_IS_TRINAMIC #if Y2_IS_TRINAMIC
stepperY2.setCurrent(val, R_SENSE, HOLD_MULTIPLIER); SET_CURR(4, Y2);
#endif #endif
EEPROM_READ(val);
#if Z2_IS_TRINAMIC #if Z2_IS_TRINAMIC
stepperZ2.setCurrent(val, R_SENSE, HOLD_MULTIPLIER); SET_CURR(5, Z2);
#endif #endif
EEPROM_READ(val);
#if E0_IS_TRINAMIC #if E0_IS_TRINAMIC
stepperE0.setCurrent(val, R_SENSE, HOLD_MULTIPLIER); SET_CURR(6, E0);
#endif #endif
EEPROM_READ(val);
#if E1_IS_TRINAMIC #if E1_IS_TRINAMIC
stepperE1.setCurrent(val, R_SENSE, HOLD_MULTIPLIER); SET_CURR(7, E1);
#endif #endif
EEPROM_READ(val);
#if E2_IS_TRINAMIC #if E2_IS_TRINAMIC
stepperE2.setCurrent(val, R_SENSE, HOLD_MULTIPLIER); SET_CURR(8, E2);
#endif #endif
EEPROM_READ(val);
#if E3_IS_TRINAMIC #if E3_IS_TRINAMIC
stepperE3.setCurrent(val, R_SENSE, HOLD_MULTIPLIER); SET_CURR(9, E3);
#endif #endif
EEPROM_READ(val);
#if E4_IS_TRINAMIC #if E4_IS_TRINAMIC
stepperE4.setCurrent(val, R_SENSE, HOLD_MULTIPLIER); SET_CURR(10, E4);
#endif #endif
}
#else #else
uint16_t val;
for (uint8_t q=11; q--;) EEPROM_READ(val); for (uint8_t q=11; q--;) EEPROM_READ(val);
#endif #endif
@ -1140,19 +1144,23 @@ void MarlinSettings::postprocess() {
int16_t thrs; int16_t thrs;
#if ENABLED(SENSORLESS_HOMING) #if ENABLED(SENSORLESS_HOMING)
EEPROM_READ(thrs); EEPROM_READ(thrs);
if (!validating) {
#if ENABLED(X_IS_TMC2130) #if ENABLED(X_IS_TMC2130)
stepperX.sgt(thrs); stepperX.sgt(thrs);
#endif #endif
#if ENABLED(X2_IS_TMC2130) #if ENABLED(X2_IS_TMC2130)
stepperX2.sgt(thrs); stepperX2.sgt(thrs);
#endif #endif
}
EEPROM_READ(thrs); EEPROM_READ(thrs);
if (!validating) {
#if ENABLED(Y_IS_TMC2130) #if ENABLED(Y_IS_TMC2130)
stepperY.sgt(thrs); stepperY.sgt(thrs);
#endif #endif
#if ENABLED(Y2_IS_TMC2130) #if ENABLED(Y2_IS_TMC2130)
stepperY2.sgt(thrs); stepperY2.sgt(thrs);
#endif #endif
}
#else #else
for (uint8_t q = 0; q < 2; q++) EEPROM_READ(thrs); for (uint8_t q = 0; q < 2; q++) EEPROM_READ(thrs);
#endif #endif
@ -1185,7 +1193,7 @@ void MarlinSettings::postprocess() {
// //
#if ENABLED(CNC_COORDINATE_SYSTEMS) #if ENABLED(CNC_COORDINATE_SYSTEMS)
(void)gcode.select_coordinate_system(-1); // Go back to machine space if (!validating) (void)gcode.select_coordinate_system(-1); // Go back to machine space
EEPROM_READ(gcode.coordinate_system); // 27 floats EEPROM_READ(gcode.coordinate_system); // 27 floats
#else #else
for (uint8_t q = 27; q--;) EEPROM_READ(dummy); for (uint8_t q = 27; q--;) EEPROM_READ(dummy);
@ -1215,17 +1223,18 @@ void MarlinSettings::postprocess() {
#if ENABLED(ADVANCED_PAUSE_FEATURE) #if ENABLED(ADVANCED_PAUSE_FEATURE)
for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) { for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
EEPROM_READ(dummy); EEPROM_READ(dummy);
if (q < COUNT(filament_change_unload_length)) filament_change_unload_length[q] = dummy; if (!validating && q < COUNT(filament_change_unload_length)) filament_change_unload_length[q] = dummy;
} }
for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) { for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
EEPROM_READ(dummy); EEPROM_READ(dummy);
if (q < COUNT(filament_change_load_length)) filament_change_load_length[q] = dummy; if (!validating && q < COUNT(filament_change_load_length)) filament_change_load_length[q] = dummy;
} }
#else #else
for (uint8_t q = MAX_EXTRUDERS * 2; q--;) EEPROM_READ(dummy); for (uint8_t q = MAX_EXTRUDERS * 2; q--;) EEPROM_READ(dummy);
#endif #endif
if (working_crc == stored_crc) { if (working_crc == stored_crc) {
if (!validating) {
postprocess(); postprocess();
#if ENABLED(EEPROM_CHITCHAT) #if ENABLED(EEPROM_CHITCHAT)
SERIAL_ECHO_START(); SERIAL_ECHO_START();
@ -1235,6 +1244,7 @@ void MarlinSettings::postprocess() {
SERIAL_ECHOLNPGM(")"); SERIAL_ECHOLNPGM(")");
#endif #endif
} }
}
else { else {
#if ENABLED(EEPROM_CHITCHAT) #if ENABLED(EEPROM_CHITCHAT)
SERIAL_ERROR_START(); SERIAL_ERROR_START();
@ -1253,6 +1263,7 @@ void MarlinSettings::postprocess() {
// disrupting the mesh data // disrupting the mesh data
ubl.report_state(); ubl.report_state();
if (!validating) {
if (!ubl.sanity_check()) { if (!ubl.sanity_check()) {
SERIAL_EOL(); SERIAL_EOL();
#if ENABLED(EEPROM_CHITCHAT) #if ENABLED(EEPROM_CHITCHAT)
@ -1261,6 +1272,7 @@ void MarlinSettings::postprocess() {
#endif #endif
} }
else { else {
eeprom_error = true;
#if ENABLED(EEPROM_CHITCHAT) #if ENABLED(EEPROM_CHITCHAT)
SERIAL_PROTOCOLPGM("?Can't enable "); SERIAL_PROTOCOLPGM("?Can't enable ");
ubl.echo_name(); ubl.echo_name();
@ -1282,17 +1294,31 @@ void MarlinSettings::postprocess() {
SERIAL_ECHOLNPGM("UBL System reset()"); SERIAL_ECHOLNPGM("UBL System reset()");
#endif #endif
} }
}
#endif #endif
} }
#if ENABLED(EEPROM_CHITCHAT) && DISABLED(DISABLE_M503) #if ENABLED(EEPROM_CHITCHAT) && DISABLED(DISABLE_M503)
report(); if (!validating) report();
#endif #endif
EEPROM_FINISH(); EEPROM_FINISH();
return !eeprom_error; return !eeprom_error;
} }
bool MarlinSettings::validate() {
validating = true;
const bool success = _load();
validating = false;
return success;
}
bool MarlinSettings::load() {
if (validate()) return _load();
reset();
return true;
}
#if ENABLED(AUTO_BED_LEVELING_UBL) #if ENABLED(AUTO_BED_LEVELING_UBL)
#if ENABLED(EEPROM_CHITCHAT) #if ENABLED(EEPROM_CHITCHAT)

@ -30,7 +30,7 @@ class MarlinSettings {
MarlinSettings() { } MarlinSettings() { }
static void reset(); static void reset();
static bool save(); static bool save(); // Return 'true' if data was saved
FORCE_INLINE static bool init_eeprom() { FORCE_INLINE static bool init_eeprom() {
bool success = true; bool success = true;
@ -48,7 +48,8 @@ class MarlinSettings {
} }
#if ENABLED(EEPROM_SETTINGS) #if ENABLED(EEPROM_SETTINGS)
static bool load(); static bool load(); // Return 'true' if data was loaded ok
static bool validate(); // Return 'true' if EEPROM data is ok
#if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
// That can store is enabled // That can store is enabled
@ -77,7 +78,8 @@ class MarlinSettings {
static void postprocess(); static void postprocess();
#if ENABLED(EEPROM_SETTINGS) #if ENABLED(EEPROM_SETTINGS)
static bool eeprom_error;
static bool eeprom_error, validating;
#if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
// That can store is enabled // That can store is enabled
@ -87,6 +89,7 @@ class MarlinSettings {
#endif #endif
static bool _load();
#endif #endif
}; };

Loading…
Cancel
Save