From c9c9f28735effa47e610265439d7e2486f10f48d Mon Sep 17 00:00:00 2001 From: ainyan03 <205502311+ainyan03@users.noreply.github.com> Date: Thu, 27 Aug 2026 02:09:52 +0000 Subject: [PATCH] Bus_SPI: restore SPI_USER_REG before releasing the bus lock endTransaction() wrote SPI_USER_REG back to its idle value after spi::endTransaction() had already released the bus mutex. Another task that was blocked on the mutex could therefore have its own transaction configured and running when the late write landed and cleared ck_out_edge, which corrupts the next transfer of a mode 1/2 device sharing the bus (measured on ESP32-S3: same core / same priority as the panel task, ~1 hit per 100k chunks; none with the write moved inside the lock). --- src/lgfx/v1/platforms/esp32/Bus_SPI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp b/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp index c08fb59..3800736 100644 --- a/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp +++ b/src/lgfx/v1/platforms/esp32/Bus_SPI.cpp @@ -566,10 +566,10 @@ namespace lgfx #if defined (LGFX_SPI_CLOCK_TAKEOVER) if (_cfg.use_lock) { spi_clock_restore(this, _cfg.spi_host); } #endif - if (_cfg.use_lock) spi::endTransaction(_cfg.spi_host); #if defined (ARDUINO) // Arduino ESP32 *_spi_user_reg = SPI_USR_MOSI | SPI_USR_MISO | SPI_DOUTDIN; // for other SPI device (e.g. SD card) #endif + if (_cfg.use_lock) spi::endTransaction(_cfg.spi_host); } void Bus_SPI::wait(void)