Browse Source

Fix SPI, SD for BIGTREETECH SKR Mini (#14287)

3DSmitty 6 years ago
parent
commit
66d51272af

+ 14
- 33
Marlin/src/HAL/HAL_STM32F1/HAL_spi_STM32F1.cpp View File

@@ -36,20 +36,14 @@
36 36
 // Includes
37 37
 // --------------------------------------------------------------------------
38 38
 
39
-#include "HAL.h"
40
-#include "../shared/HAL_SPI.h"
41
-#include "pins_arduino.h"
42
-#include "spi_pins.h"
39
+#include "../../inc/MarlinConfig.h"
43 40
 #include <SPI.h>
44 41
 
45
-#include "../../inc/MarlinConfigPre.h"
46 42
 
47 43
 // --------------------------------------------------------------------------
48 44
 // Public Variables
49 45
 // --------------------------------------------------------------------------
50 46
 
51
-static SPISettings spiConfig;
52
-
53 47
 // --------------------------------------------------------------------------
54 48
 // Public functions
55 49
 // --------------------------------------------------------------------------
@@ -82,8 +76,7 @@ void spiBegin() {
82 76
   #if !PIN_EXISTS(SS)
83 77
     #error "SS_PIN not defined!"
84 78
   #endif
85
-  SET_OUTPUT(SS_PIN);
86
-  WRITE(SS_PIN, HIGH);
79
+  OUT_WRITE(SS_PIN, HIGH);
87 80
 }
88 81
 
89 82
 /**
@@ -105,8 +98,11 @@ void spiInit(uint8_t spiRate) {
105 98
     case SPI_SPEED_6:       clock = SPI_CLOCK_DIV64; break;
106 99
     default:                clock = SPI_CLOCK_DIV2; // Default from the SPI library
107 100
   }
108
-  spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
101
+  SPI.setModule(SPI_DEVICE);
109 102
   SPI.begin();
103
+  SPI.setClockDivider(clock);
104
+  SPI.setBitOrder(MSBFIRST);
105
+  SPI.setDataMode(SPI_MODE0);
110 106
 }
111 107
 
112 108
 /**
@@ -117,9 +113,9 @@ void spiInit(uint8_t spiRate) {
117 113
  * @details
118 114
  */
119 115
 uint8_t spiRec(void) {
120
-  SPI.beginTransaction(spiConfig);
116
+  WRITE(SS_PIN, LOW);
121 117
   uint8_t returnByte = SPI.transfer(0xFF);
122
-  SPI.endTransaction();
118
+  WRITE(SS_PIN, HIGH);
123 119
   return returnByte;
124 120
 }
125 121
 
@@ -133,9 +129,9 @@ uint8_t spiRec(void) {
133 129
  * @details Uses DMA
134 130
  */
135 131
 void spiRead(uint8_t* buf, uint16_t nbyte) {
136
-  SPI.beginTransaction(spiConfig);
132
+  WRITE(SS_PIN, LOW);
137 133
   SPI.dmaTransfer(0, const_cast<uint8_t*>(buf), nbyte);
138
-  SPI.endTransaction();
134
+  WRITE(SS_PIN, HIGH);
139 135
 }
140 136
 
141 137
 /**
@@ -146,9 +142,9 @@ void spiRead(uint8_t* buf, uint16_t nbyte) {
146 142
  * @details
147 143
  */
148 144
 void spiSend(uint8_t b) {
149
-  SPI.beginTransaction(spiConfig);
145
+  WRITE(SS_PIN, LOW);
150 146
   SPI.send(b);
151
-  SPI.endTransaction();
147
+  WRITE(SS_PIN, HIGH);
152 148
 }
153 149
 
154 150
 /**
@@ -160,25 +156,10 @@ void spiSend(uint8_t b) {
160 156
  * @details Use DMA
161 157
  */
162 158
 void spiSendBlock(uint8_t token, const uint8_t* buf) {
163
-  SPI.beginTransaction(spiConfig);
159
+  WRITE(SS_PIN, LOW);
164 160
   SPI.send(token);
165 161
   SPI.dmaSend(const_cast<uint8_t*>(buf), 512);
166
-  SPI.endTransaction();
167
-}
168
-
169
-/**
170
- * @brief  Begin SPI transaction, set clock, bit order, data mode
171
- *
172
- * @param  spiClock   Clock setting
173
- * @param  bitOrder   Bit Order setting
174
- * @param  dataMode   Data Mode setting
175
- * @return Nothing
176
- *
177
- * @details Uses an SPI Config via SPISettings
178
- */
179
-void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
180
-  spiConfig = SPISettings(spiClock, (BitOrder)bitOrder, dataMode);
181
-  SPI.beginTransaction(spiConfig);
162
+  WRITE(SS_PIN, HIGH);
182 163
 }
183 164
 
184 165
 #if ENABLED(SPI_EEPROM)

+ 21
- 5
Marlin/src/HAL/HAL_STM32F1/spi_pins.h View File

@@ -21,13 +21,29 @@
21 21
 /**
22 22
  * HAL for stm32duino.com based on Libmaple and compatible (STM32F1)
23 23
  */
24
-
25 24
 /**
26 25
  * Define SPI Pins: SCK, MISO, MOSI, SS
27 26
  *
28 27
  * Any PIN can be used for Chip Select (SS)
28
+ * 
29
+ * SPI1 is enabled by default
29 30
  */
30
-#define SCK_PIN   PA5
31
-#define MISO_PIN  PA6
32
-#define MOSI_PIN  PA7
33
-#define SS_PIN    PA4
31
+#if ENABLED(ENABLE_SPI3)
32
+  #define SPI_DEVICE 3
33
+  #define SCK_PIN   BOARD_SPI3_SCK_PIN
34
+  #define MISO_PIN  BOARD_SPI3_MISO_PIN
35
+  #define MOSI_PIN  BOARD_SPI3_MOSI_PIN
36
+  #define SS_PIN    BOARD_SPI3_NSS_PIN
37
+#elif ENABLED(ENABLE_SPI2)
38
+  #define SPI_DEVICE 2
39
+  #define SCK_PIN   BOARD_SPI2_SCK_PIN
40
+  #define MISO_PIN  BOARD_SPI2_MISO_PIN
41
+  #define MOSI_PIN  BOARD_SPI2_MOSI_PIN
42
+  #define SS_PIN    BOARD_SPI2_NSS_PIN
43
+#else
44
+  #define SPI_DEVICE 1
45
+  #define SCK_PIN   BOARD_SPI1_SCK_PIN
46
+  #define MISO_PIN  BOARD_SPI1_MISO_PIN
47
+  #define MOSI_PIN  BOARD_SPI1_MOSI_PIN
48
+  #define SS_PIN    BOARD_SPI1_NSS_PIN
49
+#endif

+ 16
- 10
Marlin/src/pins/pins_BIGTREE_SKR_MINI_V1_1.h View File

@@ -28,6 +28,9 @@
28 28
   #define BOARD_NAME "BIGTREE SKR mini V1.1"
29 29
 #endif
30 30
 
31
+  //#define DISABLE_DEBUG
32
+  #define DISABLE_JTAG
33
+
31 34
 // Ignore temp readings during develpment.
32 35
 //#define BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE
33 36
 
@@ -89,14 +92,14 @@
89 92
 //
90 93
 
91 94
 /**
92
- *               _____                                             _____
93
- *           NC | · · | GND                                    5V | · · | GND
94
- *        RESET | · · | 1.31(SD_DETECT)             (LCD_D7) 1.23 | · · | 1.22 (LCD_D6)
95
- *   (MOSI)0.18 | · · | 3.25(BTN_EN2)               (LCD_D5) 1.21 | · · | 1.20 (LCD_D4)
96
- *  (SD_SS)0.16 | · · | 3.26(BTN_EN1)               (LCD_RS) 1.19 | · · | 1.18 (LCD_EN)
97
- *    (SCK)0.15 | · · | 0.17(MISO)                 (BTN_ENC) 0.28 | · · | 1.30 (BEEPER)
98
- *                ̄ ̄                                                ̄ ̄
99
- *               EXP2                                              EXP1
95
+ *                _____                                             _____
96
+ *            NC | · · | GND                                    5V | · · | GND
97
+ *         RESET | · · | PB9 (SD_DETECT)             (LCD_D7) PC14 | · · | PC15 (LCD_D6)
98
+ *  (MOSI)   PB5 | · · | PB8 (BTN_EN2)               (LCD_D5)  PB7 | · · | PC13 (LCD_D4)
99
+ * (SD_SS)  PA15 | · · | PD2 (BTN_EN1)               (LCD_RS) PC12 | · · | PB6  (LCD_EN)
100
+ *   (SCK)   PB3 | · · | PB4 (MISO)                 (BTN_ENC) PC11 | · · | PC10 (BEEPER)
101
+ *                ̄ ̄                                              ̄ ̄
102
+ *                EXP2                                              EXP1
100 103
  */
101 104
 
102 105
 #if ENABLED(ULTRA_LCD)
@@ -123,10 +126,13 @@
123 126
 // SD Card
124 127
 //
125 128
 
126
-// Marlin uses the SD drive attached to the LCD
129
+// By default the onboard SD is enabled. 
130
+// To disable it and use an external SD (connected to LCD)
131
+// enable STM32_SD_LCD.
132
+
127 133
 //#define STM32_SD_LCD
128 134
 
129
-#ifdef STM32_SD_LCD
135
+#if ENABLED(STM32_SD_LCD)
130 136
   #define SD_DETECT_PIN    PB9
131 137
   #define ENABLE_SPI3
132 138
 #else

Loading…
Cancel
Save