diff --git a/Firmware/ConfigurationStore.cpp b/Firmware/ConfigurationStore.cpp index 264486b7..4984c152 100644 --- a/Firmware/ConfigurationStore.cpp +++ b/Firmware/ConfigurationStore.cpp @@ -57,13 +57,14 @@ void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size, char* name) //====================================================================================== #define EEPROM_OFFSET 20 +#define EEPROM_M500_SIZE 188 //bytes // IMPORTANT: Whenever there are changes made to the variables stored in EEPROM -// in the functions below, also increment the version number. This makes sure that +// in the functions below, also increment the version number and update EEPROM_M500_SIZE. This makes sure that // the default values are used whenever there is a change to the data, to prevent // wrong data being written to the variables. // ALSO: always make sure the variables in the Store and retrieve sections are in the same order. -#define EEPROM_VERSION "V2" +#define EEPROM_VERSION "V3" #ifdef EEPROM_SETTINGS void Config_StoreSettings(uint16_t offset) @@ -142,12 +143,17 @@ void Config_StoreSettings(uint16_t offset) EEPROM_WRITE_VAR(i,max_feedrate_silent); EEPROM_WRITE_VAR(i,max_acceleration_units_per_sq_second_silent); - - char ver2[4]=EEPROM_VERSION; - i=offset; - EEPROM_WRITE_VAR(i,ver2); // validate data - SERIAL_ECHO_START; - SERIAL_ECHOLNPGM("Settings Stored"); + if (EEPROM_M500_SIZE + EEPROM_OFFSET == i) { + char ver2[4] = EEPROM_VERSION; + i = offset; + EEPROM_WRITE_VAR(i, ver2); // validate data + SERIAL_ECHO_START; + SERIAL_ECHOLNPGM("Settings Stored"); + } + else { //size of eeprom M500 section probably changed by mistake and data are not valid; do not validate data by storing eeprom version + //M500 EEPROM section will be erased on next printer reboot and default vaules will be used + puts_P(PSTR("Data stored to EEPROM not valid.")); + } } #endif //EEPROM_SETTINGS diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 2544dce6..5ca589fa 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1642,7 +1642,7 @@ void setup() if (!previous_settings_retrieved) { lcd_show_fullscreen_message_and_wait_P(_i("Old settings found. Default PID, Esteps etc. will be set.")); //if EEPROM version or printer type was changed, inform user that default setting were loaded////MSG_DEFAULT_SETTINGS_LOADED c=20 r=4 - erase_eeprom_section(EEPROM_OFFSET, 156); //erase M500 part of eeprom + erase_eeprom_section(EEPROM_OFFSET, EEPROM_M500_SIZE); //erase M500 part of eeprom } if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) == 1) { lcd_wizard(0);