Prevent Watchdog reset writing Creality 4.x EEPROM (#20328)
This commit is contained in:
parent
db8fb9a03a
commit
6f4381df53
|
@ -48,6 +48,8 @@ bool PersistentStore::access_start() { eeprom_init(); return true; }
|
||||||
bool PersistentStore::access_finish() { return true; }
|
bool PersistentStore::access_finish() { return true; }
|
||||||
|
|
||||||
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
|
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
|
||||||
|
size_t written = 0;
|
||||||
|
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t v = *value;
|
uint8_t v = *value;
|
||||||
uint8_t * const p = (uint8_t * const)pos;
|
uint8_t * const p = (uint8_t * const)pos;
|
||||||
|
@ -55,6 +57,9 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
|
||||||
// so only write bytes that have changed!
|
// so only write bytes that have changed!
|
||||||
if (v != eeprom_read_byte(p)) {
|
if (v != eeprom_read_byte(p)) {
|
||||||
eeprom_write_byte(p, v);
|
eeprom_write_byte(p, v);
|
||||||
|
if (++written % 128 == 0)
|
||||||
|
safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||||
|
else
|
||||||
delay(2);
|
delay(2);
|
||||||
if (eeprom_read_byte(p) != v) {
|
if (eeprom_read_byte(p) != v) {
|
||||||
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
||||||
|
|
Loading…
Reference in a new issue