STM32: Fix SD EEPROM emulation conflict (#14012)

This commit is contained in:
Tanguy Pruvot 2019-05-15 09:42:10 +02:00 committed by Scott Lahteine
parent 785c01f2bc
commit d7b0369e39
2 changed files with 17 additions and 10 deletions

View file

@ -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);
} }

View file

@ -144,6 +144,7 @@ public:
static card_flags_t flag; static card_flags_t flag;
static char filename[FILENAME_LENGTH], longFilename[LONG_FILENAME_LENGTH]; static char filename[FILENAME_LENGTH], longFilename[LONG_FILENAME_LENGTH];
static int8_t autostart_index; static int8_t autostart_index;
static SdFile getroot() { return root; }
#if ENABLED(BINARY_FILE_TRANSFER) #if ENABLED(BINARY_FILE_TRANSFER)
#if NUM_SERIAL > 1 #if NUM_SERIAL > 1