Skip to content

Enable I2S for ESP32C6 (ESP32_GENERIC_C6) #17644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jimisola
Copy link

@jimisola jimisola commented Jul 9, 2025

Summary

The ESP32_GENERIC_C6 firmware doesn't support I2S. This PR enables I2S support.

Fixes: https://github.com/orgs/micropython/discussions/17151

Testing

image

The I2S import works but I'm yet to test that the audio actually works. But, according to @steve1780 who also custom built the firmware it worked for him: https://github.com/orgs/micropython/discussions/17151#discussioncomment-12925674

Signed-off-by: Jimisola Laursen <jimisola@jimisola.com>
@jimisola
Copy link
Author

jimisola commented Jul 9, 2025

I'm having issues confirming this with PCM5102A (see here). I doubt it, but could there be an issue with PCM5102A and MicroPython in general?

Would be nice if someone could verify this PR. @steve1780 might be able to test it.

@steve1780
Copy link

@jimisola,

I was not able to run the test code directly as I dont have a sd module at the moment, but I did some testing on the XIAO ESP32C6. As you know the ESP32C6 allows any GPIO pin to be assigned to any hardware block. In this case we are looking at the I2S on the C6 in which there is only one block (I2S_ID=0). I tested the pins from my original configuration:
SCK_PIN = 22
WS_PIN = 23
SD_PIN = 16
which worked fine.

I also tested your configuration:
SCK_PIN = 22
WS_PIN = 20
SD_PIN = 21
which did not work for me. GPIO20 happens to be MISO on the XIAO and there are always some GPIO pins that you can't output to like the ones for flash memory etc. I'm not exactly sure why this is on the XIAO.

I did try other GPIO combinations like:
SCK_PIN = 22
WS_PIN = 23
SD_PIN = 21
which did work. Also note that the ESP32 needs a hard reset (I used power-up) to reset the I2S block. Soft reset like ^D in Thonny does not cut it.

I used Mike Teachman's code to test this.

@jimisola
Copy link
Author

jimisola commented Jul 10, 2025

@steve1780

Just to confirm, you mention SD_PIN but say that you didn't have an SD module.

I used:

I2S_BCK_PIN = 22  # Bit Clock
I2S_DATA_PIN = 21  # Data In
I2S_LCK_PIN = 20  # Word Select (LRCK)

and you wrote that you tested my configuration:

SCK_PIN = 22
WS_PIN = 20
SD_PIN = 21

It seems as if we are using different PINs.

  • BCK vs SCK
  • WS vs DATA/DIN
  • SD vs LCK?

Did you use this example.

I had an issue with that example it seems as if dataformat, channelformat etc does not exist in MicroPython 1.25/1.26.

My code looks as follows:

# I2S pin configuration for PCM5102A
I2S_BCK_PIN = 22  # Bit Clock
I2S_DATA_PIN = 21  # Data In
I2S_LCK_PIN = 20  # Word Select (LRCK)


audio_out = I2S(
    I2S_ID,
    sck=Pin(I2S_BCK_PIN),
    ws=Pin(I2S_LCK_PIN),
    sd=Pin(I2S_DATA_PIN),
    mode=I2S.TX,
    bits=wav_info["bits_per_sample"],
    format=I2S.STEREO,
    rate=24000,
    ibuf=2048,
)

Looking at it now it seems as if I'm using the wrong PINs unless there is a different between your module and mine (PCM5201A). What module do you use?

image

@jimisola
Copy link
Author

According to ChatGPT the pin mappings are correct but it could be that I'm using WS_PIN = 20
then and it can't be used (like you said). I'll have things soldered already so it'll have to redo it to test.

image

@jimisola
Copy link
Author

I found some more information now on the PCM5201A (which also in the datasheet). I'll have to do some more soldering to configure it correctly.

pschatzmann/arduino-audio-tools#773 (comment)
image

https://community.home-assistant.io/t/i2s-audio-with-pcm5102a/739461/6
image

@steve1780
Copy link

@jimisola

Just to confirm, you mention SD_PIN but say that you didn't have an SD module.

Poor use of terms. SD_PIN just means "serial data". I am using the exact same PCM5201A module.
I was using this example from Mike Teachman: https://github.com/miketeachman/micropython-i2s-examples/blob/master/examples/play_tone.py

I really suspect the use of GPIO20 is the culprit. Which ESP32 board are you using?

