From 73fcfc5141cbcfdd79ae6d98ac693e5bd1eea5e9 Mon Sep 17 00:00:00 2001 From: 94xhn <87560781+94xhn@users.noreply.github.com> Date: Mon, 20 Jul 2026 13:16:58 +0800 Subject: [PATCH] Fix TMC6200 SPI transaction handling: use endTransaction() not end() readRegister() and writeRegister() both pair spi->beginTransaction() with spi->end() instead of spi->endTransaction(). end() tears down the whole SPI peripheral (spi_deinit on STM32), while endTransaction() just releases the transaction lock. Every other driver in this repo (drv8316, drv832x, drv8376) correctly uses endTransaction() here. On the STM32 Arduino core the effect is worse than just needing a fresh begin() before reusing the bus: SPIClass::beginTransaction() skips re-initializing the hardware whenever the SPISettings object is unchanged from the last call, so the very next TMC6200 register access (e.g. the read-modify-write in setDriverState()) ends up transferring over a peripheral that was just de-initialized by the previous call's end(), with no error raised. Confirmed this by tracing the actual Arduino_Core_STM32 SPI.cpp logic and reproducing the sequence in a small standalone harness. Reported in #66, maintainer agreed with the fix but it was never applied. --- src/drivers/tmc6200/TMC6200.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/drivers/tmc6200/TMC6200.cpp b/src/drivers/tmc6200/TMC6200.cpp index 659ab5d..a0deff1 100644 --- a/src/drivers/tmc6200/TMC6200.cpp +++ b/src/drivers/tmc6200/TMC6200.cpp @@ -180,7 +180,7 @@ uint32_t TMC6200Driver::readRegister(uint8_t addr) { value |= (spi->transfer(0x00) << 8); value |= (spi->transfer(0x00) << 0); - spi->end(); + spi->endTransaction(); digitalWrite(csPin, HIGH); return value; @@ -199,7 +199,7 @@ void TMC6200Driver::writeRegister(uint8_t addr, uint32_t data) { spi->transfer(0xFF & (data >> 8)); spi->transfer(0xFF & (data >> 0)); - spi->end(); + spi->endTransaction(); digitalWrite(csPin, HIGH); }