Browse Source

STM32F1 SPI1 bugfix (#14679)

pull/1/head
BigTreeTech 5 years ago
committed by Scott Lahteine
parent
commit
a38b9da672
  1. 5
      Marlin/src/HAL/HAL_STM32F1/HAL.cpp
  2. 14
      Marlin/src/HAL/HAL_STM32F1/HAL_spi_STM32F1.cpp
  3. 2
      Marlin/src/pins/stm32/pins_BIGTREE_SKR_E3_DIP.h
  4. 3
      Marlin/src/pins/stm32/pins_BIGTREE_SKR_MINI_E3.h

5
Marlin/src/HAL/HAL_STM32F1/HAL.cpp

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

14
Marlin/src/HAL/HAL_STM32F1/HAL_spi_STM32F1.cpp

@ -79,15 +79,25 @@ void spiBegin() {
* @details * @details
*/ */
void spiInit(uint8_t spiRate) { void spiInit(uint8_t spiRate) {
/**
* STM32F1 APB1 = 72MHz, APB2 = 36MHz, max SPI speed of this MCU if 18Mhz
* STM32F1 has 3 SPI ports, SPI1 in APB1, SPI2/SPI3 in APB2
* so the minimum prescale of SPI1 is DIV4, SPI2/SPI3 is DIV2
*/
#if SPI_DEVICE == 1
#define SPI_CLOCK_MAX SPI_CLOCK_DIV4
#else
#define SPI_CLOCK_MAX SPI_CLOCK_DIV2
#endif
uint8_t clock; uint8_t clock;
switch (spiRate) { switch (spiRate) {
case SPI_FULL_SPEED: clock = SPI_CLOCK_DIV2 ; break; case SPI_FULL_SPEED: clock = SPI_CLOCK_MAX ; break;
case SPI_HALF_SPEED: clock = SPI_CLOCK_DIV4 ; break; case SPI_HALF_SPEED: clock = SPI_CLOCK_DIV4 ; break;
case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8 ; break; case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8 ; break;
case SPI_EIGHTH_SPEED: clock = SPI_CLOCK_DIV16; break; case SPI_EIGHTH_SPEED: clock = SPI_CLOCK_DIV16; break;
case SPI_SPEED_5: clock = SPI_CLOCK_DIV32; break; case SPI_SPEED_5: clock = SPI_CLOCK_DIV32; break;
case SPI_SPEED_6: clock = SPI_CLOCK_DIV64; break; case SPI_SPEED_6: clock = SPI_CLOCK_DIV64; break;
default: clock = SPI_CLOCK_DIV2; // Default from the SPI library default: clock = SPI_CLOCK_DIV2; // Default from the SPI library
} }
SPI.setModule(SPI_DEVICE); SPI.setModule(SPI_DEVICE);
SPI.begin(); SPI.begin();

2
Marlin/src/pins/stm32/pins_BIGTREE_SKR_E3_DIP.h

@ -148,7 +148,7 @@
// //
// USB connect control // USB connect control
// //
#define USB_CONNECT PC13 #define USB_CONNECT_PIN PC13
#define USB_CONNECT_INVERTING false #define USB_CONNECT_INVERTING false
#define SD_DETECT_PIN PC4 #define SD_DETECT_PIN PC4

3
Marlin/src/pins/stm32/pins_BIGTREE_SKR_MINI_E3.h

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

Loading…
Cancel
Save