Skip to content

Commit

Permalink
clear any pending interrupt flag
Browse files Browse the repository at this point in the history
While debugging, I found that on RP2040 the first looped background
write on a StateMachine would be garbled: It the first few outputs
would be as expected, but then the data would go back to the start
of the buffer.

I realized that this could be due to there already being a pending
interrupt on this DMA channel that had occurred previously but never
been acknowledged. In fact, by printing the value of `dma_hw->intr`
before this, I could see that it was the case.

After this change, both my special case reproducer from the related
issue works, and the odd gaps in LED data transmission seen in the
WIP code for TM1814 LEDs was fixed.

I never saw this problem on Feather RP2350, only on Metro RP2040,
but I don't know why. It would depend on what had previously
happened to the DMA channel that ends up allocated to this PIO
state machine. Less likely, it could depend on details of the DMA
peripheral that changed between the chips.

Closes: #9678
  • Loading branch information
jepler committed Oct 3, 2024
1 parent fad755d commit d0e8030
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ports/raspberrypi/common-hal/rp2pio/StateMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,8 @@ bool common_hal_rp2pio_statemachine_background_write(rp2pio_statemachine_obj_t *
false);

common_hal_mcu_disable_interrupts();
// Acknowledge any previous pending interrupt
dma_hw->ints0 |= 1u << channel;
MP_STATE_PORT(background_pio)[channel] = self;
dma_hw->inte0 |= 1u << channel;
irq_set_mask_enabled(1 << DMA_IRQ_0, true);
Expand Down

0 comments on commit d0e8030

Please sign in to comment.