瀏覽代碼

Avoid watchdog reset in all wired EEPROMs (#21436)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
Tomas Rimkus 4 年之前
父節點
當前提交
8a67846872
No account linked to committer's email address

+ 3
- 3
Marlin/src/HAL/AVR/eeprom.cpp 查看文件

@@ -40,13 +40,13 @@ bool PersistentStore::access_start()  { return true; }
40 40
 bool PersistentStore::access_finish() { return true; }
41 41
 
42 42
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
43
+  uint16_t written = 0;
43 44
   while (size--) {
44 45
     uint8_t * const p = (uint8_t * const)pos;
45 46
     uint8_t v = *value;
46
-    // EEPROM has only ~100,000 write cycles,
47
-    // so only write bytes that have changed!
48
-    if (v != eeprom_read_byte(p)) {
47
+    if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
49 48
       eeprom_write_byte(p, v);
49
+      if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
50 50
       if (eeprom_read_byte(p) != v) {
51 51
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
52 52
         return true;

+ 3
- 4
Marlin/src/HAL/DUE/eeprom_flash.cpp 查看文件

@@ -976,14 +976,13 @@ bool PersistentStore::access_start()  { ee_Init();  return true; }
976 976
 bool PersistentStore::access_finish() { ee_Flush(); return true; }
977 977
 
978 978
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
979
+  uint16_t written = 0;
979 980
   while (size--) {
980 981
     uint8_t * const p = (uint8_t * const)pos;
981 982
     uint8_t v = *value;
982
-    // EEPROM has only ~100,000 write cycles,
983
-    // so only write bytes that have changed!
984
-    if (v != ee_Read(uint32_t(p))) {
983
+    if (v != ee_Read(uint32_t(p))) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
985 984
       ee_Write(uint32_t(p), v);
986
-      delay(2);
985
+      if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
987 986
       if (ee_Read(uint32_t(p)) != v) {
988 987
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
989 988
         return true;

+ 3
- 4
Marlin/src/HAL/DUE/eeprom_wired.cpp 查看文件

@@ -42,14 +42,13 @@ bool PersistentStore::access_start()  { eeprom_init(); return true; }
42 42
 bool PersistentStore::access_finish() { return true; }
43 43
 
44 44
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
45
+  uint16_t written = 0;
45 46
   while (size--) {
46 47
     uint8_t * const p = (uint8_t * const)pos;
47 48
     uint8_t v = *value;
48
-    // EEPROM has only ~100,000 write cycles,
49
-    // so only write bytes that have changed!
50
-    if (v != eeprom_read_byte(p)) {
49
+    if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
51 50
       eeprom_write_byte(p, v);
52
-      delay(2);
51
+      if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
53 52
       if (eeprom_read_byte(p) != v) {
54 53
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
55 54
         return true;

+ 4
- 8
Marlin/src/HAL/LPC1768/eeprom_wired.cpp 查看文件

@@ -42,25 +42,22 @@ bool PersistentStore::access_start()  { eeprom_init(); return true; }
42 42
 bool PersistentStore::access_finish() { return true; }
43 43
 
44 44
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
45
+  uint16_t written = 0;
45 46
   while (size--) {
46 47
     uint8_t v = *value;
47
-
48
-    // EEPROM has only ~100,000 write cycles,
49
-    // so only write bytes that have changed!
50 48
     uint8_t * const p = (uint8_t * const)pos;
51
-    if (v != eeprom_read_byte(p)) {
49
+    if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
52 50
       eeprom_write_byte(p, v);
51
+      if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
53 52
       if (eeprom_read_byte(p) != v) {
54 53
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
55 54
         return true;
56 55
       }
57 56
     }
58
-
59 57
     crc16(crc, &v, 1);
60 58
     pos++;
61 59
     value++;
62
-  };
63
-
60
+  }
64 61
   return false;
65 62
 }
66 63
 
@@ -68,7 +65,6 @@ bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t
68 65
   do {
69 66
     // Read from external EEPROM
70 67
     const uint8_t c = eeprom_read_byte((uint8_t*)pos);
71
-
72 68
     if (writing) *value = c;
73 69
     crc16(crc, &c, 1);
74 70
     pos++;

+ 3
- 2
Marlin/src/HAL/SAMD51/eeprom_wired.cpp 查看文件

@@ -41,12 +41,13 @@ bool PersistentStore::access_start()  { eeprom_init(); return true; }
41 41
 bool PersistentStore::access_finish() { return true; }
42 42
 
43 43
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
44
+  uint16_t written = 0;
44 45
   while (size--) {
45 46
     const uint8_t v = *value;
46 47
     uint8_t * const p = (uint8_t * const)pos;
47
-    if (v != eeprom_read_byte(p)) {
48
+    if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
48 49
       eeprom_write_byte(p, v);
49
-      delay(2);
50
+      if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
50 51
       if (eeprom_read_byte(p) != v) {
51 52
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
52 53
         return true;

+ 4
- 7
Marlin/src/HAL/STM32/eeprom_wired.cpp 查看文件

@@ -43,25 +43,22 @@ bool PersistentStore::access_start()  { eeprom_init(); return true; }
43 43
 bool PersistentStore::access_finish() { return true; }
44 44
 
45 45
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
46
+  uint16_t written = 0;
46 47
   while (size--) {
47 48
     uint8_t v = *value;
48
-
49
-    // EEPROM has only ~100,000 write cycles,
50
-    // so only write bytes that have changed!
51 49
     uint8_t * const p = (uint8_t * const)pos;
52
-    if (v != eeprom_read_byte(p)) {
50
+    if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
53 51
       eeprom_write_byte(p, v);
52
+      if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
54 53
       if (eeprom_read_byte(p) != v) {
55 54
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
56 55
         return true;
57 56
       }
58 57
     }
59
-
60 58
     crc16(crc, &v, 1);
61 59
     pos++;
62 60
     value++;
63
-  };
64
-
61
+  }
65 62
   return false;
66 63
 }
67 64
 

+ 3
- 6
Marlin/src/HAL/STM32F1/eeprom_bl24cxx.cpp 查看文件

@@ -19,14 +19,13 @@
19 19
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20 20
  *
21 21
  */
22
+#ifdef __STM32F1__
22 23
 
23 24
 /**
24 25
  * PersistentStore for Arduino-style EEPROM interface
25 26
  * with simple implementations supplied by Marlin.
26 27
  */
27 28
 
28
-#ifdef __STM32F1__
29
-
30 29
 #include "../../inc/MarlinConfig.h"
31 30
 
32 31
 #if ENABLED(IIC_BL24CXX_EEPROM)
@@ -48,13 +47,11 @@ bool PersistentStore::access_start()  { eeprom_init(); return true; }
48 47
 bool PersistentStore::access_finish() { return true; }
49 48
 
50 49
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
51
-  size_t written = 0;
50
+  uint16_t written = 0;
52 51
   while (size--) {
53 52
     uint8_t v = *value;
54 53
     uint8_t * const p = (uint8_t * const)pos;
55
-    // EEPROM has only ~100,000 write cycles,
56
-    // so only write bytes that have changed!
57
-    if (v != eeprom_read_byte(p)) {
54
+    if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
58 55
       eeprom_write_byte(p, v);
59 56
       if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
60 57
       if (eeprom_read_byte(p) != v) {

+ 3
- 3
Marlin/src/HAL/STM32F1/eeprom_wired.cpp 查看文件

@@ -52,13 +52,13 @@ bool PersistentStore::access_start() {
52 52
 }
53 53
 
54 54
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
55
+  uint16_t written = 0;
55 56
   while (size--) {
56 57
     uint8_t * const p = (uint8_t * const)pos;
57 58
     uint8_t v = *value;
58
-    // EEPROM has only ~100,000 write cycles,
59
-    // so only write bytes that have changed!
60
-    if (v != eeprom_read_byte(p)) {
59
+    if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
61 60
       eeprom_write_byte(p, v);
61
+      if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
62 62
       if (eeprom_read_byte(p) != v) {
63 63
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
64 64
         return true;

+ 7
- 7
Marlin/src/HAL/TEENSY31_32/eeprom.cpp 查看文件

@@ -18,14 +18,14 @@
18 18
  */
19 19
 #ifdef __MK20DX256__
20 20
 
21
-#include "../../inc/MarlinConfig.h"
22
-
23
-#if USE_WIRED_EEPROM
24
-
25 21
 /**
26 22
  * HAL PersistentStore for Teensy 3.2 (MK20DX256)
27 23
  */
28 24
 
25
+#include "../../inc/MarlinConfig.h"
26
+
27
+#if USE_WIRED_EEPROM
28
+
29 29
 #include "../shared/eeprom_api.h"
30 30
 #include <avr/eeprom.h>
31 31
 
@@ -38,13 +38,13 @@ bool PersistentStore::access_start()  { return true; }
38 38
 bool PersistentStore::access_finish() { return true; }
39 39
 
40 40
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
41
+  uint16_t written = 0;
41 42
   while (size--) {
42 43
     uint8_t * const p = (uint8_t * const)pos;
43 44
     uint8_t v = *value;
44
-    // EEPROM has only ~100,000 write cycles,
45
-    // so only write bytes that have changed!
46
-    if (v != eeprom_read_byte(p)) {
45
+    if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
47 46
       eeprom_write_byte(p, v);
47
+      if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
48 48
       if (eeprom_read_byte(p) != v) {
49 49
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
50 50
         return true;

+ 3
- 3
Marlin/src/HAL/TEENSY35_36/eeprom.cpp 查看文件

@@ -42,13 +42,13 @@ bool PersistentStore::access_start()  { return true; }
42 42
 bool PersistentStore::access_finish() { return true; }
43 43
 
44 44
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
45
+  uint16_t written = 0;
45 46
   while (size--) {
46 47
     uint8_t * const p = (uint8_t * const)pos;
47 48
     uint8_t v = *value;
48
-    // EEPROM has only ~100,000 write cycles,
49
-    // so only write bytes that have changed!
50
-    if (v != eeprom_read_byte(p)) {
49
+    if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
51 50
       eeprom_write_byte(p, v);
51
+      if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
52 52
       if (eeprom_read_byte(p) != v) {
53 53
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
54 54
         return true;

+ 7
- 7
Marlin/src/HAL/TEENSY40_41/eeprom.cpp 查看文件

@@ -22,14 +22,14 @@
22 22
  */
23 23
 #ifdef __IMXRT1062__
24 24
 
25
-#include "../../inc/MarlinConfig.h"
26
-
27
-#if USE_WIRED_EEPROM
28
-
29 25
 /**
30 26
  * HAL PersistentStore for Teensy 4.0 (IMXRT1062DVL6A) / 4.1 (IMXRT1062DVJ6A)
31 27
  */
32 28
 
29
+#include "../../inc/MarlinConfig.h"
30
+
31
+#if USE_WIRED_EEPROM
32
+
33 33
 #include "../shared/eeprom_api.h"
34 34
 #include <avr/eeprom.h>
35 35
 
@@ -42,13 +42,13 @@ bool PersistentStore::access_start()  { return true; }
42 42
 bool PersistentStore::access_finish() { return true; }
43 43
 
44 44
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
45
+  uint16_t written = 0;
45 46
   while (size--) {
46 47
     uint8_t * const p = (uint8_t * const)pos;
47 48
     uint8_t v = *value;
48
-    // EEPROM has only ~100,000 write cycles,
49
-    // so only write bytes that have changed!
50
-    if (v != eeprom_read_byte(p)) {
49
+    if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
51 50
       eeprom_write_byte(p, v);
51
+      if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
52 52
       if (eeprom_read_byte(p) != v) {
53 53
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
54 54
         return true;

Loading…
取消
儲存