drivers: spi_sam: 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 <bartosz.bilas@hotmail.com>
This commit is contained in:
parent
05f326c96e
commit
61646649a1
1 changed files with 7 additions and 1 deletions
|
@ -103,7 +103,6 @@ static int spi_sam_configure(const struct device *dev,
|
|||
regs->SPI_CR = SPI_CR_SPIEN; /* Enable SPI */
|
||||
|
||||
data->ctx.config = config;
|
||||
spi_context_cs_configure(&data->ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -429,6 +428,7 @@ static int spi_sam_release(const struct device *dev,
|
|||
|
||||
static int spi_sam_init(const struct device *dev)
|
||||
{
|
||||
int err;
|
||||
const struct spi_sam_config *cfg = dev->config;
|
||||
struct spi_sam_data *data = dev->data;
|
||||
|
||||
|
@ -436,6 +436,11 @@ static int spi_sam_init(const struct device *dev)
|
|||
|
||||
soc_gpio_list_configure(cfg->pins, cfg->num_pins);
|
||||
|
||||
err = spi_context_cs_configure_all(&data->ctx);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
spi_context_unlock_unconditionally(&data->ctx);
|
||||
|
||||
/* The device will be configured and enabled when transceive
|
||||
|
@ -466,6 +471,7 @@ static const struct spi_driver_api spi_sam_driver_api = {
|
|||
static struct spi_sam_data spi_sam_dev_data_##n = { \
|
||||
SPI_CONTEXT_INIT_LOCK(spi_sam_dev_data_##n, ctx), \
|
||||
SPI_CONTEXT_INIT_SYNC(spi_sam_dev_data_##n, ctx), \
|
||||
SPI_CONTEXT_CS_GPIOS_INITIALIZE(DT_DRV_INST(n), ctx) \
|
||||
}; \
|
||||
DEVICE_DT_INST_DEFINE(n, &spi_sam_init, NULL, \
|
||||
&spi_sam_dev_data_##n, \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue