summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryangpeng <[email protected]>2024-02-06 13:33:07 +0800
committerMeco Man <[email protected]>2024-02-17 01:07:19 -0500
commit02eaf76d7b9c6ee0f968465cd8837fe5dfa58a83 (patch)
treefca105c4f0456a3f5e1fac4f96f19aba5890f9be
parent0c000b403f73834bb5b2792b96b854bdeadab128 (diff)
[qspi]修复qspi配置未生效问题
-rw-r--r--components/drivers/include/drivers/spi.h5
-rw-r--r--components/drivers/spi/qspi_core.c30
-rw-r--r--components/drivers/spi/spi_core.c40
3 files changed, 45 insertions, 30 deletions
diff --git a/components/drivers/include/drivers/spi.h b/components/drivers/include/drivers/spi.h
index 8ba269f94b..b35c7b30b3 100644
--- a/components/drivers/include/drivers/spi.h
+++ b/components/drivers/include/drivers/spi.h
@@ -181,9 +181,12 @@ rt_err_t rt_spi_bus_attach_device(struct rt_spi_device *device,
rt_err_t rt_spi_bus_attach_device_cspin(struct rt_spi_device *device,
const char *name,
const char *bus_name,
- rt_base_t cs_pin,
+ rt_base_t cs_pin,
void *user_data);
+/* re-configure SPI bus */
+rt_err_t rt_spi_bus_configure(struct rt_spi_device *device);
+
/**
* This function takes SPI bus.
*
diff --git a/components/drivers/spi/qspi_core.c b/components/drivers/spi/qspi_core.c
index 010b427f5f..5d17a085e0 100644
--- a/components/drivers/spi/qspi_core.c
+++ b/components/drivers/spi/qspi_core.c
@@ -15,21 +15,27 @@ 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);
- struct rt_qspi_device *qspi_device = (struct rt_qspi_device *)device;
- rt_err_t result = RT_EOK;
+ /* 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 &&
+ device->config.qspi_dl_width == cfg->qspi_dl_width &&
+ device->config.parent.data_width == cfg->parent.data_width &&
+ device->config.parent.mode == (cfg->parent.mode & RT_SPI_MODE_MASK) &&
+ device->config.parent.max_hz == cfg->parent.max_hz)
+ {
+ return RT_EOK;
+ }
/* copy configuration items */
- qspi_device->config.parent.mode = cfg->parent.mode;
- qspi_device->config.parent.max_hz = cfg->parent.max_hz;
- qspi_device->config.parent.data_width = cfg->parent.data_width;
- qspi_device->config.parent.reserved = cfg->parent.reserved;
- qspi_device->config.medium_size = cfg->medium_size;
- qspi_device->config.ddr_mode = cfg->ddr_mode;
- qspi_device->config.qspi_dl_width = cfg->qspi_dl_width;
+ device->config.parent.mode = cfg->parent.mode;
+ device->config.parent.max_hz = cfg->parent.max_hz;
+ device->config.parent.data_width = cfg->parent.data_width;
+ device->config.parent.reserved = cfg->parent.reserved;
+ device->config.medium_size = cfg->medium_size;
+ device->config.ddr_mode = cfg->ddr_mode;
+ device->config.qspi_dl_width = cfg->qspi_dl_width;
- result = rt_spi_configure(&device->parent, &cfg->parent);
-
- return result;
+ return rt_spi_bus_configure(&device->parent);
}
rt_err_t rt_qspi_bus_register(struct rt_spi_bus *bus, const char *name, const struct rt_spi_ops *ops)
diff --git a/components/drivers/spi/spi_core.c b/components/drivers/spi/spi_core.c
index 3209a54db9..295b7f0296 100644
--- a/components/drivers/spi/spi_core.c
+++ b/components/drivers/spi/spi_core.c
@@ -87,26 +87,10 @@ rt_err_t rt_spi_bus_attach_device(struct rt_spi_device *device,
return rt_spi_bus_attach_device_cspin(device, name, bus_name, PIN_NONE, user_data);
}
-rt_err_t rt_spi_configure(struct rt_spi_device *device,
- struct rt_spi_configuration *cfg)
+rt_err_t rt_spi_bus_configure(struct rt_spi_device *device)
{
rt_err_t result = -RT_ERROR;
- RT_ASSERT(device != RT_NULL);
-
- /* 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) &&
- device->config.max_hz == cfg->max_hz)
- {
- return RT_EOK;
- }
-
- /* set configuration */
- device->config.data_width = cfg->data_width;
- device->config.mode = cfg->mode & RT_SPI_MODE_MASK;
- device->config.max_hz = cfg->max_hz;
-
/* reset the CS pin */
if (device->cs_pin != PIN_NONE)
{
@@ -144,6 +128,28 @@ rt_err_t rt_spi_configure(struct rt_spi_device *device,
return result;
}
+rt_err_t rt_spi_configure(struct rt_spi_device *device,
+ struct rt_spi_configuration *cfg)
+{
+ RT_ASSERT(device != RT_NULL);
+ RT_ASSERT(cfg != RT_NULL);
+
+ /* 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) &&
+ device->config.max_hz == cfg->max_hz)
+ {
+ return RT_EOK;
+ }
+
+ /* set configuration */
+ device->config.data_width = cfg->data_width;
+ device->config.mode = cfg->mode & RT_SPI_MODE_MASK;
+ device->config.max_hz = cfg->max_hz;
+
+ return rt_spi_bus_configure(device);
+}
+
rt_err_t rt_spi_send_then_send(struct rt_spi_device *device,
const void *send_buf1,
rt_size_t send_length1,