From 61a67aff316ca5b25f8169f5dce27ced23c09773 Mon Sep 17 00:00:00 2001 From: Sergey Date: Wed, 27 May 2020 22:01:51 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D1=88=D0=B8=D0=B1=D0=BA=D0=B0=20=D1=81?= =?UTF-8?q?=D0=BB=D0=B8=D1=8F=D0=BD=D0=B8=D1=8F=20=D0=B2=D0=B5=D1=82=D0=BE?= =?UTF-8?q?=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/HAL/STM32F1/eeprom.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/Marlin/src/HAL/STM32F1/eeprom.cpp b/Marlin/src/HAL/STM32F1/eeprom.cpp index 48daffc4f0..d10af28a8c 100644 --- a/Marlin/src/HAL/STM32F1/eeprom.cpp +++ b/Marlin/src/HAL/STM32F1/eeprom.cpp @@ -56,18 +56,11 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui while (size--) { uint8_t * const p = (uint8_t * const)pos; uint8_t v = *value; - uint8_t r_val; - - DEBUG("Write to : %d val: %0X",pos,v); - r_val=eeprom_read_byte((uint16_t *)p); - - if (v != r_val) { - DEBUG("Read val: %0X To write val: %0X",r_val,v); - eeprom_write_byte((uint16_t *)p, v); - r_val=eeprom_read_byte((uint16_t *)p); - DEBUG("Read back val: %0X",r_val); - if (r_val != v) { - ERROR("Write error"); + // EEPROM has only ~100,000 write cycles, + // so only write bytes that have changed! + if (v != eeprom_read_byte(p)) { + eeprom_write_byte(p, v); + if (eeprom_read_byte(p) != v) { SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE); return true; } @@ -81,8 +74,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) { do { - DEBUG("Read form: %d",pos); - uint8_t c = eeprom_read_byte((uint16_t*)pos); + uint8_t c = eeprom_read_byte((uint8_t*)pos); if (writing && value) *value = c; crc16(crc, &c, 1); pos++;