From a38b9da67286bcb285932d27046c64bded7ab076 Mon Sep 17 00:00:00 2001 From: BigTreeTech <38851044+bigtreetech@users.noreply.github.com> Date: Sun, 21 Jul 2019 09:35:41 +0800 Subject: [PATCH] STM32F1 SPI1 bugfix (#14679) --- Marlin/src/HAL/HAL_STM32F1/HAL.cpp | 5 +++++ Marlin/src/HAL/HAL_STM32F1/HAL_spi_STM32F1.cpp | 14 ++++++++++++-- Marlin/src/pins/stm32/pins_BIGTREE_SKR_E3_DIP.h | 2 +- Marlin/src/pins/stm32/pins_BIGTREE_SKR_MINI_E3.h | 3 ++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL.cpp b/Marlin/src/HAL/HAL_STM32F1/HAL.cpp index 0a58c45d1f..17457343d0 100644 --- a/Marlin/src/HAL/HAL_STM32F1/HAL.cpp +++ b/Marlin/src/HAL/HAL_STM32F1/HAL.cpp @@ -201,6 +201,11 @@ void HAL_init(void) { #if PIN_EXISTS(LED) OUT_WRITE(LED_PIN, LOW); #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 diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_spi_STM32F1.cpp b/Marlin/src/HAL/HAL_STM32F1/HAL_spi_STM32F1.cpp index a0fdf6b65b..ae5681ebef 100644 --- a/Marlin/src/HAL/HAL_STM32F1/HAL_spi_STM32F1.cpp +++ b/Marlin/src/HAL/HAL_STM32F1/HAL_spi_STM32F1.cpp @@ -79,15 +79,25 @@ void spiBegin() { * @details */ 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; 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_QUARTER_SPEED: clock = SPI_CLOCK_DIV8 ; break; case SPI_EIGHTH_SPEED: clock = SPI_CLOCK_DIV16; break; case SPI_SPEED_5: clock = SPI_CLOCK_DIV32; 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.begin(); diff --git a/Marlin/src/pins/stm32/pins_BIGTREE_SKR_E3_DIP.h b/Marlin/src/pins/stm32/pins_BIGTREE_SKR_E3_DIP.h index 5b5d8c3b8c..992c38a39a 100644 --- a/Marlin/src/pins/stm32/pins_BIGTREE_SKR_E3_DIP.h +++ b/Marlin/src/pins/stm32/pins_BIGTREE_SKR_E3_DIP.h @@ -148,7 +148,7 @@ // // USB connect control // -#define USB_CONNECT PC13 +#define USB_CONNECT_PIN PC13 #define USB_CONNECT_INVERTING false #define SD_DETECT_PIN PC4 diff --git a/Marlin/src/pins/stm32/pins_BIGTREE_SKR_MINI_E3.h b/Marlin/src/pins/stm32/pins_BIGTREE_SKR_MINI_E3.h index 5c7fc758bd..57331e65f9 100644 --- a/Marlin/src/pins/stm32/pins_BIGTREE_SKR_MINI_E3.h +++ b/Marlin/src/pins/stm32/pins_BIGTREE_SKR_MINI_E3.h @@ -19,6 +19,7 @@ * along with this program. If not, see . * */ +#pragma once #ifndef TARGET_STM32F1 #error "Oops! Select an STM32F1 board in 'Tools > Board.'" @@ -102,7 +103,7 @@ // // USB connect control // -#define USB_CONNECT PC13 +#define USB_CONNECT_PIN PC13 #define USB_CONNECT_INVERTING false #define SD_DETECT_PIN PC4