-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Open
Labels
Description
Port, board and/or hardware
RP2, PICO and PICO2, RP2040 and RP2350
MicroPython version
MicroPython v1.26.0 on 2025-08-09; Raspberry Pi Pico2 with RP2350
No Pin() IRQ when using the second core (_thread).
Primary core works as intended.
Reproduction
#!micropython
# -*- coding: UTF-8 -*-
# vim:fileencoding=UTF-8:ts=4
#╭──────────────────────────────────────────────────────────────────────────────╮
#│ PICO_THREAD_PIN_IRQ_TEST.PY │
#│ Board: PICO2/RP2350 │
#│ Micropython: 3.4.0; MicroPython v1.26.0 on 2025-08-09 │
#│ Testing: Pin.irq() on both cores │
#│ using a bridge between GPIO16 and GPIO17 │
#│ GPIO16 runs a slow PWM │
#│ GPIO17 acts as an input with IRQ │
#╰──────────────────────────────────────────────────────────────────────────────╯
import _thread
from sys import version
from array import array
from machine import Pin, PWM
from time import sleep_ms
_SIO_BASE = const(0xd0000000)
_CPUID = const(0x000 >>2)
_THREAD_HLT = const(0)
_THREAD_RUN = const(1)
_THREAD_FIN = const(2)
@micropython.viper
def cpuid() -> int:
sio: ptr32 = ptr32(_SIO_BASE)
return sio[_CPUID]
def core1(data,hard):
def cb_core1(pin):
print('cb_core1(): IRQ on core:', cpuid(), end=' ')
print('count:', data[1])
if data[1]:
data[1] -= 1
print('core1() is running on core:', cpuid())
pin = Pin(17, Pin.IN, Pin.PULL_UP)
data[1] = 5
pin.irq(handler=cb_core1, trigger=Pin.IRQ_FALLING, hard=hard)
while data[0] == _THREAD_RUN and data[1]:
sleep_ms(10)
pin.irq(None)
pin.init()
data[0] = _THREAD_FIN
return
def core0():
def cb_core0(pin):
print('cb_core0(): IRQ on core:', cpuid(), end=' ')
print('count:', data[1])
if data[1]:
data[1] -= 1
print(version)
data = array('I', (_THREAD_HLT,0)) # [0]state [1] counter
pwm = PWM(16, freq=10, duty_u16=2**15)
print('Testing hard=False on core 0')
pin = Pin(17, Pin.IN, None)
data[1] = 5
pin.irq(handler=cb_core0, trigger=Pin.IRQ_FALLING, hard=False)
while data[1]:
sleep_ms(10)
pin.irq(None)
pin.init()
print('Testing hard=True on core 0')
pin = Pin(17, Pin.IN, None)
data[1] = 5
pin.irq(handler=cb_core0, trigger=Pin.IRQ_FALLING, hard=True)
while data[1]:
sleep_ms(10)
pin.irq(None)
pin.init()
print('Testing hard=False on core 1')
data[0] = _THREAD_RUN
_thread.start_new_thread(core1, (data,False))
loops = 100
while (loops:= loops-1) and data[0] != _THREAD_FIN:
sleep_ms(10)
data[0] = _THREAD_HLT
while data[0] != _THREAD_FIN: pass
print('Testing hard=True on core 1')
data[0] = _THREAD_RUN
_thread.start_new_thread(core1, (data,True))
loops = 100
while (loops:= loops-1) and data[0] != _THREAD_FIN:
sleep_ms(10)
data[0] = _THREAD_HLT
while data[0] != _THREAD_FIN: pass
pwm.deinit()
core0()
3.4.0; MicroPython v1.26.0 on 2025-08-09
Testing hard=False on core 0
cb_core0(): IRQ on core: 0 count: 5
cb_core0(): IRQ on core: 0 count: 4
cb_core0(): IRQ on core: 0 count: 3
cb_core0(): IRQ on core: 0 count: 2
cb_core0(): IRQ on core: 0 count: 1
Testing hard=True on core 0
cb_core0(): IRQ on core: 0 count: 5
cb_core0(): IRQ on core: 0 count: 4
cb_core0(): IRQ on core: 0 count: 3
cb_core0(): IRQ on core: 0 count: 2
cb_core0(): IRQ on core: 0 count: 1
Testing hard=False on core 1
core1() is running on core: 1
Testing hard=True on core 1
core1() is running on core: 1
### Expected behaviour
Well, should fire IRQ/callback events when running on core 1.
### Observed behaviour
Does not.
### Additional Information
No, I've provided everything above.
### Code of Conduct
Yes, I agree