← index #16076PR #3489
Related · high · value 0.550
QUERY · ISSUE

i2s bug?

openby shaojiajun314opened 2024-10-25updated 2026-03-24
bugport-esp32

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

image

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

CANDIDATE · PULL REQUEST

esp32: Add I2S peripheral support.

closedby aykevlopened 2017-12-14updated 2021-07-13

Implementation of hardware I2S for the ESP32.

This appears to be the first I2S implementation for MicroPython. I've followed the proposed I2S machine API mostly, but did not follow it exactly. This is the current API / example code:

import machine
i2s = machine.I2S([0,] bclk=4, ws=15, data_out=2, data_in=22, [samplerate=48000,] [bitdepth=16])
buffer = ... # generate sine wave or something
while True:
    i2s.write(buffer)

# also implemented
i2s.deinit()
i2s.init(...) # throws an error if initialized already

Not yet implemented, mostly due to lacking hardware:

  • communication format, e.g. MSB/LSB.
  • clock: the ESP32 has an APLL clock, but I'm not sure what it's purpose is
  • callbacks (for now, i2s.write() blocks if the buffer is full)
  • reading from the I2S bus
  • not setting the data_in pin (not sure if this is possible)
  • change parameters
  • stop/start (without deinit) - by default it keeps looping existing data if the buffer isn't filled fast enough
  • internal ADC

Which of these (if any) should be implemented before it can be merged?

Documentation: https://esp-idf.readthedocs.io/en/latest/api-reference/peripherals/i2s.html

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