Skip to content

Commit 857cd9f

Browse files
authored
Merge pull request #9845 from jarlamsa/stm_spi_peripheral_name
Add spi_get_peripheral_name() to stm_spi
2 parents 7ed16fb + a9f0924 commit 857cd9f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/TARGET_NUCLEO_F429ZI/PeripheralNames.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ typedef enum {
5757
UART_8 = (int)UART8_BASE
5858
} UARTName;
5959

60+
#define SPI_COUNT 6
6061
typedef enum {
6162
SPI_1 = (int)SPI1_BASE,
6263
SPI_2 = (int)SPI2_BASE,

targets/TARGET_STM/stm_spi_api.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,24 @@ void init_spi(spi_t *obj)
9292
}
9393
}
9494

95+
SPIName spi_get_peripheral_name(PinName mosi, PinName miso, PinName sclk) {
96+
SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI);
97+
SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO);
98+
SPIName spi_sclk = (SPIName)pinmap_peripheral(sclk, PinMap_SPI_SCLK);
99+
100+
SPIName spi_per;
101+
102+
// If 3 wire SPI is used, the miso is not connected.
103+
if (miso == NC) {
104+
spi_per = (SPIName)pinmap_merge(spi_mosi, spi_sclk);
105+
} else {
106+
SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso);
107+
spi_per = (SPIName)pinmap_merge(spi_data, spi_sclk);
108+
}
109+
110+
return spi_per;
111+
}
112+
95113
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
96114
{
97115
struct spi_s *spiobj = SPI_S(obj);

0 commit comments

Comments
 (0)