Skip to content

Commit 91f6426

Browse files
committed
Fix DVI blanking during SPI transactions
SPI was using DMA to transfer to PSRAM. When a cache miss occurs, the DMA can't switch to another transfer and throws off DVI timing. So, only use DMA with SPI when the buffers are in SRAM. This will slow down SPI transactions when the FIFOs are empty and the CPU is busy running a background task. It will still be correct though since we control the SPI clock. Fixes #10557
1 parent edc82dd commit 91f6426

File tree

1 file changed

+4
-1
lines changed
  • ports/raspberrypi/common-hal/busio

1 file changed

+4
-1
lines changed

ports/raspberrypi/common-hal/busio/SPI.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,10 @@ static bool _transfer(busio_spi_obj_t *self,
182182
chan_tx = dma_claim_unused_channel(false);
183183
chan_rx = dma_claim_unused_channel(false);
184184
}
185-
bool use_dma = chan_rx >= 0 && chan_tx >= 0;
185+
bool has_dma_channels = chan_rx >= 0 && chan_tx >= 0;
186+
// Only use DMA if both data buffers are in SRAM. Otherwise, we'll stall the DMA with PSRAM or flash cache misses.
187+
bool data_in_sram = data_in >= (uint8_t *)SRAM_BASE && data_out >= (uint8_t *)SRAM_BASE;
188+
bool use_dma = has_dma_channels && data_in_sram;
186189
if (use_dma) {
187190
dma_channel_config c = dma_channel_get_default_config(chan_tx);
188191
channel_config_set_transfer_data_size(&c, DMA_SIZE_8);

0 commit comments

Comments
 (0)