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
   #if PIN_EXISTS(LED)
201
   #if PIN_EXISTS(LED)
202
     OUT_WRITE(LED_PIN, LOW);
202
     OUT_WRITE(LED_PIN, LOW);
203
   #endif
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
 /* VGPV Done with defines
211
 /* VGPV Done with defines

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

79
  * @details
79
  * @details
80
  */
80
  */
81
 void spiInit(uint8_t spiRate) {
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
   uint8_t  clock;
92
   uint8_t  clock;
83
   switch (spiRate) {
93
   switch (spiRate) {
84
-    case SPI_FULL_SPEED:    clock = SPI_CLOCK_DIV2 ; break;
94
+    case SPI_FULL_SPEED:    clock = SPI_CLOCK_MAX ;  break;
85
     case SPI_HALF_SPEED:    clock = SPI_CLOCK_DIV4 ; break;
95
     case SPI_HALF_SPEED:    clock = SPI_CLOCK_DIV4 ; break;
86
     case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8 ; break;
96
     case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8 ; break;
87
     case SPI_EIGHTH_SPEED:  clock = SPI_CLOCK_DIV16; break;
97
     case SPI_EIGHTH_SPEED:  clock = SPI_CLOCK_DIV16; break;
88
     case SPI_SPEED_5:       clock = SPI_CLOCK_DIV32; break;
98
     case SPI_SPEED_5:       clock = SPI_CLOCK_DIV32; break;
89
     case SPI_SPEED_6:       clock = SPI_CLOCK_DIV64; break;
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
   SPI.setModule(SPI_DEVICE);
102
   SPI.setModule(SPI_DEVICE);
93
   SPI.begin();
103
   SPI.begin();

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

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

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

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

Loading…
Cancel
Save