Browse Source

Merge pull request #7875 from thinkyhead/bf2_fill_eeprom_dat_ff

[2.0.x] Update LPC persistent store to initialize eeprom.dat with FF
Scott Lahteine 7 years ago
parent
commit
a058638d11
1 changed files with 20 additions and 3 deletions
  1. 20
    3
      Marlin/src/HAL/HAL_LPC1768/persistent_store_impl.cpp

+ 20
- 3
Marlin/src/HAL/HAL_LPC1768/persistent_store_impl.cpp View File

@@ -19,14 +19,31 @@ FATFS fat_fs;
19 19
 FIL eeprom_file;
20 20
 
21 21
 bool access_start() {
22
+  UINT file_size = 0,
23
+       bytes_written = 0;
24
+  const char eeprom_zero = 0xFF;
22 25
   MSC_Aquire_Lock();
23
-  if(f_mount(&fat_fs, "", 1)){
26
+  if (f_mount(&fat_fs, "", 1)) {
24 27
     MSC_Release_Lock();
25 28
     return false;
26 29
   }
27 30
   FRESULT res = f_open(&eeprom_file, "eeprom.dat", FA_OPEN_ALWAYS | FA_WRITE | FA_READ);
28
-  if(res) MSC_Release_Lock();
29
-  return (res == FR_OK);
31
+  if (res) MSC_Release_Lock();
32
+
33
+  if (res == FR_OK) file_size = f_size(&eeprom_file);
34
+
35
+  if (res == FR_OK) {
36
+    f_lseek(&eeprom_file, file_size);
37
+    while (file_size < E2END && res == FR_OK) {
38
+      res = f_write(&eeprom_file, &eeprom_zero, 1, &bytes_written);
39
+      file_size++;
40
+    }
41
+  }
42
+  if (res == FR_OK) {
43
+    f_lseek(&eeprom_file, 0);
44
+    f_sync(&eeprom_file);
45
+  }
46
+  return res == FR_OK;
30 47
 }
31 48
 
32 49
 bool access_finish() {

Loading…
Cancel
Save