Browse Source

Better EEPROM read/write error handling

pull/1/head
Scott Lahteine 8 years ago
parent
commit
492b68f8e3
  1. 41
      Marlin/configuration_store.cpp

41
Marlin/configuration_store.cpp

@ -188,10 +188,11 @@ void Config_Postprocess() {
value++; value++;
}; };
} }
bool eeprom_read_error;
void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size) { void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size) {
do { do {
uint8_t c = eeprom_read_byte((unsigned char*)pos); uint8_t c = eeprom_read_byte((unsigned char*)pos);
*value = c; if (!eeprom_read_error) *value = c;
eeprom_checksum += c; eeprom_checksum += c;
pos++; pos++;
value++; value++;
@ -203,6 +204,7 @@ void Config_Postprocess() {
#define EEPROM_SKIP(VAR) eeprom_index += sizeof(VAR) #define EEPROM_SKIP(VAR) eeprom_index += sizeof(VAR)
#define EEPROM_WRITE(VAR) _EEPROM_writeData(eeprom_index, (uint8_t*)&VAR, sizeof(VAR)) #define EEPROM_WRITE(VAR) _EEPROM_writeData(eeprom_index, (uint8_t*)&VAR, sizeof(VAR))
#define EEPROM_READ(VAR) _EEPROM_readData(eeprom_index, (uint8_t*)&VAR, sizeof(VAR)) #define EEPROM_READ(VAR) _EEPROM_readData(eeprom_index, (uint8_t*)&VAR, sizeof(VAR))
#define EEPROM_ASSERT(TST,ERR) if () do{ SERIAL_ERROR_START; SERIAL_ERRORLNPGM(ERR); eeprom_read_error |= true; }while(0)
/** /**
* M500 - Store Configuration * M500 - Store Configuration
@ -371,17 +373,21 @@ void Config_Postprocess() {
EEPROM_WRITE(dummy); EEPROM_WRITE(dummy);
} }
uint16_t final_checksum = eeprom_checksum, if (!eeprom_write_error) {
eeprom_size = eeprom_index;
eeprom_index = EEPROM_OFFSET; uint16_t final_checksum = eeprom_checksum,
EEPROM_WRITE(version); eeprom_size = eeprom_index;
EEPROM_WRITE(final_checksum);
// Report storage size // Write the EEPROM header
SERIAL_ECHO_START; eeprom_index = EEPROM_OFFSET;
SERIAL_ECHOPAIR("Settings Stored (", eeprom_size); EEPROM_WRITE(version);
SERIAL_ECHOLNPGM(" bytes)"); EEPROM_WRITE(final_checksum);
// Report storage size
SERIAL_ECHO_START;
SERIAL_ECHOPAIR("Settings Stored (", eeprom_size);
SERIAL_ECHOLNPGM(" bytes)");
}
} }
/** /**
@ -390,6 +396,7 @@ void Config_Postprocess() {
void Config_RetrieveSettings() { void Config_RetrieveSettings() {
EEPROM_START(); EEPROM_START();
eeprom_read_error = false; // If set EEPROM_READ won't write into RAM
char stored_ver[4]; char stored_ver[4];
EEPROM_READ(stored_ver); EEPROM_READ(stored_ver);
@ -568,11 +575,15 @@ void Config_Postprocess() {
} }
if (eeprom_checksum == stored_checksum) { if (eeprom_checksum == stored_checksum) {
Config_Postprocess(); if (eeprom_read_error)
SERIAL_ECHO_START; Config_ResetDefault();
SERIAL_ECHO(version); else {
SERIAL_ECHOPAIR(" stored settings retrieved (", eeprom_index); Config_Postprocess();
SERIAL_ECHOLNPGM(" bytes)"); SERIAL_ECHO_START;
SERIAL_ECHO(version);
SERIAL_ECHOPAIR(" stored settings retrieved (", eeprom_index);
SERIAL_ECHOLNPGM(" bytes)");
}
} }
else { else {
SERIAL_ERROR_START; SERIAL_ERROR_START;

Loading…
Cancel
Save