✨🔨 EEPROM exclusion zone (#26729)
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
parent
6c1fd1f69c
commit
01094ea6aa
|
@ -35,14 +35,14 @@
|
||||||
#ifndef MARLIN_EEPROM_SIZE
|
#ifndef MARLIN_EEPROM_SIZE
|
||||||
#define MARLIN_EEPROM_SIZE size_t(E2END + 1)
|
#define MARLIN_EEPROM_SIZE size_t(E2END + 1)
|
||||||
#endif
|
#endif
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
bool PersistentStore::access_start() { return true; }
|
bool PersistentStore::access_start() { 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) {
|
||||||
uint16_t written = 0;
|
uint16_t written = 0;
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t * const p = (uint8_t * const)pos;
|
uint8_t * const p = (uint8_t * const)REAL_EEPROM_ADDR(pos);
|
||||||
uint8_t v = *value;
|
uint8_t v = *value;
|
||||||
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
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);
|
eeprom_write_byte(p, v);
|
||||||
|
@ -61,7 +61,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*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
do {
|
do {
|
||||||
uint8_t c = eeprom_read_byte((uint8_t*)pos);
|
const uint8_t c = eeprom_read_byte((uint8_t*)REAL_EEPROM_ADDR(pos));
|
||||||
if (writing) *value = c;
|
if (writing) *value = c;
|
||||||
crc16(crc, &c, 1);
|
crc16(crc, &c, 1);
|
||||||
pos++;
|
pos++;
|
||||||
|
|
|
@ -958,14 +958,14 @@ static void ee_Init() {
|
||||||
#ifndef MARLIN_EEPROM_SIZE
|
#ifndef MARLIN_EEPROM_SIZE
|
||||||
#define MARLIN_EEPROM_SIZE 0x1000 // 4KB
|
#define MARLIN_EEPROM_SIZE 0x1000 // 4KB
|
||||||
#endif
|
#endif
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
bool PersistentStore::access_start() { ee_Init(); return true; }
|
bool PersistentStore::access_start() { ee_Init(); return true; }
|
||||||
bool PersistentStore::access_finish() { ee_Flush(); return true; }
|
bool PersistentStore::access_finish() { ee_Flush(); 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) {
|
||||||
uint16_t written = 0;
|
uint16_t written = 0;
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t * const p = (uint8_t * const)pos;
|
uint8_t * const p = (uint8_t * const)REAL_EEPROM_ADDR(pos);
|
||||||
uint8_t v = *value;
|
uint8_t v = *value;
|
||||||
if (v != ee_Read(uint32_t(p))) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
if (v != ee_Read(uint32_t(p))) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
||||||
ee_Write(uint32_t(p), v);
|
ee_Write(uint32_t(p), v);
|
||||||
|
@ -984,7 +984,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*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
do {
|
do {
|
||||||
uint8_t c = ee_Read(uint32_t(pos));
|
uint8_t c = ee_Read(uint32_t(REAL_EEPROM_ADDR(pos)));
|
||||||
if (writing) *value = c;
|
if (writing) *value = c;
|
||||||
crc16(crc, &c, 1);
|
crc16(crc, &c, 1);
|
||||||
pos++;
|
pos++;
|
||||||
|
|
|
@ -36,14 +36,14 @@
|
||||||
#ifndef MARLIN_EEPROM_SIZE
|
#ifndef MARLIN_EEPROM_SIZE
|
||||||
#error "MARLIN_EEPROM_SIZE is required for I2C / SPI EEPROM."
|
#error "MARLIN_EEPROM_SIZE is required for I2C / SPI EEPROM."
|
||||||
#endif
|
#endif
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
bool PersistentStore::access_start() { eeprom_init(); return true; }
|
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) {
|
||||||
uint16_t written = 0;
|
uint16_t written = 0;
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t * const p = (uint8_t * const)pos;
|
uint8_t * const p = (uint8_t * const)REAL_EEPROM_ADDR(pos);
|
||||||
uint8_t v = *value;
|
uint8_t v = *value;
|
||||||
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
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);
|
eeprom_write_byte(p, v);
|
||||||
|
@ -62,7 +62,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*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
do {
|
do {
|
||||||
uint8_t c = eeprom_read_byte((uint8_t*)pos);
|
const uint8_t c = eeprom_read_byte((uint8_t*)REAL_EEPROM_ADDR(pos));
|
||||||
if (writing) *value = c;
|
if (writing) *value = c;
|
||||||
crc16(crc, &c, 1);
|
crc16(crc, &c, 1);
|
||||||
pos++;
|
pos++;
|
||||||
|
|
|
@ -31,24 +31,28 @@
|
||||||
#ifndef MARLIN_EEPROM_SIZE
|
#ifndef MARLIN_EEPROM_SIZE
|
||||||
#define MARLIN_EEPROM_SIZE 0x1000 // 4KB
|
#define MARLIN_EEPROM_SIZE 0x1000 // 4KB
|
||||||
#endif
|
#endif
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
|
||||||
bool PersistentStore::access_start() { return EEPROM.begin(MARLIN_EEPROM_SIZE); }
|
bool PersistentStore::access_start() { return EEPROM.begin(MARLIN_EEPROM_SIZE); }
|
||||||
bool PersistentStore::access_finish() { EEPROM.end(); return true; }
|
bool PersistentStore::access_finish() { EEPROM.end(); 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) {
|
||||||
for (size_t i = 0; i < size; i++) {
|
for (size_t i = 0; i < size; i++) {
|
||||||
EEPROM.write(pos++, value[i]);
|
const int p = REAL_EEPROM_ADDR(pos);
|
||||||
|
EEPROM.write(p, value[i]);
|
||||||
crc16(crc, &value[i], 1);
|
crc16(crc, &value[i], 1);
|
||||||
|
++pos;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
for (size_t i = 0; i < size; i++) {
|
for (size_t i = 0; i < size; i++) {
|
||||||
uint8_t c = EEPROM.read(pos++);
|
const int p = REAL_EEPROM_ADDR(pos);
|
||||||
|
uint8_t c = EEPROM.read(p);
|
||||||
if (writing) value[i] = c;
|
if (writing) value[i] = c;
|
||||||
crc16(crc, &c, 1);
|
crc16(crc, &c, 1);
|
||||||
|
++pos;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
#error "MARLIN_EEPROM_SIZE is required for IIC_BL24CXX_EEPROM."
|
#error "MARLIN_EEPROM_SIZE is required for IIC_BL24CXX_EEPROM."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
|
||||||
bool PersistentStore::access_start() {
|
bool PersistentStore::access_start() {
|
||||||
eeprom_init();
|
eeprom_init();
|
||||||
|
@ -49,7 +49,7 @@ 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) {
|
||||||
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)REAL_EEPROM_ADDR(pos);
|
||||||
|
|
||||||
// EEPROM has only ~100,000 write cycles,
|
// EEPROM has only ~100,000 write cycles,
|
||||||
// so only write bytes that have changed!
|
// so only write bytes that have changed!
|
||||||
|
@ -70,16 +70,10 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size,
|
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing /*=true*/) {
|
||||||
uint16_t *crc, const bool writing /*=true*/) {
|
|
||||||
do {
|
do {
|
||||||
uint8_t *const p = (uint8_t *const)pos;
|
const uint8_t c = eeprom_read_byte((uint8_t*)REAL_EEPROM_ADDR(pos));
|
||||||
uint8_t c = eeprom_read_byte(p);
|
if (writing) *value = c;
|
||||||
if (writing)
|
|
||||||
{
|
|
||||||
*value = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
crc16(crc, &c, 1);
|
crc16(crc, &c, 1);
|
||||||
pos++;
|
pos++;
|
||||||
value++;
|
value++;
|
||||||
|
|
|
@ -38,9 +38,7 @@
|
||||||
#define MARLIN_EEPROM_SIZE 0x1000 // 4KB
|
#define MARLIN_EEPROM_SIZE 0x1000 // 4KB
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
size_t PersistentStore::capacity() {
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
return MARLIN_EEPROM_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define _ALIGN(x) __attribute__((aligned(x)))
|
#define _ALIGN(x) __attribute__((aligned(x)))
|
||||||
static char _ALIGN(4) HAL_eeprom_data[MARLIN_EEPROM_SIZE];
|
static char _ALIGN(4) HAL_eeprom_data[MARLIN_EEPROM_SIZE];
|
||||||
|
@ -85,11 +83,10 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
|
||||||
|
|
||||||
bool PersistentStore::read_data(int &pos, uint8_t *value, const size_t size, uint16_t *crc, const bool writing /*=true*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t *value, const size_t size, uint16_t *crc, const bool writing /*=true*/) {
|
||||||
for (size_t i = 0; i < size; i++) {
|
for (size_t i = 0; i < size; i++) {
|
||||||
uint8_t c = HAL_eeprom_data[pos + i];
|
const uint8_t c = HAL_eeprom_data[pos + i];
|
||||||
if (writing) value[i] = c;
|
if (writing) value[i] = c;
|
||||||
crc16(crc, &c, 1);
|
crc16(crc, &c, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
pos += size;
|
pos += size;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
#ifndef MARLIN_EEPROM_SIZE
|
#ifndef MARLIN_EEPROM_SIZE
|
||||||
#error "MARLIN_EEPROM_SIZE is required for I2C / SPI EEPROM."
|
#error "MARLIN_EEPROM_SIZE is required for I2C / SPI EEPROM."
|
||||||
#endif
|
#endif
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
|
||||||
bool PersistentStore::access_finish() { return true; }
|
bool PersistentStore::access_finish() { return true; }
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ bool PersistentStore::access_start() {
|
||||||
|
|
||||||
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) {
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t *const p = (uint8_t *const)pos;
|
uint8_t * const p = (uint8_t * const)REAL_EEPROM_ADDR(pos);
|
||||||
uint8_t v = *value;
|
uint8_t v = *value;
|
||||||
// EEPROM has only ~100,000 write cycles,
|
// EEPROM has only ~100,000 write cycles,
|
||||||
// so only write bytes that have changed!
|
// so only write bytes that have changed!
|
||||||
|
@ -77,10 +77,8 @@ 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*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing /*=true*/) {
|
||||||
do {
|
do {
|
||||||
uint8_t c = eeprom_read_byte((uint8_t *)pos);
|
const uint8_t c = eeprom_read_byte((uint8_t *)REAL_EEPROM_ADDR(pos));
|
||||||
if (writing && value) {
|
if (writing && value) *value = c;
|
||||||
*value = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
crc16(crc, &c, 1);
|
crc16(crc, &c, 1);
|
||||||
pos++;
|
pos++;
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
uint8_t buffer[MARLIN_EEPROM_SIZE];
|
uint8_t buffer[MARLIN_EEPROM_SIZE];
|
||||||
char filename[] = "eeprom.dat";
|
char filename[] = "eeprom.dat";
|
||||||
|
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
|
||||||
bool PersistentStore::access_start() {
|
bool PersistentStore::access_start() {
|
||||||
const char eeprom_erase_value = 0xFF;
|
const char eeprom_erase_value = 0xFF;
|
||||||
|
|
|
@ -61,7 +61,7 @@ static uint8_t ram_eeprom[MARLIN_EEPROM_SIZE] __attribute__((aligned(4))) = {0};
|
||||||
static bool eeprom_dirty = false;
|
static bool eeprom_dirty = false;
|
||||||
static int current_slot = 0;
|
static int current_slot = 0;
|
||||||
|
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
|
||||||
bool PersistentStore::access_start() {
|
bool PersistentStore::access_start() {
|
||||||
uint32_t first_nblank_loc, first_nblank_val;
|
uint32_t first_nblank_loc, first_nblank_val;
|
||||||
|
@ -112,7 +112,8 @@ bool PersistentStore::access_finish() {
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
for (size_t i = 0; i < size; i++) ram_eeprom[pos + i] = value[i];
|
const int p = REAL_EEPROM_ADDR(pos);
|
||||||
|
for (size_t i = 0; i < size; i++) ram_eeprom[p + i] = value[i];
|
||||||
eeprom_dirty = true;
|
eeprom_dirty = true;
|
||||||
crc16(crc, value, size);
|
crc16(crc, value, size);
|
||||||
pos += size;
|
pos += size;
|
||||||
|
@ -120,8 +121,9 @@ 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*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
|
const int p = REAL_EEPROM_ADDR(pos);
|
||||||
const uint8_t * const buff = writing ? &value[0] : &ram_eeprom[pos];
|
const uint8_t * const buff = writing ? &value[0] : &ram_eeprom[pos];
|
||||||
if (writing) for (size_t i = 0; i < size; i++) value[i] = ram_eeprom[pos + i];
|
if (writing) for (size_t i = 0; i < size; i++) value[i] = ram_eeprom[p + i];
|
||||||
crc16(crc, buff, size);
|
crc16(crc, buff, size);
|
||||||
pos += size;
|
pos += size;
|
||||||
return false; // return true for any error
|
return false; // return true for any error
|
||||||
|
|
|
@ -49,7 +49,7 @@ bool eeprom_file_open = false;
|
||||||
#define MARLIN_EEPROM_SIZE size_t(0x1000) // 4KiB of Emulated EEPROM
|
#define MARLIN_EEPROM_SIZE size_t(0x1000) // 4KiB of Emulated EEPROM
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
|
||||||
bool PersistentStore::access_start() {
|
bool PersistentStore::access_start() {
|
||||||
const char eeprom_erase_value = 0xFF;
|
const char eeprom_erase_value = 0xFF;
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
#ifndef MARLIN_EEPROM_SIZE
|
#ifndef MARLIN_EEPROM_SIZE
|
||||||
#define MARLIN_EEPROM_SIZE 0x8000 // 32K
|
#define MARLIN_EEPROM_SIZE 0x8000 // 32K
|
||||||
#endif
|
#endif
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
|
||||||
bool PersistentStore::access_start() { eeprom_init(); return true; }
|
bool PersistentStore::access_start() { eeprom_init(); return true; }
|
||||||
bool PersistentStore::access_finish() { return true; }
|
bool PersistentStore::access_finish() { return true; }
|
||||||
|
@ -45,7 +45,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
|
||||||
uint16_t written = 0;
|
uint16_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)REAL_EEPROM_ADDR(pos);
|
||||||
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
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);
|
eeprom_write_byte(p, v);
|
||||||
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||||
|
@ -64,7 +64,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*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
do {
|
do {
|
||||||
// Read from external EEPROM
|
// Read from external EEPROM
|
||||||
const uint8_t c = eeprom_read_byte((uint8_t*)pos);
|
const uint8_t c = eeprom_read_byte((uint8_t*)REAL_EEPROM_ADDR(pos));
|
||||||
if (writing) *value = c;
|
if (writing) *value = c;
|
||||||
crc16(crc, &c, 1);
|
crc16(crc, &c, 1);
|
||||||
pos++;
|
pos++;
|
||||||
|
|
|
@ -37,19 +37,24 @@ static const uint8_t flashdata[TOTAL_FLASH_SIZE] __attribute__((__aligned__(256
|
||||||
|
|
||||||
#include "../shared/eeprom_api.h"
|
#include "../shared/eeprom_api.h"
|
||||||
|
|
||||||
size_t PersistentStore::capacity() {
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
return MARLIN_EEPROM_SIZE;
|
|
||||||
/* const uint8_t psz = NVMCTRL->SEESTAT.bit.PSZ,
|
/*
|
||||||
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
const uint8_t psz = NVMCTRL->SEESTAT.bit.PSZ,
|
||||||
sblk = NVMCTRL->SEESTAT.bit.SBLK;
|
sblk = NVMCTRL->SEESTAT.bit.SBLK;
|
||||||
|
|
||||||
return (!psz && !sblk) ? 0
|
return (
|
||||||
|
(!psz && !sblk) ? 0
|
||||||
: (psz <= 2) ? (0x200 << psz)
|
: (psz <= 2) ? (0x200 << psz)
|
||||||
: (sblk == 1 || psz == 3) ? 4096
|
: (sblk == 1 || psz == 3) ? 4096
|
||||||
: (sblk == 2 || psz == 4) ? 8192
|
: (sblk == 2 || psz == 4) ? 8192
|
||||||
: (sblk <= 4 || psz == 5) ? 16384
|
: (sblk <= 4 || psz == 5) ? 16384
|
||||||
: (sblk >= 9 && psz == 7) ? 65536
|
: (sblk >= 9 && psz == 7) ? 65536
|
||||||
: 32768;*/
|
: 32768
|
||||||
|
) - eeprom_exclude_size;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
uint32_t PAGE_SIZE;
|
uint32_t PAGE_SIZE;
|
||||||
uint32_t ROW_SIZE;
|
uint32_t ROW_SIZE;
|
||||||
|
@ -99,8 +104,7 @@ bool PersistentStore::access_finish() {
|
||||||
volatile uint32_t *dst_addr = (volatile uint32_t *) &flashdata;
|
volatile uint32_t *dst_addr = (volatile uint32_t *) &flashdata;
|
||||||
|
|
||||||
uint32_t *pointer = (uint32_t *) buffer;
|
uint32_t *pointer = (uint32_t *) buffer;
|
||||||
for (uint32_t i = 0; i < TOTAL_FLASH_SIZE; i+=4) {
|
for (uint32_t i = 0; i < TOTAL_FLASH_SIZE; i += 4) {
|
||||||
|
|
||||||
*dst_addr = (uint32_t) *pointer;
|
*dst_addr = (uint32_t) *pointer;
|
||||||
pointer++;
|
pointer++;
|
||||||
dst_addr ++;
|
dst_addr ++;
|
||||||
|
@ -120,19 +124,19 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
|
||||||
if (!hasWritten) {
|
if (!hasWritten) {
|
||||||
// init temp buffer
|
// init temp buffer
|
||||||
buffer = (uint8_t *) malloc(MARLIN_EEPROM_SIZE);
|
buffer = (uint8_t *) malloc(MARLIN_EEPROM_SIZE);
|
||||||
hasWritten=true;
|
hasWritten = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(buffer+pos,value,size);
|
memcpy(buffer + REAL_EEPROM_ADDR(pos), value, size);
|
||||||
pos += size;
|
pos += size;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
volatile uint8_t *dst_addr = (volatile uint8_t *) &flashdata;
|
volatile uint8_t *dst_addr = (volatile uint8_t *) &flashdata;
|
||||||
dst_addr += pos;
|
dst_addr += REAL_EEPROM_ADDR(pos);
|
||||||
|
|
||||||
memcpy(value,(const void *) dst_addr,size);
|
memcpy(value, (const void *)dst_addr, size);
|
||||||
pos += size;
|
pos += size;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
static bool initialized;
|
static bool initialized;
|
||||||
|
|
||||||
size_t PersistentStore::capacity() { return qspi.size(); }
|
size_t PersistentStore::capacity() { return qspi.size() - eeprom_exclude_size; }
|
||||||
|
|
||||||
bool PersistentStore::access_start() {
|
bool PersistentStore::access_start() {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
|
@ -56,7 +56,7 @@ bool PersistentStore::access_finish() {
|
||||||
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) {
|
||||||
while (size--) {
|
while (size--) {
|
||||||
const uint8_t v = *value;
|
const uint8_t v = *value;
|
||||||
qspi.writeByte(pos, v);
|
qspi.writeByte(REAL_EEPROM_ADDR(pos), v);
|
||||||
crc16(crc, &v, 1);
|
crc16(crc, &v, 1);
|
||||||
pos++;
|
pos++;
|
||||||
value++;
|
value++;
|
||||||
|
@ -66,7 +66,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*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t c = qspi.readByte(pos);
|
const uint8_t c = qspi.readByte(REAL_EEPROM_ADDR(pos));
|
||||||
if (writing) *value = c;
|
if (writing) *value = c;
|
||||||
crc16(crc, &c, 1);
|
crc16(crc, &c, 1);
|
||||||
pos++;
|
pos++;
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
#ifndef MARLIN_EEPROM_SIZE
|
#ifndef MARLIN_EEPROM_SIZE
|
||||||
#error "MARLIN_EEPROM_SIZE is required for I2C / SPI EEPROM."
|
#error "MARLIN_EEPROM_SIZE is required for I2C / SPI EEPROM."
|
||||||
#endif
|
#endif
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
|
||||||
bool PersistentStore::access_start() { eeprom_init(); return true; }
|
bool PersistentStore::access_start() { eeprom_init(); return true; }
|
||||||
bool PersistentStore::access_finish() { return true; }
|
bool PersistentStore::access_finish() { return true; }
|
||||||
|
@ -51,7 +51,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
|
||||||
uint16_t written = 0;
|
uint16_t written = 0;
|
||||||
while (size--) {
|
while (size--) {
|
||||||
const uint8_t v = *value;
|
const uint8_t v = *value;
|
||||||
uint8_t * const p = (uint8_t * const)pos;
|
uint8_t * const p = (uint8_t * const)REAL_EEPROM_ADDR(pos);
|
||||||
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
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);
|
eeprom_write_byte(p, v);
|
||||||
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||||
|
@ -69,7 +69,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*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t c = eeprom_read_byte((uint8_t*)pos);
|
const uint8_t c = eeprom_read_byte((uint8_t*)REAL_EEPROM_ADDR(pos));
|
||||||
if (writing) *value = c;
|
if (writing) *value = c;
|
||||||
crc16(crc, &c, 1);
|
crc16(crc, &c, 1);
|
||||||
pos++;
|
pos++;
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
static bool initialized;
|
static bool initialized;
|
||||||
|
|
||||||
size_t PersistentStore::capacity() { return qspi.size(); }
|
size_t PersistentStore::capacity() { return qspi.size() - eeprom_exclude_size; }
|
||||||
|
|
||||||
bool PersistentStore::access_start() {
|
bool PersistentStore::access_start() {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
|
@ -53,7 +53,7 @@ bool PersistentStore::access_finish() {
|
||||||
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) {
|
||||||
while (size--) {
|
while (size--) {
|
||||||
const uint8_t v = *value;
|
const uint8_t v = *value;
|
||||||
qspi.writeByte(pos, v);
|
qspi.writeByte(REAL_EEPROM_ADDR(pos), v);
|
||||||
crc16(crc, &v, 1);
|
crc16(crc, &v, 1);
|
||||||
pos++;
|
pos++;
|
||||||
value++;
|
value++;
|
||||||
|
@ -63,7 +63,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*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t c = qspi.readByte(pos);
|
const uint8_t c = qspi.readByte(REAL_EEPROM_ADDR(pos));
|
||||||
if (writing) *value = c;
|
if (writing) *value = c;
|
||||||
crc16(crc, &c, 1);
|
crc16(crc, &c, 1);
|
||||||
pos++;
|
pos++;
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
#ifndef MARLIN_EEPROM_SIZE
|
#ifndef MARLIN_EEPROM_SIZE
|
||||||
#error "MARLIN_EEPROM_SIZE is required for I2C / SPI EEPROM."
|
#error "MARLIN_EEPROM_SIZE is required for I2C / SPI EEPROM."
|
||||||
#endif
|
#endif
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
|
||||||
bool PersistentStore::access_start() { eeprom_init(); return true; }
|
bool PersistentStore::access_start() { eeprom_init(); return true; }
|
||||||
bool PersistentStore::access_finish() { return true; }
|
bool PersistentStore::access_finish() { return true; }
|
||||||
|
@ -49,7 +49,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
|
||||||
uint16_t written = 0;
|
uint16_t written = 0;
|
||||||
while (size--) {
|
while (size--) {
|
||||||
const uint8_t v = *value;
|
const uint8_t v = *value;
|
||||||
uint8_t * const p = (uint8_t * const)pos;
|
uint8_t * const p = (uint8_t * const)REAL_EEPROM_ADDR(pos);
|
||||||
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
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);
|
eeprom_write_byte(p, v);
|
||||||
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||||
|
@ -67,7 +67,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*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t c = eeprom_read_byte((uint8_t*)pos);
|
const uint8_t c = eeprom_read_byte((uint8_t*)REAL_EEPROM_ADDR(pos));
|
||||||
if (writing) *value = c;
|
if (writing) *value = c;
|
||||||
crc16(crc, &c, 1);
|
crc16(crc, &c, 1);
|
||||||
pos++;
|
pos++;
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
#error "MARLIN_EEPROM_SIZE is required for IIC_BL24CXX_EEPROM."
|
#error "MARLIN_EEPROM_SIZE is required for IIC_BL24CXX_EEPROM."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
|
||||||
bool PersistentStore::access_start() { eeprom_init(); return true; }
|
bool PersistentStore::access_start() { eeprom_init(); return true; }
|
||||||
bool PersistentStore::access_finish() { return true; }
|
bool PersistentStore::access_finish() { return true; }
|
||||||
|
@ -53,7 +53,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
|
||||||
uint16_t written = 0;
|
uint16_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)REAL_EEPROM_ADDR(pos);
|
||||||
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
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);
|
eeprom_write_byte(p, v);
|
||||||
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||||
|
@ -71,8 +71,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*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
do {
|
do {
|
||||||
uint8_t * const p = (uint8_t * const)pos;
|
const uint8_t c = eeprom_read_byte((uint8_t*)REAL_EEPROM_ADDR(pos));
|
||||||
uint8_t c = eeprom_read_byte(p);
|
|
||||||
if (writing) *value = c;
|
if (writing) *value = c;
|
||||||
crc16(crc, &c, 1);
|
crc16(crc, &c, 1);
|
||||||
pos++;
|
pos++;
|
||||||
|
|
|
@ -101,7 +101,7 @@ static bool eeprom_data_written = false;
|
||||||
#ifndef MARLIN_EEPROM_SIZE
|
#ifndef MARLIN_EEPROM_SIZE
|
||||||
#define MARLIN_EEPROM_SIZE size_t(E2END + 1)
|
#define MARLIN_EEPROM_SIZE size_t(E2END + 1)
|
||||||
#endif
|
#endif
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
|
||||||
bool PersistentStore::access_start() {
|
bool PersistentStore::access_start() {
|
||||||
|
|
||||||
|
@ -245,14 +245,15 @@ bool PersistentStore::access_finish() {
|
||||||
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) {
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t v = *value;
|
uint8_t v = *value;
|
||||||
|
const int p = REAL_EEPROM_ADDR(pos);
|
||||||
#if ENABLED(FLASH_EEPROM_LEVELING)
|
#if ENABLED(FLASH_EEPROM_LEVELING)
|
||||||
if (v != ram_eeprom[pos]) {
|
if (v != ram_eeprom[p]) {
|
||||||
ram_eeprom[pos] = v;
|
ram_eeprom[p] = v;
|
||||||
eeprom_data_written = true;
|
eeprom_data_written = true;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (v != eeprom_buffered_read_byte(pos)) {
|
if (v != eeprom_buffered_read_byte(p)) {
|
||||||
eeprom_buffered_write_byte(pos, v);
|
eeprom_buffered_write_byte(p, v);
|
||||||
eeprom_data_written = true;
|
eeprom_data_written = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -265,7 +266,8 @@ 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*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
do {
|
do {
|
||||||
const uint8_t c = TERN(FLASH_EEPROM_LEVELING, ram_eeprom[pos], eeprom_buffered_read_byte(pos));
|
const int p = REAL_EEPROM_ADDR(pos);
|
||||||
|
const uint8_t c = TERN(FLASH_EEPROM_LEVELING, ram_eeprom[p], eeprom_buffered_read_byte(p));
|
||||||
if (writing) *value = c;
|
if (writing) *value = c;
|
||||||
crc16(crc, &c, 1);
|
crc16(crc, &c, 1);
|
||||||
pos++;
|
pos++;
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
#ifndef MARLIN_EEPROM_SIZE
|
#ifndef MARLIN_EEPROM_SIZE
|
||||||
#define MARLIN_EEPROM_SIZE 0x1000 // 4KB
|
#define MARLIN_EEPROM_SIZE 0x1000 // 4KB
|
||||||
#endif
|
#endif
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
|
||||||
#define _ALIGN(x) __attribute__ ((aligned(x)))
|
#define _ALIGN(x) __attribute__ ((aligned(x)))
|
||||||
static char _ALIGN(4) HAL_eeprom_data[MARLIN_EEPROM_SIZE];
|
static char _ALIGN(4) HAL_eeprom_data[MARLIN_EEPROM_SIZE];
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
#ifndef MARLIN_EEPROM_SIZE
|
#ifndef MARLIN_EEPROM_SIZE
|
||||||
#define MARLIN_EEPROM_SIZE 0x1000 // 4KB
|
#define MARLIN_EEPROM_SIZE 0x1000 // 4KB
|
||||||
#endif
|
#endif
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
|
||||||
bool PersistentStore::access_start() { return true; }
|
bool PersistentStore::access_start() { return true; }
|
||||||
bool PersistentStore::access_finish() { return true; }
|
bool PersistentStore::access_finish() { return true; }
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
#ifndef MARLIN_EEPROM_SIZE
|
#ifndef MARLIN_EEPROM_SIZE
|
||||||
#define MARLIN_EEPROM_SIZE size_t(E2END + 1)
|
#define MARLIN_EEPROM_SIZE size_t(E2END + 1)
|
||||||
#endif
|
#endif
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
|
||||||
bool PersistentStore::access_start() { eeprom_init(); return true; }
|
bool PersistentStore::access_start() { eeprom_init(); return true; }
|
||||||
bool PersistentStore::access_finish() { return true; }
|
bool PersistentStore::access_finish() { return true; }
|
||||||
|
@ -47,7 +47,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
|
||||||
uint16_t written = 0;
|
uint16_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)REAL_EEPROM_ADDR(pos);
|
||||||
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
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);
|
eeprom_write_byte(p, v);
|
||||||
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||||
|
@ -66,7 +66,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*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
do {
|
do {
|
||||||
// Read from either external EEPROM, program flash or Backup SRAM
|
// Read from either external EEPROM, program flash or Backup SRAM
|
||||||
const uint8_t c = eeprom_read_byte((uint8_t*)pos);
|
const uint8_t c = eeprom_read_byte((uint8_t*)REAL_EEPROM_ADDR(pos));
|
||||||
if (writing) *value = c;
|
if (writing) *value = c;
|
||||||
crc16(crc, &c, 1);
|
crc16(crc, &c, 1);
|
||||||
pos++;
|
pos++;
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
#error "MARLIN_EEPROM_SIZE is required for IIC_BL24CXX_EEPROM."
|
#error "MARLIN_EEPROM_SIZE is required for IIC_BL24CXX_EEPROM."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
|
||||||
bool PersistentStore::access_start() { eeprom_init(); return true; }
|
bool PersistentStore::access_start() { eeprom_init(); return true; }
|
||||||
bool PersistentStore::access_finish() { return true; }
|
bool PersistentStore::access_finish() { return true; }
|
||||||
|
@ -50,7 +50,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
|
||||||
uint16_t written = 0;
|
uint16_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)REAL_EEPROM_ADDR(pos);
|
||||||
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
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);
|
eeprom_write_byte(p, v);
|
||||||
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||||
|
@ -68,8 +68,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*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
do {
|
do {
|
||||||
uint8_t * const p = (uint8_t * const)pos;
|
const uint8_t c = eeprom_read_byte((uint8_t*)REAL_EEPROM_ADDR(pos));
|
||||||
uint8_t c = eeprom_read_byte(p);
|
|
||||||
if (writing) *value = c;
|
if (writing) *value = c;
|
||||||
crc16(crc, &c, 1);
|
crc16(crc, &c, 1);
|
||||||
pos++;
|
pos++;
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
#ifndef MARLIN_EEPROM_SIZE
|
#ifndef MARLIN_EEPROM_SIZE
|
||||||
#define MARLIN_EEPROM_SIZE ((EEPROM_PAGE_SIZE) * 2)
|
#define MARLIN_EEPROM_SIZE ((EEPROM_PAGE_SIZE) * 2)
|
||||||
#endif
|
#endif
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
|
||||||
static uint8_t ram_eeprom[MARLIN_EEPROM_SIZE] __attribute__((aligned(4))) = {0};
|
static uint8_t ram_eeprom[MARLIN_EEPROM_SIZE] __attribute__((aligned(4))) = {0};
|
||||||
static bool eeprom_dirty = false;
|
static bool eeprom_dirty = false;
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
#ifndef MARLIN_EEPROM_SIZE
|
#ifndef MARLIN_EEPROM_SIZE
|
||||||
#define MARLIN_EEPROM_SIZE 0x1000 // 4KB
|
#define MARLIN_EEPROM_SIZE 0x1000 // 4KB
|
||||||
#endif
|
#endif
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
|
||||||
#define _ALIGN(x) __attribute__ ((aligned(x))) // SDIO uint32_t* compat.
|
#define _ALIGN(x) __attribute__ ((aligned(x))) // SDIO uint32_t* compat.
|
||||||
static char _ALIGN(4) HAL_eeprom_data[MARLIN_EEPROM_SIZE];
|
static char _ALIGN(4) HAL_eeprom_data[MARLIN_EEPROM_SIZE];
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
#ifndef MARLIN_EEPROM_SIZE
|
#ifndef MARLIN_EEPROM_SIZE
|
||||||
#error "MARLIN_EEPROM_SIZE is required for I2C / SPI EEPROM."
|
#error "MARLIN_EEPROM_SIZE is required for I2C / SPI EEPROM."
|
||||||
#endif
|
#endif
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
|
||||||
bool PersistentStore::access_finish() { return true; }
|
bool PersistentStore::access_finish() { return true; }
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ bool PersistentStore::access_start() {
|
||||||
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) {
|
||||||
uint16_t written = 0;
|
uint16_t written = 0;
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t * const p = (uint8_t * const)pos;
|
uint8_t * const p = (uint8_t * const)REAL_EEPROM_ADDR(pos);
|
||||||
uint8_t v = *value;
|
uint8_t v = *value;
|
||||||
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
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);
|
eeprom_write_byte(p, v);
|
||||||
|
@ -76,7 +76,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*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
do {
|
do {
|
||||||
uint8_t c = eeprom_read_byte((uint8_t*)pos);
|
const uint8_t c = eeprom_read_byte((uint8_t*)REAL_EEPROM_ADDR(pos));
|
||||||
if (writing && value) *value = c;
|
if (writing && value) *value = c;
|
||||||
crc16(crc, &c, 1);
|
crc16(crc, &c, 1);
|
||||||
pos++;
|
pos++;
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
#ifndef MARLIN_EEPROM_SIZE
|
#ifndef MARLIN_EEPROM_SIZE
|
||||||
#define MARLIN_EEPROM_SIZE size_t(E2END + 1)
|
#define MARLIN_EEPROM_SIZE size_t(E2END + 1)
|
||||||
#endif
|
#endif
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
|
||||||
bool PersistentStore::access_start() { return true; }
|
bool PersistentStore::access_start() { return true; }
|
||||||
bool PersistentStore::access_finish() { return true; }
|
bool PersistentStore::access_finish() { return true; }
|
||||||
|
@ -44,7 +44,7 @@ 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) {
|
||||||
uint16_t written = 0;
|
uint16_t written = 0;
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t * const p = (uint8_t * const)pos;
|
uint8_t * const p = (uint8_t * const)REAL_EEPROM_ADDR(pos);
|
||||||
uint8_t v = *value;
|
uint8_t v = *value;
|
||||||
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
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);
|
eeprom_write_byte(p, v);
|
||||||
|
@ -63,7 +63,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*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
do {
|
do {
|
||||||
uint8_t c = eeprom_read_byte((uint8_t*)pos);
|
const uint8_t c = eeprom_read_byte((uint8_t*)REAL_EEPROM_ADDR(pos));
|
||||||
if (writing) *value = c;
|
if (writing) *value = c;
|
||||||
crc16(crc, &c, 1);
|
crc16(crc, &c, 1);
|
||||||
pos++;
|
pos++;
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
#ifndef MARLIN_EEPROM_SIZE
|
#ifndef MARLIN_EEPROM_SIZE
|
||||||
#define MARLIN_EEPROM_SIZE size_t(E2END + 1)
|
#define MARLIN_EEPROM_SIZE size_t(E2END + 1)
|
||||||
#endif
|
#endif
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
|
||||||
bool PersistentStore::access_start() { return true; }
|
bool PersistentStore::access_start() { return true; }
|
||||||
bool PersistentStore::access_finish() { return true; }
|
bool PersistentStore::access_finish() { return true; }
|
||||||
|
@ -43,7 +43,7 @@ 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) {
|
||||||
uint16_t written = 0;
|
uint16_t written = 0;
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t * const p = (uint8_t * const)pos;
|
uint8_t * const p = (uint8_t * const)REAL_EEPROM_ADDR(pos);
|
||||||
uint8_t v = *value;
|
uint8_t v = *value;
|
||||||
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
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);
|
eeprom_write_byte(p, v);
|
||||||
|
@ -62,7 +62,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*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
do {
|
do {
|
||||||
uint8_t c = eeprom_read_byte((uint8_t*)pos);
|
const uint8_t c = eeprom_read_byte((uint8_t*)REAL_EEPROM_ADDR(pos));
|
||||||
if (writing) *value = c;
|
if (writing) *value = c;
|
||||||
crc16(crc, &c, 1);
|
crc16(crc, &c, 1);
|
||||||
pos++;
|
pos++;
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
#ifndef MARLIN_EEPROM_SIZE
|
#ifndef MARLIN_EEPROM_SIZE
|
||||||
#define MARLIN_EEPROM_SIZE size_t(E2END + 1)
|
#define MARLIN_EEPROM_SIZE size_t(E2END + 1)
|
||||||
#endif
|
#endif
|
||||||
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
|
size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE - eeprom_exclude_size; }
|
||||||
|
|
||||||
bool PersistentStore::access_start() { return true; }
|
bool PersistentStore::access_start() { return true; }
|
||||||
bool PersistentStore::access_finish() { return true; }
|
bool PersistentStore::access_finish() { return true; }
|
||||||
|
@ -43,7 +43,7 @@ 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) {
|
||||||
uint16_t written = 0;
|
uint16_t written = 0;
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t * const p = (uint8_t * const)pos;
|
uint8_t * const p = (uint8_t * const)REAL_EEPROM_ADDR(pos);
|
||||||
uint8_t v = *value;
|
uint8_t v = *value;
|
||||||
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
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);
|
eeprom_write_byte(p, v);
|
||||||
|
@ -62,7 +62,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*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
do {
|
do {
|
||||||
uint8_t c = eeprom_read_byte((uint8_t*)pos);
|
const uint8_t c = eeprom_read_byte((uint8_t*)REAL_EEPROM_ADDR(pos));
|
||||||
if (writing) *value = c;
|
if (writing) *value = c;
|
||||||
crc16(crc, &c, 1);
|
crc16(crc, &c, 1);
|
||||||
pos++;
|
pos++;
|
||||||
|
|
|
@ -26,6 +26,19 @@
|
||||||
|
|
||||||
#include "../../libs/crc16.h"
|
#include "../../libs/crc16.h"
|
||||||
|
|
||||||
|
// For testing. Define with -DEEPROM_EXCL_ZONE=919,926 in INI files.
|
||||||
|
//#define EEPROM_EXCL_ZONE 919,926 // Test a range
|
||||||
|
//#define EEPROM_EXCL_ZONE 333 // Test a single byte
|
||||||
|
|
||||||
|
#ifdef EEPROM_EXCL_ZONE
|
||||||
|
static constexpr int eeprom_exclude_zone[] = { EEPROM_EXCL_ZONE },
|
||||||
|
eeprom_exclude_size = eeprom_exclude_zone[COUNT(eeprom_exclude_zone) - 1] - eeprom_exclude_zone[0] + 1;
|
||||||
|
#define REAL_EEPROM_ADDR(A) (A < eeprom_exclude_zone[0] ? (A) : (A) + eeprom_exclude_size)
|
||||||
|
#else
|
||||||
|
#define REAL_EEPROM_ADDR(A) (A)
|
||||||
|
static constexpr int eeprom_exclude_size = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
class PersistentStore {
|
class PersistentStore {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
@ -1817,7 +1817,8 @@ void unified_bed_leveling::smart_fill_mesh() {
|
||||||
print_hex_word(i);
|
print_hex_word(i);
|
||||||
SERIAL_ECHOPGM(": ");
|
SERIAL_ECHOPGM(": ");
|
||||||
for (uint16_t j = 0; j < 16; j++) {
|
for (uint16_t j = 0; j < 16; j++) {
|
||||||
persistentStore.read_data(i + j, &cccc, sizeof(uint8_t));
|
int pos = i + j;
|
||||||
|
persistentStore.read_data(pos, &cccc, sizeof(uint8_t));
|
||||||
print_hex_byte(cccc);
|
print_hex_byte(cccc);
|
||||||
SERIAL_CHAR(' ');
|
SERIAL_CHAR(' ');
|
||||||
}
|
}
|
||||||
|
|
|
@ -729,7 +729,8 @@ void MarlinSettings::postprocess() {
|
||||||
|
|
||||||
bool MarlinSettings::sd_update_status() {
|
bool MarlinSettings::sd_update_status() {
|
||||||
uint8_t val;
|
uint8_t val;
|
||||||
persistentStore.read_data(SD_FIRMWARE_UPDATE_EEPROM_ADDR, &val);
|
int pos = SD_FIRMWARE_UPDATE_EEPROM_ADDR;
|
||||||
|
persistentStore.read_data(pos, &val);
|
||||||
return (val == SD_FIRMWARE_UPDATE_ACTIVE_VALUE);
|
return (val == SD_FIRMWARE_UPDATE_ACTIVE_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue