From 4ea434796bb1f5bcc9d44bfcd0d9d66b8476faa9 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 25 May 2021 23:28:48 -0400 Subject: [PATCH] stm32: Support spi1 on PB4/PB5/PB3 on stm32f103 and stm32f2 Signed-off-by: Kevin O'Connor --- src/stm32/spi.c | 10 +++++----- src/stm32/stm32f1.c | 6 ++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/stm32/spi.c b/src/stm32/spi.c index 3e9ba71a..dec59b08 100644 --- a/src/stm32/spi.c +++ b/src/stm32/spi.c @@ -19,11 +19,11 @@ DECL_ENUMERATION("spi_bus", "spi2", 0); DECL_CONSTANT_STR("BUS_PINS_spi2", "PB14,PB15,PB13"); DECL_ENUMERATION("spi_bus", "spi1", 1); DECL_CONSTANT_STR("BUS_PINS_spi1", "PA6,PA7,PA5"); -#if CONFIG_MACH_STM32F0 || CONFIG_MACH_STM32F4 - DECL_ENUMERATION("spi_bus", "spi2a", 2); +DECL_ENUMERATION("spi_bus", "spi1a", 2); +DECL_CONSTANT_STR("BUS_PINS_spi1a", "PB4,PB5,PB3"); +#if CONFIG_MACH_STM32F0 || CONFIG_MACH_STM32F2 || CONFIG_MACH_STM32F4 + DECL_ENUMERATION("spi_bus", "spi2a", 3); DECL_CONSTANT_STR("BUS_PINS_spi2a", "PC2,PC3,PB10"); - DECL_ENUMERATION("spi_bus", "spi1a", 3); - DECL_CONSTANT_STR("BUS_PINS_spi1a", "PB4,PB5,PB3"); #endif #ifdef SPI3 DECL_ENUMERATION("spi_bus", "spi3", 4); @@ -46,8 +46,8 @@ DECL_CONSTANT_STR("BUS_PINS_spi1", "PA6,PA7,PA5"); static const struct spi_info spi_bus[] = { { SPI2, GPIO('B', 14), GPIO('B', 15), GPIO('B', 13), SPI_FUNCTION }, { SPI1, GPIO('A', 6), GPIO('A', 7), GPIO('A', 5), SPI_FUNCTION }, - { SPI2, GPIO('C', 2), GPIO('C', 3), GPIO('B', 10), SPI_FUNCTION }, { SPI1, GPIO('B', 4), GPIO('B', 5), GPIO('B', 3), SPI_FUNCTION }, + { SPI2, GPIO('C', 2), GPIO('C', 3), GPIO('B', 10), SPI_FUNCTION }, #ifdef SPI3 { SPI3, GPIO('B', 4), GPIO('B', 5), GPIO('B', 3), GPIO_FUNCTION(6) }, #if CONFIG_MACH_STM32F4 diff --git a/src/stm32/stm32f1.c b/src/stm32/stm32f1.c index 57007615..c0ae35fa 100644 --- a/src/stm32/stm32f1.c +++ b/src/stm32/stm32f1.c @@ -154,6 +154,12 @@ gpio_peripheral(uint32_t gpio, uint32_t mode, int pullup) if (gpio == GPIO('B', 8) || gpio == GPIO('B', 9)) stm32f1_alternative_remap(AFIO_MAPR_I2C1_REMAP_Msk, AFIO_MAPR_I2C1_REMAP); + } else if (func == 5) { + // SPI + if (gpio == GPIO('B', 3) || gpio == GPIO('B', 4) + || gpio == GPIO('B', 5)) + stm32f1_alternative_remap(AFIO_MAPR_SPI1_REMAP_Msk, + AFIO_MAPR_SPI1_REMAP); } else if (func == 7) { // USART if (gpio == GPIO('B', 6) || gpio == GPIO('B', 7))