Skip to content

Commit 5423e49

Browse files
committed
rp2pio: Transfer up to 32 bytes before checking background tasks
@jerryneedell noticed that this problem affected strips short enough to not use the DMA peripheral, thanks for the hot tip! Instead of checking for background tasks after every byte transfer, try up to 32 transfers before attending to background tasks. This fixes the problem I was seeing on my 5-pixel circuit. Closes #4135.
1 parent a10ce39 commit 5423e49

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

ports/raspberrypi/common-hal/rp2pio/StateMachine.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -546,15 +546,23 @@ static bool _transfer(rp2pio_statemachine_obj_t *self,
546546
size_t tx_remaining = out_len;
547547

548548
while (rx_remaining || tx_remaining) {
549-
if (tx_remaining && !pio_sm_is_tx_fifo_full(self->pio, self->state_machine)) {
550-
*tx_destination = *data_out;
551-
data_out++;
552-
--tx_remaining;
553-
}
554-
if (rx_remaining && !pio_sm_is_rx_fifo_empty(self->pio, self->state_machine)) {
555-
*data_in = (uint8_t) *rx_source;
556-
data_in++;
557-
--rx_remaining;
549+
for (int i=0; i<32; i++) {
550+
bool did_transfer = false;
551+
if (tx_remaining && !pio_sm_is_tx_fifo_full(self->pio, self->state_machine)) {
552+
*tx_destination = *data_out;
553+
data_out++;
554+
--tx_remaining;
555+
did_transfer = true;
556+
}
557+
if (rx_remaining && !pio_sm_is_rx_fifo_empty(self->pio, self->state_machine)) {
558+
*data_in = (uint8_t) *rx_source;
559+
data_in++;
560+
--rx_remaining;
561+
did_transfer = true;
562+
}
563+
if (!did_transfer) {
564+
break;
565+
}
558566
}
559567
RUN_BACKGROUND_TASKS;
560568
if (mp_hal_is_interrupted()) {

0 commit comments

Comments
 (0)