@jimisola
Copy link
Author

@jimisola

Just to confirm, you mention SD_PIN but say that you didn't have an SD module.

Poor use of terms. SD_PIN just means "serial data". I am using the exact same PCM5201A module. I was using this example from Mike Teachman: https://github.com/miketeachman/micropython-i2s-examples/blob/master/examples/play_tone.py

Ok.

I really suspect the use of GPIO20 is the culprit. Which ESP32 board are you using?

Yes, I believe so too now that I know that you use the PCM5201A module as well.
I'm not sure which ESP32 C6 board it is. I bought a bunch of different ones on AE.

If I may ask, just to save some time. How did you configure H1-H4, i.e solder?

H1L (FLT) = L
H2L (DMP) = L
H3L (XMT) = H
H4L (FMT) = L 

and also full PIN configuration:

  • It was mentioned in one of the links that SCK to GND was used to avoid "weird sounds".
  • Do you have VIN to 3V3 or 5V? (in of the links/screenshots above they use 5V)

@steve1780
Copy link

@jimisola ,

Too bad about the origin of the board. It would help to know the pinout. Back in the ESP32-WROOM days they were alot more standardized. Now, we are not guaranteed to have Vcc and Gnd in the same place. I don't even trust Seeed with their C6 pinout diagram. Gotta look at the schematics.

I'm powering the PCM5201 board VIN with 3v3 from the ESP32C6 regulator.

I'm not sure how the SCK works, I'm tying it to Gnd as others have suggested. I did not touch H1-H4. They seem to be in the positions you indicated.

@jimisola
Copy link
Author

I'm not very good at soldering or electronics in general but I'm learning.

So, I resolded so that I can use 3 header pins between the ESP32 and the PCM5201A.
I therefore went with PIN 21-23 but slightly different configuration:

# I2S pin configuration for PCM5102A
I2S_BCK_PIN = 23  # Bit Clock
I2S_DIN_PIN = 22  # Data In
I2S_LCK_PIN = 21  # Word Select (LRCK)

Would you mind testing if that works for you?

After some digging I think that I found my board (wuxx nanoesp32-c6):

The troubleshooting now is mainly for me to feel confident about this PR working. Although you've managed to confirm that it works for you, so in theory it should be ready for merge.

@steve1780
Copy link

@jimisola

I'll check your new configuration in a bit. The nanoESP32C6 documentation has a lot to be desired, but I went to the Espressif datasheet and found this:
image

It confirms that the GPIO20 on the XIAO was mapped to the same pin on the nano. (Something to do with the SDIO_DATA0?)

The PR should be fine. The #define not being set, just excluded the I2S module from the build. It was probably done a while ago and no one had a C6 to test it. I'm new to github and I did not want to botch the PR. Thanks.

@steve1780
Copy link

@jimisola - Your new pin configuration works just fine.

@jimisola
Copy link
Author

jimisola commented Jul 11, 2025

@steve1780

@jimisola - Your new pin configuration works just fine.

Great. Thank for confirming that. Something else wrong at my end then.
Will try with another ESP32C6 and PCM5102A after the weekend.

@jimisola
Copy link
Author

@steve1780 We are troubleshooting here now and on my C6 I don't get a signal on WS.
We tried with a C3 and official firmware and there is signal. Connecting a PCM5102A to it now to test.

So, we'll try to rule out the following now:

  1. the firmware I built is faulty: is yours available for download somewhere?
  2. the C6 I have is faulty: we'll try with another one as well

@jimisola
Copy link
Author

@steve1780 We got it to work on my ESPC6 and ESPC3 🚀

For ESPC6 we used:

I2S_BCK_PIN = 9 # Bit Clock
I2S_DIN_PIN = 18 # Data In
I2S_LCK_PIN = 19 # Word Select (LRCK)

and SCK connected to ground.

Let's hope that some maintainer accept this PR now.

@steve1780
Copy link

@jimisola,
I've skimmed C6 data again from Espressif and can't see any irregularities with the GPIO matrix that would indicate use of GPIO20 would be an issue with I2S. I cannot check your final pin configuration as GPIO9 is on the back of the XIAO board and is also a BOOT strap pin.

@jimisola
Copy link
Author

Forgot to say that we tried PIN 20 and 21. None of them worked (not output voltage).

I don't think that this is an issue with the I2S implementation for C6 but rather the way some Dev Boards have their pinout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy