From a9f0924f7bfbc15e60844b0900f6bc3ec5ba8038 Mon Sep 17 00:00:00 2001 From: Jarno Lamsa Date: Thu, 14 Feb 2019 09:30:53 +0200 Subject: [PATCH] Add spi_get_peripheral_name() to stm_spi This is to have support for per-peripheral mutex introduced in https://github.com/ARMmbed/mbed-os/pull/9469 Together fixes an issue seen in https://github.com/ARMmbed/mbed-os/issues/9149 --- .../TARGET_NUCLEO_F429ZI/PeripheralNames.h | 1 + targets/TARGET_STM/stm_spi_api.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/TARGET_NUCLEO_F429ZI/PeripheralNames.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/TARGET_NUCLEO_F429ZI/PeripheralNames.h index d2c2320ba5..773fdfa77f 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/TARGET_NUCLEO_F429ZI/PeripheralNames.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/TARGET_NUCLEO_F429ZI/PeripheralNames.h @@ -57,6 +57,7 @@ typedef enum { UART_8 = (int)UART8_BASE } UARTName; +#define SPI_COUNT 6 typedef enum { SPI_1 = (int)SPI1_BASE, SPI_2 = (int)SPI2_BASE, diff --git a/targets/TARGET_STM/stm_spi_api.c b/targets/TARGET_STM/stm_spi_api.c index 0482a4b11e..5c391ff38e 100644 --- a/targets/TARGET_STM/stm_spi_api.c +++ b/targets/TARGET_STM/stm_spi_api.c @@ -92,6 +92,24 @@ void init_spi(spi_t *obj) } } +SPIName spi_get_peripheral_name(PinName mosi, PinName miso, PinName sclk) { + SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI); + SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO); + SPIName spi_sclk = (SPIName)pinmap_peripheral(sclk, PinMap_SPI_SCLK); + + SPIName spi_per; + + // If 3 wire SPI is used, the miso is not connected. + if (miso == NC) { + spi_per = (SPIName)pinmap_merge(spi_mosi, spi_sclk); + } else { + SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso); + spi_per = (SPIName)pinmap_merge(spi_data, spi_sclk); + } + + return spi_per; +} + void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel) { struct spi_s *spiobj = SPI_S(obj);