Skip to content

Commit 403b109

Browse files
committed
rp2/machine_spi: Don't use DMA for SPI transfers if PSRAM is enabled.
Fixes bug where SPI can freeze if another DMA channel is tranferring to/from PSRAM. Signed-off-by: Dryw Wade <dryw.wade@sparkfun.com>
1 parent 78ff170 commit 403b109

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

ports/rp2/machine_spi.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ static void machine_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj
261261

262262
static void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
263263
machine_spi_obj_t *self = (machine_spi_obj_t *)self_in;
264+
265+
// Fix for #18471
266+
#if !MICROPY_HW_ENABLE_PSRAM
267+
264268
// Use DMA for large transfers if channels are available
265269
const size_t dma_min_size_threshold = 32;
266270
int chan_tx = -1;
@@ -309,13 +313,17 @@ static void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8
309313
dma_channel_unclaim(chan_tx);
310314
}
311315

312-
if (!use_dma) {
313-
// Use software for small transfers, or if couldn't claim two DMA channels
314-
if (write_only) {
315-
spi_write_blocking(self->spi_inst, src, len);
316-
} else {
317-
spi_write_read_blocking(self->spi_inst, src, dest, len);
318-
}
316+
// Return if DMA transfer was used
317+
if (use_dma) {
318+
return;
319+
}
320+
#endif
321+
322+
// Use software transfer
323+
if (write_only) {
324+
spi_write_blocking(self->spi_inst, src, len);
325+
} else {
326+
spi_write_read_blocking(self->spi_inst, src, dest, len);
319327
}
320328
}
321329

0 commit comments

Comments
 (0)