Merge pull request #7875 from thinkyhead/bf2_fill_eeprom_dat_ff

[2.0.x] Update LPC persistent store to initialize eeprom.dat with FF
This commit is contained in:
Scott Lahteine 2017-10-07 15:13:21 -05:00 committed by GitHub
commit a058638d11

View File

@ -19,14 +19,31 @@ FATFS fat_fs;
FIL eeprom_file; FIL eeprom_file;
bool access_start() { bool access_start() {
UINT file_size = 0,
bytes_written = 0;
const char eeprom_zero = 0xFF;
MSC_Aquire_Lock(); MSC_Aquire_Lock();
if(f_mount(&fat_fs, "", 1)){ if (f_mount(&fat_fs, "", 1)) {
MSC_Release_Lock(); MSC_Release_Lock();
return false; return false;
} }
FRESULT res = f_open(&eeprom_file, "eeprom.dat", FA_OPEN_ALWAYS | FA_WRITE | FA_READ); FRESULT res = f_open(&eeprom_file, "eeprom.dat", FA_OPEN_ALWAYS | FA_WRITE | FA_READ);
if(res) MSC_Release_Lock(); if (res) MSC_Release_Lock();
return (res == FR_OK);
if (res == FR_OK) file_size = f_size(&eeprom_file);
if (res == FR_OK) {
f_lseek(&eeprom_file, file_size);
while (file_size < E2END && res == FR_OK) {
res = f_write(&eeprom_file, &eeprom_zero, 1, &bytes_written);
file_size++;
}
}
if (res == FR_OK) {
f_lseek(&eeprom_file, 0);
f_sync(&eeprom_file);
}
return res == FR_OK;
} }
bool access_finish() { bool access_finish() {