From 90b5c170347e7a46a8f56628a9830ea5a719a326 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Sun, 6 Jul 2025 07:20:48 +0100 Subject: [PATCH] Fix SPI bus lock issue in spi_start_extended when using mutual exclusion (#25447) --- platforms/chibios/drivers/spi_master.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/platforms/chibios/drivers/spi_master.c b/platforms/chibios/drivers/spi_master.c index f5e48edfda5..84d027bf49d 100644 --- a/platforms/chibios/drivers/spi_master.c +++ b/platforms/chibios/drivers/spi_master.c @@ -130,10 +130,16 @@ bool spi_start_extended(spi_start_config_t *start_config) { #endif // (SPI_USE_MUTUAL_EXCLUSION == TRUE) if (spiStarted) { +#if (SPI_USE_MUTUAL_EXCLUSION == TRUE) + spiReleaseBus(&SPI_DRIVER); +#endif // (SPI_USE_MUTUAL_EXCLUSION == TRUE) return false; } #if SPI_SELECT_MODE != SPI_SELECT_MODE_NONE if (start_config->slave_pin == NO_PIN) { +# if (SPI_USE_MUTUAL_EXCLUSION == TRUE) + spiReleaseBus(&SPI_DRIVER); +# endif // (SPI_USE_MUTUAL_EXCLUSION == TRUE) return false; } #endif @@ -146,10 +152,16 @@ bool spi_start_extended(spi_start_config_t *start_config) { # if defined(AT32F415) if (roundedDivisor < 2 || roundedDivisor > 1024) { +# if (SPI_USE_MUTUAL_EXCLUSION == TRUE) + spiReleaseBus(&SPI_DRIVER); +# endif // (SPI_USE_MUTUAL_EXCLUSION == TRUE) return false; } # else if (roundedDivisor < 2 || roundedDivisor > 256) { +# if (SPI_USE_MUTUAL_EXCLUSION == TRUE) + spiReleaseBus(&SPI_DRIVER); +# endif // (SPI_USE_MUTUAL_EXCLUSION == TRUE) return false; } # endif @@ -234,6 +246,9 @@ bool spi_start_extended(spi_start_config_t *start_config) { } if (start_config->divisor < 1) { +# if (SPI_USE_MUTUAL_EXCLUSION == TRUE) + spiReleaseBus(&SPI_DRIVER); +# endif // (SPI_USE_MUTUAL_EXCLUSION == TRUE) return false; }