Browse Source

STM32: Fix SD EEPROM emulation conflict (#14012)

Tanguy Pruvot 6 years ago
parent
commit
d7b0369e39
2 changed files with 17 additions and 10 deletions
  1. 16
    10
      Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp
  2. 1
    0
      Marlin/src/sd/cardreader.h

+ 16
- 10
Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp View File

@@ -43,26 +43,32 @@ static char HAL_STM32F1_eeprom_content[HAL_STM32F1_EEPROM_SIZE];
43 43
 
44 44
   #include "../../sd/cardreader.h"
45 45
 
46
-  static char eeprom_filename[] = "eeprom.dat";
46
+  #define EEPROM_FILENAME "eeprom.dat"
47 47
 
48 48
   bool PersistentStore::access_start() {
49 49
     if (!card.isDetected()) return false;
50
-    int16_t bytes_read = 0;
51
-    constexpr char eeprom_zero = 0xFF;
52
-    card.openFile(eeprom_filename, true);
53
-    bytes_read = card.read(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
50
+
51
+    SdFile file, root = card.getroot();
52
+    if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
53
+      return false;
54
+
55
+    int16_t bytes_read = file.read(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
54 56
     if (bytes_read < 0) return false;
55 57
     for (; bytes_read < HAL_STM32F1_EEPROM_SIZE; bytes_read++)
56
-      HAL_STM32F1_eeprom_content[bytes_read] = eeprom_zero;
57
-    card.closefile();
58
+      HAL_STM32F1_eeprom_content[bytes_read] = 0xFF;
59
+    file.close();
58 60
     return true;
59 61
   }
60 62
 
61 63
   bool PersistentStore::access_finish() {
62 64
     if (!card.isDetected()) return false;
63
-    card.openFile(eeprom_filename, false);
64
-    int16_t bytes_written = card.write(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
65
-    card.closefile();
65
+
66
+    SdFile file, root = card.getroot();
67
+    if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC))
68
+      return false;
69
+
70
+    int16_t bytes_written = file.write(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
71
+    file.close();
66 72
     return (bytes_written == HAL_STM32F1_EEPROM_SIZE);
67 73
   }
68 74
 

+ 1
- 0
Marlin/src/sd/cardreader.h View File

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

Loading…
Cancel
Save