From 96e2a72d7159e6bb2dd449a8390faca97eec409f Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 9 Mar 2023 11:53:16 -0500 Subject: [PATCH] run background tasks during multi-part DMA --- ports/atmel-samd/common-hal/busio/SPI.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c index 720f487bb1..02776928ca 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.c +++ b/ports/atmel-samd/common-hal/busio/SPI.c @@ -271,10 +271,17 @@ bool common_hal_busio_spi_write(busio_spi_obj_t *self, size_t bytes_remaining = len; // Maximum DMA transfer is 65535 - while (bytes_remaining > 0) { + while (1) { size_t to_send = (bytes_remaining > 65535) ? 65535 : bytes_remaining; status = sercom_dma_write(self->spi_desc.dev.prvt, data + (len - bytes_remaining), to_send); bytes_remaining -= to_send; + if (bytes_remaining > 0) { + // Multi-part transfer; let other things run before doing the next chunk. + RUN_BACKGROUND_TASKS; + } else { + // All done. + break; + } } } else { struct io_descriptor *spi_io;