i2s bug?
Port, board and/or hardware
esp32
MicroPython version
E (151878) i2s_common: i2s_alloc_dma_desc(417): allocate DMA buffer failed
E (151878) i2s_std: i2s_std_set_slot(103): allocate memory for dma descriptor failed
E (151878) i2s_std: i2s_channel_init_std_mode(217): initialize channel failed while setting slot
E (151888) i2s_common: i2s_channel_enable(966): the channel has already enabled or not initialized
Reproduction
def _play_i2s_dac(self, name):
if self.is_play:
return False
self.is_play = True
if isinstance(name, str):
name = self.buildpath(name)
with wav_open(name) as f:
total = f.getnframes()
# print('total: ', total)
print('rate: ', f.getframerate())
try:
i2s = I2S(
0,
# sck=Pin(14), ws=Pin(13), sd=Pin(12),
sck=Pin(CONF['i2sBCLK']),
ws=Pin(CONF['i2sLRC']),
sd=Pin(CONF['i2sDIN']),
mode=I2S.TX,
bits=16,
format=I2S.MONO,
rate=f.getframerate(),
ibuf=1024
)
except Exception as e:
print('''
E (35978) i2s_common: i2s_alloc_dma_desc(417): allocate DMA buffer failed
E (35978) i2s_std: i2s_std_set_slot(103): allocate memory for dma descriptor failed
E (35988) i2s_std: i2s_channel_init_std_mode(217): initialize channel failed while setting slot
E (35998) i2s_common: i2s_channel_enable(966): the channel has already enabled or not initialized
?''')
print(e)
self.is_play = False
return False
while 1:
read_size = min(total, self.buffer_size)
tmp = f.readframes(read_size)
tmp = bytearray(tmp)
I2S.shift(buf=tmp, bits=16, shift=self.dB)
i2s.write(tmp)
total -= read_size
if total <= 0:
break
i2s.deinit()
self.is_play = False
return True
Expected behaviour
No response
Observed behaviour
E (151878) i2s_common: i2s_alloc_dma_desc(417): allocate DMA buffer failed
E (151878) i2s_std: i2s_std_set_slot(103): allocate memory for dma descriptor failed
E (151878) i2s_std: i2s_channel_init_std_mode(217): initialize channel failed while setting slot
E (151888) i2s_common: i2s_channel_enable(966): the channel has already enabled or not initialized
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree
RP2 hangs when using I2S and bitstream
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