gcode_D EEPROM size, cleanup

Fixes #19920

Co-Authored-By: Orel <37673727+0r31@users.noreply.github.com>
This commit is contained in:
Scott Lahteine 2020-10-29 17:33:59 -05:00
parent 3dbe4ac593
commit 2774b70fbf
25 changed files with 42 additions and 52 deletions

View file

@ -59,7 +59,7 @@ 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, 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); uint8_t c = eeprom_read_byte((uint8_t*)pos);
if (writing) *value = c; if (writing) *value = c;

View file

@ -996,7 +996,7 @@ 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, 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(pos));
if (writing) *value = c; if (writing) *value = c;

View file

@ -62,7 +62,7 @@ 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, 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); uint8_t c = eeprom_read_byte((uint8_t*)pos);
if (writing) *value = c; if (writing) *value = c;

View file

@ -44,7 +44,7 @@ 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, 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++); uint8_t c = EEPROM.read(pos++);
if (writing) value[i] = c; if (writing) value[i] = c;

View file

@ -78,7 +78,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return (bytes_written != size); // return true for any error return (bytes_written != size); // return true for any error
} }
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*/) {
std::size_t bytes_read = 0; std::size_t bytes_read = 0;
if (writing) { if (writing) {
for (std::size_t i = 0; i < size; i++) { for (std::size_t i = 0; i < size; i++) {

View file

@ -119,7 +119,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; // return true for any error return false; // return true for any error
} }
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 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[pos + i];
crc16(crc, buff, size); crc16(crc, buff, size);

View file

@ -143,7 +143,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return bytes_written != size; // return true for any error return bytes_written != size; // return true for any error
} }
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*/) {
if (!eeprom_file_open) return true; if (!eeprom_file_open) return true;
UINT bytes_read = 0; UINT bytes_read = 0;
FRESULT s; FRESULT s;

View file

@ -64,7 +64,7 @@ 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, 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*)pos);

View file

@ -79,7 +79,7 @@ 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, 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--) {
SYNC(NVMCTRL->SEESTAT.bit.BUSY); SYNC(NVMCTRL->SEESTAT.bit.BUSY);
uint8_t c = ((volatile uint8_t *)SEEPROM_ADDR)[pos]; uint8_t c = ((volatile uint8_t *)SEEPROM_ADDR)[pos];

View file

@ -56,7 +56,7 @@ 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, 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); uint8_t c = qspi.readByte(pos);
if (writing) *value = c; if (writing) *value = c;

View file

@ -59,7 +59,7 @@ 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, 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); uint8_t c = eeprom_read_byte((uint8_t*)pos);
if (writing) *value = c; if (writing) *value = c;

View file

@ -261,7 +261,7 @@ 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, 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 uint8_t c = TERN(FLASH_EEPROM_LEVELING, ram_eeprom[pos], eeprom_buffered_read_byte(pos));
if (writing) *value = c; if (writing) *value = c;

View file

@ -78,7 +78,7 @@ 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, 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]; uint8_t c = HAL_eeprom_data[pos + i];
if (writing) value[i] = c; if (writing) value[i] = c;

View file

@ -52,7 +52,7 @@ 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, 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 = ( *(__IO uint8_t *)(BKPSRAM_BASE + ((uint8_t*)pos)) ); const uint8_t c = ( *(__IO uint8_t *)(BKPSRAM_BASE + ((uint8_t*)pos)) );

View file

@ -65,7 +65,7 @@ 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, 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*)pos);

View file

@ -68,7 +68,7 @@ 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, 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; uint8_t * const p = (uint8_t * const)pos;
uint8_t c = eeprom_read_byte(p); uint8_t c = eeprom_read_byte(p);

View file

@ -101,7 +101,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
return false; // return true for any error return false; // return true for any error
} }
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*/) {
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[pos + i];
crc16(crc, buff, size); crc16(crc, buff, size);

View file

@ -79,7 +79,7 @@ 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, 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]; uint8_t c = HAL_eeprom_data[pos + i];
if (writing) value[i] = c; if (writing) value[i] = c;

View file

@ -72,7 +72,7 @@ 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, 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); uint8_t c = eeprom_read_byte((uint8_t*)pos);
if (writing && value) *value = c; if (writing && value) *value = c;

View file

@ -96,7 +96,7 @@ 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, 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_byte((uint8_t*)pos); uint8_t c = ee_read_byte((uint8_t*)pos);
if (writing) *value = c; if (writing) *value = c;

View file

@ -62,7 +62,7 @@ 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, 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); uint8_t c = eeprom_read_byte((uint8_t*)pos);
if (writing) *value = c; if (writing) *value = c;

View file

@ -57,7 +57,7 @@ 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, 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); uint8_t c = eeprom_read_byte((uint8_t*)pos);
if (writing) *value = c; if (writing) *value = c;

