Browse Source

Use E2END, if defined, for STM32F1 (SD) (#13981)

Tanguy Pruvot 6 years ago
parent
commit
93dd097b1c
1 changed files with 38 additions and 27 deletions
  1. 38
    27
      Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp

+ 38
- 27
Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp View File

@@ -1,10 +1,9 @@
1 1
 /**
2 2
  * Marlin 3D Printer Firmware
3
- *
4 3
  * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
5
- * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
6
- * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
7
- * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
8 7
  *
9 8
  * This program is free software: you can redistribute it and/or modify
10 9
  * it under the terms of the GNU General Public License as published by
@@ -33,33 +32,45 @@
33 32
 
34 33
 #include "../shared/persistent_store_api.h"
35 34
 
36
-#include "../../sd/cardreader.h"
35
+#ifndef E2END
36
+  #define E2END 4095
37
+#endif
38
+#define HAL_STM32F1_EEPROM_SIZE (E2END + 1)
37 39
 
38
-#define HAL_STM32F1_EEPROM_SIZE 4096
39
-char HAL_STM32F1_eeprom_content[HAL_STM32F1_EEPROM_SIZE];
40
+static char HAL_STM32F1_eeprom_content[HAL_STM32F1_EEPROM_SIZE];
40 41
 
41
-char eeprom_filename[] = "eeprom.dat";
42
+#if ENABLED(SDSUPPORT)
42 43
 
43
-bool PersistentStore::access_start() {
44
-  if (!card.isDetected()) return false;
45
-  int16_t bytes_read = 0;
46
-  constexpr char eeprom_zero = 0xFF;
47
-  card.openFile(eeprom_filename, true);
48
-  bytes_read = card.read(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
49
-  if (bytes_read < 0) return false;
50
-  for (; bytes_read < HAL_STM32F1_EEPROM_SIZE; bytes_read++)
51
-    HAL_STM32F1_eeprom_content[bytes_read] = eeprom_zero;
52
-  card.closefile();
53
-  return true;
54
-}
44
+  #include "../../sd/cardreader.h"
55 45
 
56
-bool PersistentStore::access_finish() {
57
-  if (!card.isDetected()) return false;
58
-  card.openFile(eeprom_filename, false);
59
-  int16_t bytes_written = card.write(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
60
-  card.closefile();
61
-  return (bytes_written == HAL_STM32F1_EEPROM_SIZE);
62
-}
46
+  static const char eeprom_filename[] = "eeprom.dat";
47
+
48
+  bool PersistentStore::access_start() {
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);
54
+    if (bytes_read < 0) return false;
55
+    for (; bytes_read < HAL_STM32F1_EEPROM_SIZE; bytes_read++)
56
+      HAL_STM32F1_eeprom_content[bytes_read] = eeprom_zero;
57
+    card.closefile();
58
+    return true;
59
+  }
60
+
61
+  bool PersistentStore::access_finish() {
62
+    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();
66
+    return (bytes_written == HAL_STM32F1_EEPROM_SIZE);
67
+  }
68
+
69
+#else // !SDSUPPORT
70
+
71
+  #error "Please define SPI_EEPROM (in Configuration.h) or disable EEPROM_SETTINGS."
72
+
73
+#endif // !SDSUPPORT
63 74
 
64 75
 bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t size, uint16_t *crc) {
65 76
   for (size_t i = 0; i < size; i++)

Loading…
Cancel
Save