mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
spi_slave: fix crash issue caused by setting cs to -1
Setting cs num to -1 means cs pin is not connected. But passing the value -1 to the spicommon_cs_initialize() will lead to program crash caused by "array index out of bounds". We expect the driver to execute well but the driver should not be in charge of users' behaviour, so this commit prevents the crash. https://github.com/espressif/esp-idf/issues/5784
This commit is contained in:
parent
c34c961910
commit
1393520e78
@ -124,6 +124,7 @@ esp_err_t spi_slave_initialize(spi_host_device_t host, const spi_bus_config_t *b
|
||||
#ifndef CONFIG_SPI_SLAVE_ISR_IN_IRAM
|
||||
SPI_CHECK((bus_config->intr_flags & ESP_INTR_FLAG_IRAM)==0, "ESP_INTR_FLAG_IRAM should be disabled when CONFIG_SPI_SLAVE_ISR_IN_IRAM is not set.", ESP_ERR_INVALID_ARG);
|
||||
#endif
|
||||
SPI_CHECK(slave_config->spics_io_num < 0 || GPIO_IS_VALID_GPIO(slave_config->spics_io_num), "spics pin invalid", ESP_ERR_INVALID_ARG);
|
||||
|
||||
spi_chan_claimed=spicommon_periph_claim(host, "spi slave");
|
||||
SPI_CHECK(spi_chan_claimed, "host already in use", ESP_ERR_INVALID_STATE);
|
||||
@ -151,7 +152,10 @@ esp_err_t spi_slave_initialize(spi_host_device_t host, const spi_bus_config_t *b
|
||||
ret = err;
|
||||
goto cleanup;
|
||||
}
|
||||
if (slave_config->spics_io_num >= 0) {
|
||||
spicommon_cs_initialize(host, slave_config->spics_io_num, 0, !bus_is_iomux(spihost[host]));
|
||||
}
|
||||
|
||||
// The slave DMA suffers from unexpected transactions. Forbid reading if DMA is enabled by disabling the CS line.
|
||||
if (use_dma) freeze_cs(spihost[host]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user