View file

@ -61,7 +61,7 @@ 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, 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); uint8_t c = eeprom_read_byte((uint8_t*)pos);
if (writing) *value = c; if (writing) *value = c;

View file

@ -61,7 +61,7 @@ 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, 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); uint8_t c = eeprom_read_byte((uint8_t*)pos);
if (writing) *value = c; if (writing) *value = c;

View file

@ -54,9 +54,7 @@
size_t total = persistentStore.capacity(); size_t total = persistentStore.capacity();
int pos = 0; int pos = 0;
const uint8_t value = 0x0; const uint8_t value = 0x0;
while(total--) { while (total--) persistentStore.write_data(pos, &value, 1);
persistentStore.write_data(pos, &value, 1);
}
persistentStore.access_finish(); persistentStore.access_finish();
#else #else
settings.reset(); settings.reset();
@ -70,7 +68,7 @@
uint8_t *pointer = parser.hex_adr_val('A'); uint8_t *pointer = parser.hex_adr_val('A');
uint16_t len = parser.ushortval('C', 1); uint16_t len = parser.ushortval('C', 1);
uintptr_t addr = (uintptr_t)pointer; uintptr_t addr = (uintptr_t)pointer;
NOMORE(addr, (size_t)(SRAM_SIZE - 1)); NOMORE(addr, size_t(SRAM_SIZE - 1));
NOMORE(len, SRAM_SIZE - addr); NOMORE(len, SRAM_SIZE - addr);
if (parser.seenval('X')) { if (parser.seenval('X')) {
// Write the hex bytes after the X // Write the hex bytes after the X
@ -91,16 +89,13 @@
uint8_t *pointer = parser.hex_adr_val('A'); uint8_t *pointer = parser.hex_adr_val('A');
uint16_t len = parser.ushortval('C', 1); uint16_t len = parser.ushortval('C', 1);
uintptr_t addr = (uintptr_t)pointer; uintptr_t addr = (uintptr_t)pointer;
#ifndef MARLIN_EEPROM_SIZE NOMORE(addr, size_t(persistentStore.capacity() - 1));
#define MARLIN_EEPROM_SIZE size_t(E2END + 1) NOMORE(len, persistentStore.capacity() - addr);
#endif
NOMORE(addr, (size_t)(MARLIN_EEPROM_SIZE - 1));
NOMORE(len, MARLIN_EEPROM_SIZE - addr);
if (parser.seenval('X')) { if (parser.seenval('X')) {
uint16_t val = parser.hex_val('X'); uint16_t val = parser.hex_val('X');
#if ENABLED(EEPROM_SETTINGS) #if ENABLED(EEPROM_SETTINGS)
persistentStore.access_start(); persistentStore.access_start();
while(len--) { while (len--) {
int pos = 0; int pos = 0;
persistentStore.write_data(pos, (uint8_t *)&val, sizeof(val)); persistentStore.write_data(pos, (uint8_t *)&val, sizeof(val));
} }
@ -111,23 +106,18 @@
#endif #endif
} }
else { else {
while (len--) {
// Read bytes from EEPROM // Read bytes from EEPROM
#if ENABLED(EEPROM_SETTINGS) #if ENABLED(EEPROM_SETTINGS)
persistentStore.access_start(); persistentStore.access_start();
uint8_t val;
while(len--) {
int pos = 0; int pos = 0;
if (!persistentStore.read_data(pos, (uint8_t *)&val, sizeof(val))) { uint8_t val;
print_hex_byte(val); while (len--) if (!persistentStore.read_data(pos, &val, 1)) print_hex_byte(val);
}
}
SERIAL_EOL(); SERIAL_EOL();
persistentStore.access_finish(); persistentStore.access_finish();
#else #else
SERIAL_ECHOLNPGM("NO EEPROM"); SERIAL_ECHOLNPGM("NO EEPROM");
len = 0;
#endif #endif
}
SERIAL_EOL(); SERIAL_EOL();
} }
} break; } break;
@ -156,7 +146,7 @@
uint8_t *pointer = parser.hex_adr_val('A'); uint8_t *pointer = parser.hex_adr_val('A');
uint16_t len = parser.ushortval('C', 1); uint16_t len = parser.ushortval('C', 1);
uintptr_t addr = (uintptr_t)pointer; uintptr_t addr = (uintptr_t)pointer;
NOMORE(addr, (size_t)(FLASH_SIZE - 1)); NOMORE(addr, size_t(FLASH_SIZE - 1));
NOMORE(len, FLASH_SIZE - addr); NOMORE(len, FLASH_SIZE - addr);
if (parser.seenval('X')) { if (parser.seenval('X')) {
// TODO: Write the hex bytes after the X // TODO: Write the hex bytes after the X