From 451c1c4b439597b6f4fa6466cb070a0b15aea641 Mon Sep 17 00:00:00 2001 From: Adam Wojasinski Date: Wed, 9 Aug 2023 11:13:39 +0200 Subject: [PATCH] [nrf fromtree] drivers: spi: spi_nrfx_spi: Add CPOL handling on SCK pin Pin state after SPI deinitialization is based on pinctrl configuration. On the other hand, CPOL is set during runtime. When the SPI instance is disabled GPIO takes control over SCK and drives it to state set by pinctrl driver. This might causes an invalid SCK state when the transaction is configured with CPOL (Clock Polarity). To address this issue, a patch was introduced to the SPI driver. Now, when a SPI instance is configured with CPOL, the driver is setting in the runtime the correct state of the SCK pin. Signed-off-by: Adam Wojasinski (cherry picked from commit 9de69aabfddc60c73f8897e38463ef2479201375) --- drivers/spi/spi_nrfx_spi.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/spi/spi_nrfx_spi.c b/drivers/spi/spi_nrfx_spi.c index 75a8745c7d9..825572f3c6d 100644 --- a/drivers/spi/spi_nrfx_spi.c +++ b/drivers/spi/spi_nrfx_spi.c @@ -131,6 +131,9 @@ static int configure(const struct device *dev, config.mode = get_nrf_spi_mode(spi_cfg->operation); config.bit_order = get_nrf_spi_bit_order(spi_cfg->operation); + nrf_gpio_pin_write(nrf_spi_sck_pin_get(dev_config->spi.p_reg), + spi_cfg->operation & SPI_MODE_CPOL ? 1 : 0); + if (dev_data->initialized) { nrfx_spi_uninit(&dev_config->spi); dev_data->initialized = false;