Skip to content

Commit d2cda57

Browse files
projectgusdpgeorge
authored andcommitted
rp2/rp2_dma: Disable DMA IRQ before clearing handler function.
Both the overall IRQ line and the per-channel IRQ, for good measure. Otherwise, soft reset will remove the handler before the finaliser for the DMA object(s) run and trigger IRQs if the channel is still active. Closes micropython#18765 This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <[email protected]>
1 parent 06dbc1f commit d2cda57

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎ports/rp2/rp2_dma.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ 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+
// Disable channel IRQ
431+
dma_channel_set_irq0_enabled(channel, false);
432+
430433
// Reset this channel's registers to their default values (zeros).
431434
dma_channel_config config = { .ctrl = 0 };
432435
dma_channel_configure(channel, &config, NULL, NULL, 0, false);
@@ -441,7 +444,6 @@ static mp_obj_t rp2_dma_close(mp_obj_t self_in) {
441444
if (irq) {
442445
irq->parent = MP_OBJ_NULL;
443446
irq->handler = MP_OBJ_NULL;
444-
dma_channel_set_irq0_enabled(channel, false);
445447
}
446448
dma_channel_unclaim(channel);
447449
self->channel = CHANNEL_CLOSED;
@@ -479,7 +481,8 @@ void rp2_dma_init(void) {
479481
}
480482

481483
void rp2_dma_deinit(void) {
482-
// Remove our interrupt handler.
484+
// Disable and remove our interrupt handler.
485+
irq_set_enabled(DMA_IRQ_0, false);
483486
irq_remove_handler(DMA_IRQ_0, rp2_dma_irq_handler);
484487
}
485488

0 commit comments

Comments
 (0)