summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryangpeng <[email protected]>2024-03-04 17:20:24 +0800
committerMeco Man <[email protected]>2024-03-04 19:50:36 -0500
commit1919ad0748601d8898f80b87c4d4ff82f1d33e0a (patch)
tree14d46554939f2099eee6d750d6eae15edd6de948
parent5e892607faa4b74b4f7aeab04ca53aff6b9b6c21 (diff)
[spi]修复spi总线挂载多设备通信可能失败问题
-rw-r--r--components/drivers/spi/qspi_core.c9
-rw-r--r--components/drivers/spi/spi_core.c18
2 files changed, 18 insertions, 9 deletions
diff --git a/components/drivers/spi/qspi_core.c b/components/drivers/spi/qspi_core.c
index 5d17a085e0..cd40c51646 100644
--- a/components/drivers/spi/qspi_core.c
+++ b/components/drivers/spi/qspi_core.c
@@ -15,6 +15,15 @@ rt_err_t rt_qspi_configure(struct rt_qspi_device *device, struct rt_qspi_configu
RT_ASSERT(device != RT_NULL);
RT_ASSERT(cfg != RT_NULL);
+ /* reset the CS pin */
+ if (device->parent.cs_pin != PIN_NONE)
+ {
+ if (cfg->parent.mode & RT_SPI_CS_HIGH)
+ rt_pin_write(device->parent.cs_pin, PIN_LOW);
+ else
+ rt_pin_write(device->parent.cs_pin, PIN_HIGH);
+ }
+
/* If the configurations are the same, we don't need to set again. */
if (device->config.medium_size == cfg->medium_size &&
device->config.ddr_mode == cfg->ddr_mode &&
diff --git a/components/drivers/spi/spi_core.c b/components/drivers/spi/spi_core.c
index 295b7f0296..d9d4221d49 100644
--- a/components/drivers/spi/spi_core.c
+++ b/components/drivers/spi/spi_core.c
@@ -91,15 +91,6 @@ rt_err_t rt_spi_bus_configure(struct rt_spi_device *device)
{
rt_err_t result = -RT_ERROR;
- /* reset the CS pin */
- if (device->cs_pin != PIN_NONE)
- {
- if (device->config.mode & RT_SPI_CS_HIGH)
- rt_pin_write(device->cs_pin, PIN_LOW);
- else
- rt_pin_write(device->cs_pin, PIN_HIGH);
- }
-
if (device->bus != RT_NULL)
{
result = rt_mutex_take(&(device->bus->lock), RT_WAITING_FOREVER);
@@ -134,6 +125,15 @@ rt_err_t rt_spi_configure(struct rt_spi_device *device,
RT_ASSERT(device != RT_NULL);
RT_ASSERT(cfg != RT_NULL);
+ /* reset the CS pin */
+ if (device->cs_pin != PIN_NONE)
+ {
+ if (cfg->mode & RT_SPI_CS_HIGH)
+ rt_pin_write(device->cs_pin, PIN_LOW);
+ else
+ rt_pin_write(device->cs_pin, PIN_HIGH);
+ }
+
/* If the configurations are the same, we don't need to set again. */
if (device->config.data_width == cfg->data_width &&
device->config.mode == (cfg->mode & RT_SPI_MODE_MASK) &&