From 75f8e49a9a625778e37f31a40e0f9e98a60ca3a0 Mon Sep 17 00:00:00 2001 From: jflyper Date: Wed, 23 Aug 2017 19:36:21 +0900 Subject: [PATCH] All SPI are fed with same clock (36MHz) on F1 and F3 --- src/main/drivers/bus_spi.c | 6 ++++-- src/main/drivers/bus_spi_ll.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/drivers/bus_spi.c b/src/main/drivers/bus_spi.c index 9def6956e2..be355b4135 100644 --- a/src/main/drivers/bus_spi.c +++ b/src/main/drivers/bus_spi.c @@ -263,16 +263,18 @@ void spiSetDivisor(SPI_TypeDef *instance, uint16_t divisor) { #define BR_BITS ((BIT(5) | BIT(4) | BIT(3))) - // SPI2 and SPI3 are always on APB1/AHB1 which PCLK is half that of APB2/AHB2. +#if !(defined(STM32F1) || defined(STM32F3)) + // SPI2 and SPI3 are on APB1/AHB1 which PCLK is half that of APB2/AHB2. if (instance == SPI2 || instance == SPI3) { divisor /= 2; // Safe for divisor == 0 or 1 } +#endif SPI_Cmd(instance, DISABLE); const uint16_t tempRegister = (instance->CR1 & ~BR_BITS); - instance->CR1 = (tempRegister | ((ffs(divisor | 0x100) - 2) << 3)); + instance->CR1 = tempRegister | (divisor ? ((ffs(divisor | 0x100) - 2) << 3) : 0); SPI_Cmd(instance, ENABLE); diff --git a/src/main/drivers/bus_spi_ll.c b/src/main/drivers/bus_spi_ll.c index 24abef5a91..8bb1ea0477 100644 --- a/src/main/drivers/bus_spi_ll.c +++ b/src/main/drivers/bus_spi_ll.c @@ -302,14 +302,16 @@ bool spiBusTransfer(const busDevice_t *bus, const uint8_t *txData, uint8_t *rxDa void spiSetDivisor(SPI_TypeDef *instance, uint16_t divisor) { - // SPI2 and SPI3 are always on APB1/AHB1 which PCLK is half that of APB2/AHB2. +#if !(defined(STM32F1) || defined(STM32F3)) + // SPI2 and SPI3 are on APB1/AHB1 which PCLK is half that of APB2/AHB2. if (instance == SPI2 || instance == SPI3) { divisor /= 2; // Safe for divisor == 0 or 1 } +#endif LL_SPI_Disable(instance); - LL_SPI_SetBaudRatePrescaler(instance, (ffs(divisor | 0x100) - 2) << SPI_CR1_BR_Pos); + LL_SPI_SetBaudRatePrescaler(instance, divisor ? (ffs(divisor | 0x100) - 2) << SPI_CR1_BR_Pos : 0); LL_SPI_Enable(instance); }