From 9ee947e9b02a93fc114d6a18027f48003f3d4e02 Mon Sep 17 00:00:00 2001 From: LennartF22 <18723691+LennartF22@users.noreply.github.com> Date: Thu, 10 Oct 2024 02:06:51 +0200 Subject: [PATCH] Hotfix to not use DMA on SPI3 of ESP32-S2 See issue #2343. --- lib/SpiManager/src/SpiBus.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/SpiManager/src/SpiBus.cpp b/lib/SpiManager/src/SpiBus.cpp index 0dcb5e4f4..6161507ed 100644 --- a/lib/SpiManager/src/SpiBus.cpp +++ b/lib/SpiManager/src/SpiBus.cpp @@ -18,11 +18,19 @@ SpiBus::SpiBus(const std::string& _id, spi_host_device_t _host_device) .data5_io_num = -1, .data6_io_num = -1, .data7_io_num = -1, - .max_transfer_sz = SPI_MAX_DMA_LEN, + .max_transfer_sz = 0, // defaults to SPI_MAX_DMA_LEN (=4092) or SOC_SPI_MAXIMUM_BUFFER_SIZE (=64) .flags = 0, .intr_flags = 0 }; - ESP_ERROR_CHECK(spi_bus_initialize(host_device, &bus_config, SPI_DMA_CH_AUTO)); + +#if !CONFIG_IDF_TARGET_ESP32S2 + spi_dma_chan_t dma_channel = SPI_DMA_CH_AUTO; +#else + // DMA for SPI3 on ESP32-S2 is shared with ADC/DAC, so we cannot use it here + spi_dma_chan_t dma_channel = (host_device != SPI3_HOST ? SPI_DMA_CH_AUTO : SPI_DMA_DISABLED); +#endif + + ESP_ERROR_CHECK(spi_bus_initialize(host_device, &bus_config, dma_channel)); } SpiBus::~SpiBus()