From f929123a7b10e8bfcaafdc09f7a3368cb2e41bdb Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Mon, 30 Nov 2020 22:25:44 -0800 Subject: [PATCH] Prevent Watchdog reset writing Creality 4.x EEPROM (#20328) --- Marlin/src/HAL/STM32F1/eeprom_bl24cxx.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Marlin/src/HAL/STM32F1/eeprom_bl24cxx.cpp b/Marlin/src/HAL/STM32F1/eeprom_bl24cxx.cpp index 94b5e099b..09fe8f910 100644 --- a/Marlin/src/HAL/STM32F1/eeprom_bl24cxx.cpp +++ b/Marlin/src/HAL/STM32F1/eeprom_bl24cxx.cpp @@ -48,6 +48,8 @@ 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; @@ -55,7 +57,10 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui // 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;