Avoid watchdog reset in all wired EEPROMs (#21436)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
This commit is contained in:
Tomas Rimkus
2021-03-26 01:16:45 +01:00
committed by GitHub
parent 704b8cd83c
commit 8a67846872
11 changed files with 43 additions and 54 deletions

View File

@ -18,14 +18,14 @@
*/
#ifdef __MK20DX256__
#include "../../inc/MarlinConfig.h"
#if USE_WIRED_EEPROM
/**
* HAL PersistentStore for Teensy 3.2 (MK20DX256)
*/
#include "../../inc/MarlinConfig.h"
#if USE_WIRED_EEPROM
#include "../shared/eeprom_api.h"
#include <avr/eeprom.h>
@ -38,13 +38,13 @@ bool PersistentStore::access_start() { return true; }
bool PersistentStore::access_finish() { return true; }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
uint16_t written = 0;
while (size--) {
uint8_t * const p = (uint8_t * const)pos;
uint8_t v = *value;
// EEPROM has only ~100,000 write cycles,
// so only write bytes that have changed!
if (v != eeprom_read_byte(p)) {
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
eeprom_write_byte(p, v);
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
if (eeprom_read_byte(p) != v) {
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
return true;