Handle word-padded flash-based eeprom (STM32F1)

Fix #13445
This commit is contained in:
Scott Lahteine
2019-03-24 19:10:33 -05:00
parent 32332bcd03
commit 380c771988
3 changed files with 31 additions and 12 deletions

View File

@ -74,7 +74,8 @@ bool PersistentStore::access_start() {
// sector is blank so nothing stored yet
for (int i = 0; i < EEPROM_SIZE; i++) ram_eeprom[i] = EEPROM_ERASE;
current_slot = EEPROM_SLOTS;
} else {
}
else {
// current slot is the first non blank one
current_slot = first_nblank_loc / EEPROM_SIZE;
uint8_t *eeprom_data = SLOT_ADDRESS(EEPROM_SECTOR, current_slot);

View File

@ -79,14 +79,15 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t si
}
// Now, write any remaining single byte
if (size & 1) {
const uint16_t odd = size & 1;
if (odd) {
uint16_t temp = value[size - 1];
status = FLASH_ProgramHalfWord(pageBase + pos + i, temp);
if (status != FLASH_COMPLETE) return true;
}
crc16(crc, value, size);
pos += ((size + 1) & ~1);
pos += size + odd;
return false;
}
@ -97,7 +98,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uin
if (writing) value[i] = c;
crc16(crc, &c, 1);
}
pos += ((size + 1) & ~1);
pos += ((size + 1) & ~1); // i.e., size+(size&1), round up odd values
return false;
}