Skip to content

Commit 09b46c8

Browse files
committed
drivers: spi: stm32: allow for using soft NSS in peripheral mode
The current stm32 drivers will only enable soft NSS support if the device is using a Zephyr managed GPIO for CS, or if the CONFIG_SPI_STM32_USE_HW_SS flag is set. Neither of these are actually appropriate for a peripheral, which doesn't control CS. With this change, it is possible for the SPI interface to be configured as a peripheral but still use soft NSS -- otherwise, short of creating a "fake" GPIO configuration, the peripheral will always use hard NSS, and for some boards/configurations, that is unworkable. In the case of a board where the CS is not hooked up, we can use soft NSS to allow the peripheral to assume CS and be driven by the SPI clock signal alone. Our board has only three signals (clock, COPI, POCI) enabled on one of the SPI interfaces (it is communicating with another MCU on the same board), and works with this change. Without the change, we must enable a "fake" GPIO driver configuration (which is never used for anything, and really makes little sense for a peripheral, but it just happens to force the driver to go down that code path). We cannot disable the CONFIG_SPI_STM32_USE_HW_SS mechanism, as that impacts ALL interfaces, and we have a second interface in controller mode that speaks to flash and requires the NSS_HARD codepath. Signed-off-by: Rob Newberry <rob@zenomoto.com>
1 parent f0cbba0 commit 09b46c8

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

drivers/spi/spi_ll_stm32.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,11 @@ static int spi_stm32_configure(const struct device *dev,
935935
LL_SPI_SetNSSMode(spi, LL_SPI_NSS_SOFT);
936936
} else {
937937
if ((config->operation & SPI_OP_MODE_SLAVE) != 0U) {
938-
LL_SPI_SetNSSMode(spi, LL_SPI_NSS_HARD_INPUT);
938+
if (cfg->peripheral_use_soft_nss) {
939+
LL_SPI_SetNSSMode(spi, LL_SPI_NSS_SOFT);
940+
} else {
941+
LL_SPI_SetNSSMode(spi, LL_SPI_NSS_HARD_INPUT);
942+
}
939943
} else {
940944
LL_SPI_SetNSSMode(spi, LL_SPI_NSS_HARD_OUTPUT);
941945
}

drivers/spi/spi_ll_stm32.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct spi_stm32_config {
3939
const struct stm32_pclken *pclken;
4040
bool fifo_enabled: 1;
4141
bool ioswp: 1;
42+
bool peripheral_use_soft_nss: 1;
4243
};
4344

4445
#ifdef CONFIG_SPI_STM32_DMA

dts/bindings/spi/st,stm32-spi-common.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ properties:
2121
ioswp:
2222
type: boolean
2323
description: Swap SPI MOSI and MISO pins
24+
25+
periph-use-soft-nss:
26+
type: boolean
27+
description: use soft NSS for this interface when in peripheral mode

0 commit comments

Comments
 (0)