Browse Source

Merge pull request #6772 from bgort/meshstor

Fix broken EEPROM save/load
pull/1/head
bgort 8 years ago
committed by GitHub
parent
commit
aad1acc418
  1. 14
      Marlin/configuration_store.cpp
  2. 4
      Marlin/configuration_store.h
  3. 2
      Marlin/utility.cpp

14
Marlin/configuration_store.cpp

@ -625,15 +625,18 @@ void MarlinSettings::postprocess() {
if (!eeprom_error) { if (!eeprom_error) {
const int eeprom_size = eeprom_index; const int eeprom_size = eeprom_index;
const uint16_t tcrc = working_crc;
// Write the EEPROM header // Write the EEPROM header
eeprom_index = EEPROM_OFFSET; eeprom_index = EEPROM_OFFSET;
EEPROM_WRITE(version); EEPROM_WRITE(version);
EEPROM_WRITE(working_crc); EEPROM_WRITE(tcrc);
// Report storage size // Report storage size
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOPAIR("Settings Stored (", eeprom_size - (EEPROM_OFFSET)); SERIAL_ECHOPAIR("Settings Stored (", eeprom_size - (EEPROM_OFFSET));
SERIAL_ECHOPAIR(" bytes; crc ", working_crc); SERIAL_ECHOPAIR(" bytes; crc ", tcrc);
SERIAL_ECHOLNPGM(")"); SERIAL_ECHOLNPGM(")");
} }
@ -982,11 +985,11 @@ void MarlinSettings::postprocess() {
} }
else { else {
SERIAL_ERROR_START; SERIAL_ERROR_START;
SERIAL_ERRORPGM("EEPROM checksum mismatch - (stored CRC)"); SERIAL_ERRORPGM("EEPROM CRC mismatch - (stored) ");
SERIAL_ERROR(stored_crc); SERIAL_ERROR(stored_crc);
SERIAL_ERRORPGM(" != "); SERIAL_ERRORPGM(" != ");
SERIAL_ERROR(working_crc); SERIAL_ERROR(working_crc);
SERIAL_ERRORLNPGM(" (calculated CRC)!"); SERIAL_ERRORLNPGM(" (calculated)!");
reset(); reset();
} }
@ -1027,7 +1030,6 @@ void MarlinSettings::postprocess() {
return !eeprom_error; return !eeprom_error;
} }
#if ENABLED(AUTO_BED_LEVELING_UBL) #if ENABLED(AUTO_BED_LEVELING_UBL)
void ubl_invalid_slot(const int s) { void ubl_invalid_slot(const int s) {
@ -1051,7 +1053,7 @@ void MarlinSettings::postprocess() {
if (!WITHIN(slot, 0, a - 1)) { if (!WITHIN(slot, 0, a - 1)) {
ubl_invalid_slot(a); ubl_invalid_slot(a);
SERIAL_PROTOCOLPAIR("E2END=", E2END); SERIAL_PROTOCOLPAIR("E2END=", E2END);
SERIAL_PROTOCOLPAIR(" meshes_end=", (int)meshes_end); SERIAL_PROTOCOLPAIR(" meshes_end=", meshes_end);
SERIAL_PROTOCOLLNPAIR(" slot=", slot); SERIAL_PROTOCOLLNPAIR(" slot=", slot);
SERIAL_EOL; SERIAL_EOL;
return; return;

4
Marlin/configuration_store.h

@ -67,8 +67,8 @@ class MarlinSettings {
#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
static int meshes_begin; static int meshes_begin;
const static int mat_end = E2END; // Mesh allocation table; this may not end up being necessary const static int meshes_end = E2END - 128; // 128 is a placeholder for the size of the MAT; the MAT will always
const static int meshes_end = mat_end - 128; // 128 is a placeholder for the size of the MAT // live at the very end of the eeprom
#endif #endif

2
Marlin/utility.cpp

@ -38,7 +38,7 @@ void safe_delay(millis_t ms) {
void crc16(uint16_t *crc, const void * const data, uint16_t cnt) { void crc16(uint16_t *crc, const void * const data, uint16_t cnt) {
uint8_t *ptr = (uint8_t *)data; uint8_t *ptr = (uint8_t *)data;
while (cnt-- > 0) { while (cnt--) {
*crc = (uint16_t)(*crc ^ (uint16_t)(((uint16_t)*ptr++) << 8)); *crc = (uint16_t)(*crc ^ (uint16_t)(((uint16_t)*ptr++) << 8));
for (uint8_t x = 0; x < 8; x++) for (uint8_t x = 0; x < 8; x++)
*crc = (uint16_t)((*crc & 0x8000) ? ((uint16_t)(*crc << 1) ^ 0x1021) : (*crc << 1)); *crc = (uint16_t)((*crc & 0x8000) ? ((uint16_t)(*crc << 1) ^ 0x1021) : (*crc << 1));

Loading…
Cancel
Save