Skip to content

Commit d5910c1

Browse files
committed
rp2: Properly close DMA channels.
Fixes micropython#18446 by clearing the control registers and aborting the closed channel. Signed-off-by: Dryw Wade <dryw.wade@sparkfun.com>
1 parent c07fda7 commit d5910c1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

ports/rp2/rp2_dma.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,21 @@ 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(
433+
channel,
434+
&config,
435+
NULL,
436+
NULL,
437+
0,
438+
false
439+
);
440+
441+
// Abort this channel. Must be done after clearing EN bit in control
442+
// register due to errata RP2350-E5.
443+
dma_channel_abort(channel);
444+
430445
// Clean up interrupt handler to ensure garbage collection
431446
mp_irq_obj_t *irq = MP_STATE_PORT(rp2_dma_irq_obj[channel]);
432447
MP_STATE_PORT(rp2_dma_irq_obj[channel]) = MP_OBJ_NULL;

0 commit comments

Comments
 (0)