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 #18446.

Signed-off-by: Dryw Wade <dryw.wade@sparkfun.com>
This commit is contained in:
Dryw Wade
2025-11-24 14:00:34 -07:00
committed by Damien George
parent 1ef76c7fba
commit b24c9cf2a9

View File

@@ -427,6 +427,14 @@ static mp_obj_t rp2_dma_close(mp_obj_t self_in) {
uint8_t channel = self->channel;
if (channel != CHANNEL_CLOSED) {
// Reset this channel's registers to their default values (zeros).
dma_channel_config config = { .ctrl = 0 };
dma_channel_configure(channel, &config, NULL, NULL, 0, false);
// Abort this channel. Must be done after clearing EN bit in control
// register due to errata RP2350-E5.
dma_channel_abort(channel);
// Clean up interrupt handler to ensure garbage collection
mp_irq_obj_t *irq = MP_STATE_PORT(rp2_dma_irq_obj[channel]);
MP_STATE_PORT(rp2_dma_irq_obj[channel]) = MP_OBJ_NULL;