From f40be1f17f3cceb5e44b8035dabc8916d557c3e5 Mon Sep 17 00:00:00 2001 From: Bartosz Bilas Date: Thu, 7 Oct 2021 17:04:28 +0200 Subject: [PATCH] drivers: spi_esp32_spim: initialize all cs gpios during init In case when we have multiple devices connected to the one SPI interface the initial state of CS gpios after MCU reset is floating and it might be low that prevents us from communicating between particular devices. Fix that by initializing all provided cs gpios and setting them as inactive. Signed-off-by: Bartosz Bilas --- drivers/spi/spi_esp32_spim.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi_esp32_spim.c b/drivers/spi/spi_esp32_spim.c index 1079f8e7d63..1022dfefdc9 100644 --- a/drivers/spi/spi_esp32_spim.c +++ b/drivers/spi/spi_esp32_spim.c @@ -131,6 +131,7 @@ static void IRAM_ATTR spi_esp32_isr(void *arg) static int spi_esp32_init(const struct device *dev) { + int err; const struct spi_esp32_config *cfg = dev->config; struct spi_esp32_data *data = dev->data; @@ -146,6 +147,11 @@ static int spi_esp32_init(const struct device *dev) NULL); #endif + err = spi_context_cs_configure_all(&data->ctx); + if (err < 0) { + return err; + } + spi_context_unlock_unconditionally(&data->ctx); return 0; @@ -261,8 +267,6 @@ static int IRAM_ATTR spi_esp32_configure(const struct device *dev, GPIO_OUTPUT | GPIO_ACTIVE_LOW); } - spi_context_cs_configure(&data->ctx); - /* input parameters to calculate timing configuration */ spi_hal_timing_param_t timing_param = { .half_duplex = hal_dev->half_duplex, @@ -411,6 +415,7 @@ static const struct spi_driver_api spi_api = { static struct spi_esp32_data spi_data_##idx = { \ SPI_CONTEXT_INIT_LOCK(spi_data_##idx, ctx), \ SPI_CONTEXT_INIT_SYNC(spi_data_##idx, ctx), \ + SPI_CONTEXT_CS_GPIOS_INITIALIZE(DT_DRV_INST(idx), ctx) \ .hal = { \ .hw = (spi_dev_t *)DT_REG_ADDR(DT_NODELABEL(spi##idx)), \ }, \