Skip to content

rp2: crash on soft reboot with DMA IRQ enabled and DMA active #18765

Closed

Description

@pdw-mb

Port, board and/or hardware

rp2 / rp2040

MicroPython version

MicroPython v1.27.0 on 2025-12-09; Raspberry Pi Pico with RP2040

Reproduction

Run the following code:

from rp2 import DMA

def dma_in_handler(dma):
    pass 

buf_src = bytearray(20)
buf_in = bytearray(20)

dma_in = DMA()
dma_in_ctrl = dma_in.pack_ctrl(size=0, treq_sel=0)
dma_in.irq(dma_in_handler, False)
dma_in.config(
    read=buf_src,
    write=buf_in,
    count=20,
    ctrl=dma_in_ctrl,
    trigger=True
)

#dma_in.active(False)
#dma_in.irq(None)

print("Hello")

Now attempt to soft-reboot the device (e.g. Ctrl-D on REPL). The device becomes unresponsive and requires a hard reboot.

  • Calling dma_in.active(False) before exit avoids the problem
  • Calling dma_in.irq(None) before exit avoids the problem
  • Removing the treq_sel parameter avoids the problem (presumably because the DMA is then inactive at the time of reboot)

Expected behaviour

No response

Observed behaviour

Device becomes unresponsive over serial after program is run and then MP is soft-rebooted.

Additional Information

No, I've provided everything above.

Code of Conduct

Yes, I agree

Activity

  1. agatti commented on Mar 11, 2026

    @agatti
    Contributor

    Stack trace:

    (gdb) bt
    #0  SVC_Handler () at /micropython/lib/pico-sdk/src/rp2_common/pico_crt0/crt0.S:334
    #1  <signal handler called>
    #2  0x1003bf7e in dma_channel_abort (channel=0) at /micropython/lib/pico-sdk/src/rp2_common/hardware_dma/include/hardware/dma.h:763
    #3  rp2_dma_close (self_in=0x20005750) at /micropython/ports/rp2/rp2_dma.c:436
    #4  0x10015a86 in fun_builtin_1_call (self_in=0x1006114c <rp2_dma_close_obj>, n_args=<optimized out>, n_kw=<optimized out>, args=0x20041f64)
        at /micropython/py/objfun.c:70
    #5  0x10020ce2 in mp_call_function_n_kw (fun_in=fun_in@entry=0x1006114c <rp2_dma_close_obj>, n_args=n_args@entry=1, n_kw=n_kw@entry=0, args=args@entry=0x20041f64)
        at /micropython/py/runtime.c:712
    #6  0x10020d9c in mp_call_function_1 (fun=fun@entry=0x1006114c <rp2_dma_close_obj>, arg=<optimized out>, arg@entry=0x20005750) at /micropython/py/runtime.c:690
    #7  0x1002243e in mp_call_function_1_protected (fun=0x1006114c <rp2_dma_close_obj>, arg=0x20005750) at /micropython/py/runtime_utils.c:33
    #8  0x1000c3f4 in gc_sweep_run_finalisers () at /micropython/py/gc.c:606
    #9  0x1000c55e in gc_collect_end () at /micropython/py/gc.c:549
    #10 0x1000c5a2 in gc_sweep_all () at /micropython/py/gc.c:544
    #11 0x1003a684 in main (argc=<optimized out>, argv=<optimized out>) at /micropython/ports/rp2/main.c:282
    
    (gdb) l
    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
    438             // Clean up interrupt handler to ensure garbage collection
    439             mp_irq_obj_t *irq = MP_STATE_PORT(rp2_dma_irq_obj[channel]);
    440             MP_STATE_PORT(rp2_dma_irq_obj[channel]) = MP_OBJ_NULL;
    
  2. added a commit that references this issue on Mar 18, 2026
    d2cda57
  3. added a commit that references this issue on Sep 21, 2026
    1cd3d78
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions