From 5e8146c2e925a5b634f2bbd5586252d2b2cb9bb5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 4 Jul 2025 00:11:08 +0000 Subject: [PATCH 1/3] Initial plan From 2cb308f2367a495136920406b50eb13de8d351f5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 4 Jul 2025 00:17:40 +0000 Subject: [PATCH 2/3] Fix SPI bus lock issue in spi_start_extended when using mutual exclusion Co-authored-by: tzarc <2985843+tzarc@users.noreply.github.com> --- 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 f5e48edfda..c6032d914d 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; } From a9cab9a9a4d7aa8bef2d1220b12dadb7e1c9dadb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 4 Jul 2025 00:38:25 +0000 Subject: [PATCH 3/3] Fix formatting for preprocessor directives Co-authored-by: tzarc <2985843+tzarc@users.noreply.github.com> --- platforms/chibios/drivers/spi_master.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/platforms/chibios/drivers/spi_master.c b/platforms/chibios/drivers/spi_master.c index c6032d914d..84d027bf49 100644 --- a/platforms/chibios/drivers/spi_master.c +++ b/platforms/chibios/drivers/spi_master.c @@ -137,9 +137,9 @@ bool spi_start_extended(spi_start_config_t *start_config) { } #if SPI_SELECT_MODE != SPI_SELECT_MODE_NONE if (start_config->slave_pin == NO_PIN) { -#if (SPI_USE_MUTUAL_EXCLUSION == TRUE) +# if (SPI_USE_MUTUAL_EXCLUSION == TRUE) spiReleaseBus(&SPI_DRIVER); -#endif // (SPI_USE_MUTUAL_EXCLUSION == TRUE) +# endif // (SPI_USE_MUTUAL_EXCLUSION == TRUE) return false; } #endif @@ -152,16 +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) +# if (SPI_USE_MUTUAL_EXCLUSION == TRUE) spiReleaseBus(&SPI_DRIVER); -#endif // (SPI_USE_MUTUAL_EXCLUSION == TRUE) +# endif // (SPI_USE_MUTUAL_EXCLUSION == TRUE) return false; } # else if (roundedDivisor < 2 || roundedDivisor > 256) { -#if (SPI_USE_MUTUAL_EXCLUSION == TRUE) +# if (SPI_USE_MUTUAL_EXCLUSION == TRUE) spiReleaseBus(&SPI_DRIVER); -#endif // (SPI_USE_MUTUAL_EXCLUSION == TRUE) +# endif // (SPI_USE_MUTUAL_EXCLUSION == TRUE) return false; } # endif @@ -246,9 +246,9 @@ bool spi_start_extended(spi_start_config_t *start_config) { } if (start_config->divisor < 1) { -#if (SPI_USE_MUTUAL_EXCLUSION == TRUE) +# if (SPI_USE_MUTUAL_EXCLUSION == TRUE) spiReleaseBus(&SPI_DRIVER); -#endif // (SPI_USE_MUTUAL_EXCLUSION == TRUE) +# endif // (SPI_USE_MUTUAL_EXCLUSION == TRUE) return false; }