|
@ -43,26 +43,32 @@ static char HAL_STM32F1_eeprom_content[HAL_STM32F1_EEPROM_SIZE]; |
|
|
|
|
|
|
|
|
#include "../../sd/cardreader.h" |
|
|
#include "../../sd/cardreader.h" |
|
|
|
|
|
|
|
|
static char eeprom_filename[] = "eeprom.dat"; |
|
|
#define EEPROM_FILENAME "eeprom.dat" |
|
|
|
|
|
|
|
|
bool PersistentStore::access_start() { |
|
|
bool PersistentStore::access_start() { |
|
|
if (!card.isDetected()) return false; |
|
|
if (!card.isDetected()) return false; |
|
|
int16_t bytes_read = 0; |
|
|
|
|
|
constexpr char eeprom_zero = 0xFF; |
|
|
SdFile file, root = card.getroot(); |
|
|
card.openFile(eeprom_filename, true); |
|
|
if (!file.open(&root, EEPROM_FILENAME, O_RDONLY)) |
|
|
bytes_read = card.read(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE); |
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
int16_t bytes_read = file.read(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE); |
|
|
if (bytes_read < 0) return false; |
|
|
if (bytes_read < 0) return false; |
|
|
for (; bytes_read < HAL_STM32F1_EEPROM_SIZE; bytes_read++) |
|
|
for (; bytes_read < HAL_STM32F1_EEPROM_SIZE; bytes_read++) |
|
|
HAL_STM32F1_eeprom_content[bytes_read] = eeprom_zero; |
|
|
HAL_STM32F1_eeprom_content[bytes_read] = 0xFF; |
|
|
card.closefile(); |
|
|
file.close(); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool PersistentStore::access_finish() { |
|
|
bool PersistentStore::access_finish() { |
|
|
if (!card.isDetected()) return false; |
|
|
if (!card.isDetected()) return false; |
|
|
card.openFile(eeprom_filename, false); |
|
|
|
|
|
int16_t bytes_written = card.write(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE); |
|
|
SdFile file, root = card.getroot(); |
|
|
card.closefile(); |
|
|
if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) |
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
int16_t bytes_written = file.write(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE); |
|
|
|
|
|
file.close(); |
|
|
return (bytes_written == HAL_STM32F1_EEPROM_SIZE); |
|
|
return (bytes_written == HAL_STM32F1_EEPROM_SIZE); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|