From 781c71fd230e5865a3be666c8a654ae4d974b02c Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Tue, 28 Sep 2021 11:17:04 +0200 Subject: [PATCH 1/2] dts: stm32 spi can configure the frame-format If supported by the SPI instance and soc, this property will configure the frame-format to be compliant with the TI mode. By default, if supported, the frame-format is Motorola mode. Signed-off-by: Francois Ramu --- dts/bindings/spi/st,stm32-spi-common.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/dts/bindings/spi/st,stm32-spi-common.yaml b/dts/bindings/spi/st,stm32-spi-common.yaml index b64d332b86f0c..c742313da1138 100644 --- a/dts/bindings/spi/st,stm32-spi-common.yaml +++ b/dts/bindings/spi/st,stm32-spi-common.yaml @@ -12,6 +12,16 @@ properties: interrupts: required: true + frame-format: + type: boolean + required: false + description: | + Use Frame Format to support TI or motorola SPI mode when the SPI + interface is compatible with the TI protocol. The FRF bit of the + SPIx_CR2 configures the SPI to be compliant with this protocol. + false: SPI Motorola mode (default) + true: SPI TI mode + pinctrl-0: type: phandles required: false From 9b0ca067a16cfd0af48c8790d1dfc8dc402067be Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Tue, 28 Sep 2021 11:30:34 +0200 Subject: [PATCH 2/2] drivers: spi: stm32 can support TI mode for the SPI frame format Depending of the soc and SPI peripheral, the Frame-Format of the SPI can be configured to support TI or Motorola protocol. This is configured through a new DTS property. Signed-off-by: Francois Ramu --- drivers/spi/spi_ll_stm32.c | 15 ++++++++++++++- drivers/spi/spi_ll_stm32.h | 10 ++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi_ll_stm32.c b/drivers/spi/spi_ll_stm32.c index 8d5f07640e015..78f397cfbc5e3 100644 --- a/drivers/spi/spi_ll_stm32.c +++ b/drivers/spi/spi_ll_stm32.c @@ -559,7 +559,11 @@ static int spi_stm32_configure(const struct device *dev, #if !defined(CONFIG_SOC_SERIES_STM32F1X) \ && (!defined(CONFIG_SOC_SERIES_STM32L1X) || defined(SPI_CR2_FRF)) - LL_SPI_SetStandard(spi, LL_SPI_PROTOCOL_MOTOROLA); + if (cfg->ti_mode) { + LL_SPI_SetStandard(spi, LL_SPI_PROTOCOL_TI); + } else { + LL_SPI_SetStandard(spi, LL_SPI_PROTOCOL_MOTOROLA); + } #endif /* At this point, it's mandatory to set this on the context! */ @@ -922,6 +926,14 @@ static void spi_stm32_irq_config_func_##id(const struct device *dev) \ #define SPI_DMA_STATUS_SEM(id) #endif +#if !defined(CONFIG_SOC_SERIES_STM32F1X) \ + && (!defined(CONFIG_SOC_SERIES_STM32L1X) || defined(SPI_CR2_FRF)) +#define STM32_SPI_TI_MODE_CONFIG(id) \ + .ti_mode = DT_INST_PROP(id, frame_format), +#else +#define STM32_SPI_TI_MODE_CONFIG(id) +#endif + #if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_spi_subghz) #define STM32_SPI_USE_SUBGHZSPI_NSS_CONFIG(id) \ .use_subghzspi_nss = DT_INST_PROP_OR( \ @@ -946,6 +958,7 @@ static const struct spi_stm32_config spi_stm32_cfg_##id = { \ .pinctrl_list_size = ARRAY_SIZE(spi_pins_##id), \ STM32_SPI_IRQ_HANDLER_FUNC(id) \ STM32_SPI_USE_SUBGHZSPI_NSS_CONFIG(id) \ + STM32_SPI_TI_MODE_CONFIG(id) \ }; \ \ static struct spi_stm32_data spi_stm32_dev_data_##id = { \ diff --git a/drivers/spi/spi_ll_stm32.h b/drivers/spi/spi_ll_stm32.h index 69f074fc397f8..1d651fe8c3002 100644 --- a/drivers/spi/spi_ll_stm32.h +++ b/drivers/spi/spi_ll_stm32.h @@ -19,6 +19,16 @@ struct spi_stm32_config { #ifdef CONFIG_SPI_STM32_INTERRUPT irq_config_func_t irq_config; #endif + +#if !defined(CONFIG_SOC_SERIES_STM32F1X) \ + && (!defined(CONFIG_SOC_SERIES_STM32L1X) || defined(SPI_CR2_FRF)) + /* + * if supported by the instance, this bit will configure the frame-format + * of the SPI to be compliant with the TI protocol. + */ + bool ti_mode; +#endif + #if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_spi_subghz) bool use_subghzspi_nss; #endif