Nano RP2040 Crashing on PIO IRQ call

I try to implement a function triggered by a PIO IRQ ( pio_IRQhandler() ), but when I include the IRQ handeling code into sketch, the rp2040 crashes after call (GPIO 20 High). I searched for doc, but couldn't find any official documents, only this into forum posts ... reason why.

Sketch Code that generate crash:

  // Enable IRQ0 & 1 on PIO0
  irq_set_exclusive_handler(PIO0_IRQ_0, pio_IRQhandler); // IRQ7 = PIO0_IRQ_0
  irq_set_enabled(PIO0_IRQ_0, true);
  pio0_hw->inte0 = PIO_IRQ0_INTE_SM0_BITS | PIO_IRQ0_INTE_SM1_BITS;

If the code above is not present, i runs fine. What is the correct code to use then? Or How to fix this issue? ... any clue is welcome :wink:

for reference, PIO Code:

mainloop:
    pull noblock                    ; Loads OSR with delay value
    mov x,osr                       ; OSR contents to X to prepare for future noblock pulls
    mov y,x                         ; Load (Number of Loops - 1) value into Y => "lloping"
    ;irq clear 0
    wait 1 gpio 20                   ; Wait for GPIO 20 Trigger (High=1)
    looping:                      ; Start "looping" loop
        set pins, 1            [31] ; Turn Led ON ( GPIO 25)
        nop             [31]
        nop             [31]
        nop             [31]
        nop             [31]
        nop             [31]
        nop             [31]
        nop             [31]
        set pins, 0     [31]           ; Turn Led OFF
        nop             [31]
        nop             [31]
        nop             [31]
        nop             [31]
        nop             [31]
        nop             [31]
        nop             [31]
        nop             [31]
        nop             [31]
        nop             [31]
        nop             [31]
        nop             [31]
        nop             [31]
        nop             [31]
        jmp y-- looping  [31]    ; Jumps to "looping" if y not 0, then decrements y
    irq set 0                       ; Set IRQ 0 active to triffer function pio_IRQhandler() in sketch
    jmp mainloop

Sketch:

// PIO IRQs handling
void pio_IRQhandler() {
  irq_clear(PIO0_IRQ_0);
  Serial.print("PIO0 IRQ0 !!!\n" );    
}

Thank you in advance for your help or sharing of experiences around this,
Henry

It might be that rp2040 does not allow Serial.print() from within an IRQ handler...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.