ソースを参照

STM32F4x SD-based settings storage (#14808)

yangwenxiong 5年前
コミット
6132cf900b

+ 15
- 15
Marlin/src/HAL/HAL_STM32/persistent_store_impl.cpp ファイルの表示

@@ -24,24 +24,24 @@
24 24
 
25 25
 #include "../../inc/MarlinConfig.h"
26 26
 
27
-#if ENABLED(EEPROM_SETTINGS)
27
+#if ENABLED(EEPROM_SETTINGS) && ANY(FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM)
28 28
 
29 29
 #include "../shared/persistent_store_api.h"
30 30
 
31
-#if NONE(SRAM_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM)
31
+#if ENABLED(FLASH_EEPROM_EMULATION)
32 32
   #include <EEPROM.h>
33 33
   static bool eeprom_data_written = false;
34 34
 #endif
35 35
 
36 36
 bool PersistentStore::access_start() {
37
-  #if NONE(SRAM_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM)
37
+  #if ENABLED(FLASH_EEPROM_EMULATION)
38 38
     eeprom_buffer_fill();
39 39
   #endif
40 40
   return true;
41 41
 }
42 42
 
43 43
 bool PersistentStore::access_finish() {
44
-  #if NONE(SRAM_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM)
44
+  #if ENABLED(FLASH_EEPROM_EMULATION)
45 45
     if (eeprom_data_written) {
46 46
       eeprom_buffer_flush();
47 47
       eeprom_data_written = false;
@@ -66,7 +66,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
66 66
           return true;
67 67
         }
68 68
       }
69
-    #elif DISABLED(SRAM_EEPROM_EMULATION)
69
+    #elif ENABLED(FLASH_EEPROM_EMULATION)
70 70
       eeprom_buffered_write_byte(pos, v);
71 71
     #else
72 72
       *(__IO uint8_t *)(BKPSRAM_BASE + (uint8_t * const)pos) = v;
@@ -76,7 +76,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
76 76
     pos++;
77 77
     value++;
78 78
   };
79
-  #if NONE(SRAM_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM)
79
+  #if ENABLED(FLASH_EEPROM_EMULATION)
80 80
     eeprom_data_written = true;
81 81
   #endif
82 82
 
@@ -89,7 +89,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
89 89
     const uint8_t c = (
90 90
       #if EITHER(SPI_EEPROM, I2C_EEPROM)
91 91
         eeprom_read_byte((uint8_t*)pos)
92
-      #elif DISABLED(SRAM_EEPROM_EMULATION)
92
+      #elif ENABLED(FLASH_EEPROM_EMULATION)
93 93
         eeprom_buffered_read_byte(pos)
94 94
       #else
95 95
         (*(__IO uint8_t *)(BKPSRAM_BASE + ((uint8_t*)pos)))
@@ -105,14 +105,14 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
105 105
 }
106 106
 
107 107
 size_t PersistentStore::capacity() {
108
-  #if EITHER(SPI_EEPROM, I2C_EEPROM)
109
-    return E2END + 1;
110
-  #elif DISABLED(SRAM_EEPROM_EMULATION)
111
-    return E2END + 1;
112
-  #else
113
-    return 4096; // 4kB
114
-  #endif
108
+  return (
109
+    #if ENABLED(SRAM_EEPROM_EMULATION)
110
+      4096 // 4kB
111
+    #else
112
+      E2END + 1
113
+    #endif
114
+  );
115 115
 }
116 116
 
117
-#endif // EEPROM_SETTINGS
117
+#endif // EEPROM_SETTINGS && (FLASH_EEPROM_EMULATION || SRAM_EEPROM_EMULATION || SPI_EEPROM || I2C_EEPROM)
118 118
 #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC

+ 104
- 0
Marlin/src/HAL/HAL_STM32/persistent_store_sdcard.cpp ファイルの表示

@@ -0,0 +1,104 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * HAL for stm32duino.com based on Libmaple and compatible (STM32F1)
25
+ * Implementation of EEPROM settings in SD Card
26
+ */
27
+
28
+#ifdef TARGET_STM32F4
29
+
30
+#include "../../inc/MarlinConfig.h"
31
+
32
+#if ENABLED(EEPROM_SETTINGS) && NONE(FLASH_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM)
33
+
34
+#include "../shared/persistent_store_api.h"
35
+
36
+#ifndef E2END
37
+  #define E2END 0xFFF // 4KB
38
+#endif
39
+#define HAL_EEPROM_SIZE (E2END + 1) // 16KB
40
+
41
+#define _ALIGN(x) __attribute__ ((aligned(x))) // SDIO uint32_t* compat.
42
+static char _ALIGN(4) HAL_eeprom_data[HAL_EEPROM_SIZE];
43
+
44
+#if ENABLED(SDSUPPORT)
45
+
46
+  #include "../../sd/cardreader.h"
47
+
48
+  #define EEPROM_FILENAME "eeprom.dat"
49
+
50
+  bool PersistentStore::access_start() {
51
+    if (!card.isDetected()) return false;
52
+
53
+    SdFile file, root = card.getroot();
54
+    if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
55
+      return false;
56
+
57
+    int16_t bytes_read = file.read(HAL_eeprom_data, HAL_STM32F4_EEPROM_SIZE);
58
+    if (bytes_read < 0) return false;
59
+    for (; bytes_read < HAL_STM32F4_EEPROM_SIZE; bytes_read++)
60
+      HAL_eeprom_data[bytes_read] = 0xFF;
61
+    file.close();
62
+    return true;
63
+  }
64
+
65
+  bool PersistentStore::access_finish() {
66
+    if (!card.isDetected()) return false;
67
+
68
+    SdFile file, root = card.getroot();
69
+    int16_t bytes_written = 0;
70
+    if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) {
71
+      bytes_written = file.write(HAL_eeprom_data, HAL_STM32F4_EEPROM_SIZE);
72
+      file.close();
73
+    }
74
+    return (bytes_written == HAL_STM32F4_EEPROM_SIZE);
75
+  }
76
+
77
+#else // !SDSUPPORT
78
+
79
+  #error "Please define SPI_EEPROM (in Configuration.h) or disable EEPROM_SETTINGS."
80
+
81
+#endif // !SDSUPPORT
82
+
83
+bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t size, uint16_t *crc) {
84
+  for (size_t i = 0; i < size; i++)
85
+    HAL_eeprom_data[pos + i] = value[i];
86
+  crc16(crc, value, size);
87
+  pos += size;
88
+  return false;
89
+}
90
+
91
+bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uint16_t *crc, const bool writing/*=true*/) {
92
+  for (size_t i = 0; i < size; i++) {
93
+    uint8_t c = HAL_eeprom_data[pos + i];
94
+    if (writing) value[i] = c;
95
+    crc16(crc, &c, 1);
96
+  }
97
+  pos += size;
98
+  return false;
99
+}
100
+
101
+size_t PersistentStore::capacity() { return HAL_STM32F4_EEPROM_SIZE; }
102
+
103
+#endif // EEPROM_SETTINGS
104
+#endif // __STM32F4__

+ 3
- 1
Marlin/src/pins/stm32/pins_BIGTREE_SKR_PRO_V1.1.h ファイルの表示

@@ -29,7 +29,9 @@
29 29
 
30 30
 #define BOARD_NAME "BIGTREE SKR Pro 1.1"
31 31
 
32
-#define SRAM_EEPROM_EMULATION
32
+// Use one of these or SDCard-based Emulation will be used
33
+//#define SRAM_EEPROM_EMULATION   // Use BackSRAM-based EEPROM emulation
34
+//#define FLASH_EEPROM_EMULATION  // Use Flash-based EEPROM emulation
33 35
 
34 36
 //
35 37
 // Servos

読み込み中…
キャンセル
保存