Skip to content

[spi]修复spi总线挂载多设备通信可能失败问题 #8578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions components/drivers/spi/qspi_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
18 changes: 9 additions & 9 deletions components/drivers/spi/spi_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) &&
Expand Down