Skip to content

Commit b24c9cf

Browse files
sfe-SparkFrodpgeorge
authored andcommitted
rp2/rp2_dma: Properly close DMA channels.
Clears the control registers and aborts the closed channel upon a call to `.close()` and `.__del__()` (GC collect). Fixes issue micropython#18446. Signed-off-by: Dryw Wade <[email protected]>
1 parent 1ef76c7 commit b24c9cf

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

ports/rp2/rp2_dma.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,14 @@ static mp_obj_t rp2_dma_close(mp_obj_t self_in) {
427427
uint8_t channel = self->channel;
428428

429429
if (channel != CHANNEL_CLOSED) {
430+
// Reset this channel's registers to their default values (zeros).
431+
dma_channel_config config = { .ctrl = 0 };
432+
dma_channel_configure(channel, &config, NULL, NULL, 0, false);
433+
434+
// Abort this channel. Must be done after clearing EN bit in control
435+
// register due to errata RP2350-E5.
436+
dma_channel_abort(channel);
437+
430438
// Clean up interrupt handler to ensure garbage collection
431439
mp_irq_obj_t *irq = MP_STATE_PORT(rp2_dma_irq_obj[channel]);
432440
MP_STATE_PORT(rp2_dma_irq_obj[channel]) = MP_OBJ_NULL;

0 commit comments

Comments
 (0)