From 7fb0c79ff4c1e1870c4f64acac4aa0baf54a51e9 Mon Sep 17 00:00:00 2001 From: Martin Luessi Date: Sat, 16 Apr 2022 08:39:50 -0700 Subject: [PATCH] Fix SPI LL Segment Repetition --- src/main/drivers/bus_spi_ll.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/drivers/bus_spi_ll.c b/src/main/drivers/bus_spi_ll.c index ec5a70c0b..b7f8963b8 100644 --- a/src/main/drivers/bus_spi_ll.c +++ b/src/main/drivers/bus_spi_ll.c @@ -644,6 +644,7 @@ void spiSequenceStart(const extDevice_t *dev) spiInternalStartDMA(dev); } else { busSegment_t *lastSegment = NULL; + bool segmentComplete; // Manually work through the segment list performing a transfer for each while (bus->curSegment->len) { @@ -663,15 +664,17 @@ void spiSequenceStart(const extDevice_t *dev) IOHi(dev->busType_u.spi.csnPin); } + segmentComplete = true; if (bus->curSegment->callback) { switch(bus->curSegment->callback(dev->callbackArg)) { case BUS_BUSY: // Repeat the last DMA segment - bus->curSegment--; + segmentComplete = false; break; case BUS_ABORT: bus->curSegment = (busSegment_t *)BUS_SPI_FREE; + segmentComplete = false; return; case BUS_READY: @@ -680,8 +683,10 @@ void spiSequenceStart(const extDevice_t *dev) break; } } - lastSegment = (busSegment_t *)bus->curSegment; - bus->curSegment++; + if (segmentComplete) { + lastSegment = (busSegment_t *)bus->curSegment; + bus->curSegment++; + } } if (lastSegment && !lastSegment->negateCS) { -- 2.11.4.GIT