Browse Source

Prevent Watchdog reset writing Creality 4.x EEPROM (#20328)

Jason Smith 4 years ago
parent
commit
6f4381df53
No account linked to committer's email address
1 changed files with 6 additions and 1 deletions
  1. 6
    1
      Marlin/src/HAL/STM32F1/eeprom_bl24cxx.cpp

+ 6
- 1
Marlin/src/HAL/STM32F1/eeprom_bl24cxx.cpp View File

48
 bool PersistentStore::access_finish() { return true; }
48
 bool PersistentStore::access_finish() { return true; }
49
 
49
 
50
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
50
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
51
+  size_t written = 0;
52
+
51
   while (size--) {
53
   while (size--) {
52
     uint8_t v = *value;
54
     uint8_t v = *value;
53
     uint8_t * const p = (uint8_t * const)pos;
55
     uint8_t * const p = (uint8_t * const)pos;
55
     // so only write bytes that have changed!
57
     // so only write bytes that have changed!
56
     if (v != eeprom_read_byte(p)) {
58
     if (v != eeprom_read_byte(p)) {
57
       eeprom_write_byte(p, v);
59
       eeprom_write_byte(p, v);
58
-      delay(2);
60
+      if (++written % 128 == 0)
61
+        safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
62
+      else
63
+        delay(2);
59
       if (eeprom_read_byte(p) != v) {
64
       if (eeprom_read_byte(p) != v) {
60
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
65
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
61
         return true;
66
         return true;

Loading…
Cancel
Save