Skip to content

Commit

Permalink
Prevent Watchdog reset writing Creality 4.x EEPROM (MarlinFirmware#20328
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sjasonsmith authored and W4tel-BiDi committed Apr 5, 2021
1 parent 9348b39 commit 6f3d146
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Marlin/src/HAL/STM32F1/eeprom_bl24cxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,19 @@ bool PersistentStore::access_start() { eeprom_init(); return true; }
bool PersistentStore::access_finish() { return true; }

bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
size_t written = 0;

while (size--) {
uint8_t v = *value;
uint8_t * const p = (uint8_t * const)pos;
// EEPROM has only ~100,000 write cycles,
// so only write bytes that have changed!
if (v != eeprom_read_byte(p)) {
eeprom_write_byte(p, v);
delay(2);
if (++written % 128 == 0)
safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
else
delay(2);
if (eeprom_read_byte(p) != v) {
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
return true;
Expand Down

0 comments on commit 6f3d146

Please sign in to comment.