From d65a74e2dd0846cd46ec8cd7fcfb3fcb84b54587 Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Thu, 2 Dec 2021 18:27:30 +0100 Subject: [PATCH] drivers: spi: stm32 spi drivers supports the frame format the stm32 spi drivers now takes the DTS frame_format property from the include/ drivers/spi.h It will be possible to select the Motorola (default) or TI from the DTS entry of the device, when soc supports it, else a run time error is raised. Signed-off-by: Francois Ramu --- drivers/spi/spi_ll_stm32.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi_ll_stm32.c b/drivers/spi/spi_ll_stm32.c index 49902086575..2e168d0bdfb 100644 --- a/drivers/spi/spi_ll_stm32.c +++ b/drivers/spi/spi_ll_stm32.c @@ -480,6 +480,21 @@ static int spi_stm32_configure(const struct device *dev, return -ENOTSUP; } + /* configure the frame format Motorola (default) or TI */ + if ((config->operation & SPI_FRAME_FORMAT_TI) == SPI_FRAME_FORMAT_TI) { +#ifdef LL_SPI_PROTOCOL_TI + LL_SPI_SetStandard(spi, LL_SPI_PROTOCOL_TI); +#else + LOG_ERR("Frame Format TI not supported"); + /* on stm32F1 or some stm32L1 (cat1,2) without SPI_CR2_FRF */ + return -ENOTSUP; +#endif +#if defined(LL_SPI_PROTOCOL_MOTOROLA) && defined(SPI_CR2_FRF) + } else { + LL_SPI_SetStandard(spi, LL_SPI_PROTOCOL_MOTOROLA); +#endif +} + if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE), (clock_control_subsys_t) &cfg->pclken, &clock) < 0) { LOG_ERR("Failed call clock_control_get_rate"); @@ -561,11 +576,6 @@ static int spi_stm32_configure(const struct device *dev, ll_func_set_fifo_threshold_8bit(spi); #endif -#if !defined(CONFIG_SOC_SERIES_STM32F1X) \ - && (!defined(CONFIG_SOC_SERIES_STM32L1X) || defined(SPI_CR2_FRF)) - LL_SPI_SetStandard(spi, LL_SPI_PROTOCOL_MOTOROLA); -#endif - /* At this point, it's mandatory to set this on the context! */ data->ctx.config = config;