← index #17863Issue #17968
Related · medium · value 1.538
QUERY · ISSUE

RP2 hangs when using I2S and bitstream

openby robtinkersopened 2025-08-07updated 2026-03-19
bugport-rp2

Port, board and/or hardware

rp2

MicroPython version

MicroPython v1.25.0 on 2025-04-15; Raspberry Pi Pico with RP2040

Reproduction

Running the following code in Thonny.

I have run it on an official Pico 2 W, and an RP2040-zero board from AliExpress.

I have run it on stock firmware (1.25.0), the stock ulab firmware (based on 1.24.0), and my own build (1.26.0-preview + ulab).

I have run it with both the external peripherals attached (8x8 WS2812B matrix and an INMP441 clone from AliExpress), and nothing attached to the board other than USB power.

All exhibit the same problem.

import machine, sys
from machine import Pin, I2S
from neopixel import NeoPixel

MTX_DIN = const(14)

MIC_ID  = const(0)
MIC_SCK = const(6)
MIC_WS  = const(7)
MIC_SD  = const(8)

SAMPLE_RATE = const(22050) # Hz
SAMPLE_BITS = const(16)
SAMPLE_COUNT = const(512)

if sys.platform == 'rp2':
    assert MIC_WS == MIC_SCK + 1

mtx = NeoPixel(Pin(MTX_DIN), 64)

raw = bytearray(SAMPLE_COUNT * SAMPLE_BITS // 8)

mic = None
try:
    mic = I2S(MIC_ID,
              sck=Pin(MIC_SCK), ws=Pin(MIC_WS), sd=Pin(MIC_SD),
              rate=SAMPLE_RATE, bits=SAMPLE_BITS,
              mode=I2S.RX, format=I2S.MONO,
              ibuf=len(raw)*2)
    
    loop = 0
    while True:
        print(loop, 'loop begins')
        
        num_bytes_read = mic.readinto(raw)
        assert (num_bytes_read == len(raw))
        print(loop, 'microphone read')
        
        mtx.write() # hangs
#        machine.bitstream(mtx.pin, 0, mtx.timing, mtx.buf) # hangs, equivalent to mtx.write()
#        machine.bitstream(mtx.pin, 0, mtx.timing, mtx.buf[:144]) # hangs
#        machine.bitstream(mtx.pin, 0, mtx.timing, mtx.buf[:72]) # usually works
        print(loop, 'bitstream() done')
        
        loop = loop + 1
        print('next', loop)

except Exception as e:
    sys.print_exception(e)

finally:
    try: mic.deinit()
    except: pass

Expected behaviour

The loop runs indefinitely.

Observed behaviour

0 loop begins
0 microphone read
0 bitstream() done
next 1

(and nothing else, it doesn't actually start the next loop, and the device must be power-cycled)

If I replace mtx.write() with one of the alternatives, it either hangs (for larger numbers of bytes) or runs fine (smaller number of bytes).

Additional Information

Slightly different versions of the code were sometimes printing unexpected strings instead of "next" (for example "enable_irq" and "bin")

Code of Conduct

Yes, I agree

CANDIDATE · ISSUE

rp2: No Pin IRQ on core 1 (on core 0: OK)

openby GitHubsSilverBulletopened 2025-08-21updated 2026-03-09
bugport-rp2

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

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied