Browse Source

STM32F1 SPI1 bugfix (#14679)

BigTreeTech 5 years ago
parent
commit
a38b9da672

+ 5
- 0
Marlin/src/HAL/HAL_STM32F1/HAL.cpp View File

@@ -201,6 +201,11 @@ void HAL_init(void) {
201 201
   #if PIN_EXISTS(LED)
202 202
     OUT_WRITE(LED_PIN, LOW);
203 203
   #endif
204
+  #if PIN_EXISTS(USB_CONNECT)
205
+    OUT_WRITE(USB_CONNECT_PIN, !USB_CONNECT_INVERTING);  // USB clear connection
206
+    delay(1000);                                         // Give OS time to notice
207
+    OUT_WRITE(USB_CONNECT_PIN, USB_CONNECT_INVERTING);
208
+  #endif
204 209
 }
205 210
 
206 211
 /* VGPV Done with defines

+ 12
- 2
Marlin/src/HAL/HAL_STM32F1/HAL_spi_STM32F1.cpp View File

@@ -79,15 +79,25 @@ void spiBegin() {
79 79
  * @details
80 80
  */
81 81
 void spiInit(uint8_t spiRate) {
82
+  /**
83
+   * STM32F1 APB1 = 72MHz, APB2 = 36MHz, max SPI speed of this MCU if 18Mhz 
84
+   * STM32F1 has 3 SPI ports, SPI1 in APB1, SPI2/SPI3 in APB2
85
+   * so the minimum prescale of SPI1 is DIV4, SPI2/SPI3 is DIV2
86
+   */
87
+  #if SPI_DEVICE == 1
88
+    #define SPI_CLOCK_MAX SPI_CLOCK_DIV4
89
+  #else
90
+    #define SPI_CLOCK_MAX SPI_CLOCK_DIV2
91
+  #endif
82 92
   uint8_t  clock;
83 93
   switch (spiRate) {
84
-    case SPI_FULL_SPEED:    clock = SPI_CLOCK_DIV2 ; break;
94
+    case SPI_FULL_SPEED:    clock = SPI_CLOCK_MAX ;  break;
85 95
     case SPI_HALF_SPEED:    clock = SPI_CLOCK_DIV4 ; break;
86 96
     case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8 ; break;
87 97
     case SPI_EIGHTH_SPEED:  clock = SPI_CLOCK_DIV16; break;
88 98
     case SPI_SPEED_5:       clock = SPI_CLOCK_DIV32; break;
89 99
     case SPI_SPEED_6:       clock = SPI_CLOCK_DIV64; break;
90
-    default:                clock = SPI_CLOCK_DIV2; // Default from the SPI library
100
+    default:                clock = SPI_CLOCK_DIV2;  // Default from the SPI library
91 101
   }
92 102
   SPI.setModule(SPI_DEVICE);
93 103
   SPI.begin();

+ 1
- 1
Marlin/src/pins/stm32/pins_BIGTREE_SKR_E3_DIP.h View File

@@ -148,7 +148,7 @@
148 148
 //
149 149
 // USB connect control
150 150
 //
151
-#define USB_CONNECT        PC13
151
+#define USB_CONNECT_PIN    PC13
152 152
 #define USB_CONNECT_INVERTING false
153 153
 
154 154
 #define SD_DETECT_PIN      PC4

+ 2
- 1
Marlin/src/pins/stm32/pins_BIGTREE_SKR_MINI_E3.h View File

@@ -19,6 +19,7 @@
19 19
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 20
  *
21 21
  */
22
+#pragma once
22 23
 
23 24
 #ifndef TARGET_STM32F1
24 25
   #error "Oops! Select an STM32F1 board in 'Tools > Board.'"
@@ -102,7 +103,7 @@
102 103
 //
103 104
 // USB connect control
104 105
 //
105
-#define USB_CONNECT        PC13
106
+#define USB_CONNECT_PIN    PC13
106 107
 #define USB_CONNECT_INVERTING false
107 108
 
108 109
 #define SD_DETECT_PIN      PC4

Loading…
Cancel
Save