Skip to main content
Graduate
June 19, 2023
Solved

Help in creating a simple soundcard with I2S (or SAI if necessary)

  • June 19, 2023
  • 8 replies
  • 11761 views

Hi,

I'm working on creating a simple soundcard with a simple codec called pcm5102a which is a part of the kernel source. My board is the STM32MP135F-DK. I2S seems to be enough for this purpose however if you think that SAI will work better, then I'll take advice on that happily as well.

The current configuration is as in the attached audio_test.zip with I2S1 enabled and SPI1 Clock Mux set to PLL3Q instead of the default PLL4P (all set in the STM32CubeMX). The configuration is inserted into the build with a new machine and it does build without any problems. It's only after the boot that aplay -l doesn't list any soundcards, moreover below message is visible in the dmesg output:

 

 

[ 3.600504] st,stm32-i2s 44004000.audio-controller: Could not get x8k parent clock: -2
[ 3.607136] st,stm32-i2s: probe of 44004000.audio-controller failed with error -2

 

 

I read that the x8k is one of the clocks necessary for audio handling, however can't figure out how to fix that.

Below are the most important parts regarding the soundcard configuration:

 

 

/ { sound {
 compatible = "audio-graph-card";
 label = "STM32MP1-audio-test-card";
 routing =
 "Playback" , "MCLK"; /* Set a route between "MCLK" and "playback" DAPM widgets */
 dais = <&i2s1_port>;
 status = "okay";
 };
};

&i2s1{
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&i2s1_pins_mx>;
	pinctrl-1 = <&i2s1_sleep_pins_mx>;
	status = "okay";

	/* USER CODE BEGIN i2s1 */
 #clock-cells = <0>;
 clocks = <&rcc SPI1>, <&rcc SPI1_K>, <&rcc PLL3_Q>, <&rcc PLL3_R>;
 clock-names = "pclk", "i2sclk", "x8k", "x11k";
 #sound-dai-cells = <1>;

	i2s1_port: port {
 #address-cells = <1>;
 #size-cells = <0>;
		i2s1_endpoint: endpoint {
 system-clock-frequency = <48000>;
 system-clock-direction-out;
 frame-master;
 bitclock-master;
			format = "i2s";
			mclk-fs = <256>;
 remote-endpoint = <&codec_endpoint>;
		};
	};

 codec: pcm5102a {
 compatible = "ti,pcm5102a";
 #sound-dai-cells = <0>;
 clocks = <&i2s1>; /* The codec is a consumer of I2S2 master clock */
 clock-names = "MCLK"; /* Feed MCLK codec clock with I2S2 master clock provider */

 codec_port: pcm5102a_port {
 codec_endpoint: endpoint{
 remote-endpoint = <&i2s1_endpoint>;
 };
 };
 };
	/* USER CODE END i2s1 */
};

 

 

 

 

    This topic has been closed for replies.
    Best answer by Erwan SZYMANSKI

    @AJank.2 ,
    Well it is going forward !

    I am not an audio expert, but if I remember well, I think that the additional DPAM Widget needs to be declared inside the codecs driver. In your case for example it should be something like:

    static const struct snd_soc_dapm_widget aic31xx_dapm_mclk_widgets[] = {
    	SND_SOC_DAPM_SUPPLY("MCLK", SND_SOC_NOPM, 0, 0, mclk_event,
    			 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
    };

    If you want a reference taken by ST, you can take a look at the cirrus,cs42l51 codecs driver.

    I hope that it will help you.
    Kind regards,
    Erwan.

    8 replies

    AJank.2Author
    Graduate
    June 19, 2023

    I search the forum and found this post where it's advised to use below clock configuration instead:

    clocks = <&rcc SPI1>, <&rcc SPI1_K>, <&scmi_clk CK_SCMI_PLL3_Q>, <&scmi_clk CK_SCMI_PLL3_R>;

     This operation seems to fix the x8k parent clock problem, however a list of new messages appeared in dmesg and aplay keeps returning empty list.

    root@stm32mp13-audiotest:~# dmesg | grep audio
    [ 3.601263] st,stm32-i2s 44004000.audio-controller: No cache defaults, reading back from HW
    [ 3.888307] st,stm32-i2s 44004000.audio-controller: No cache defaults, reading back from HW
    [ 83.283559] systemd[1]: Hostname set to <stm32mp13-audiotest>.
    [ 94.358163] OF: graph: no port node found in /soc/audio-controller@44004000/pcm5102a
    [ 94.487565] brcmfmac mmc1:0001:1: Direct firmware load for brcm/brcmfmac43430-sdio.st,stm32mp135f-audio_test_cubemx-mx.bin failed with error -2
    [ 94.503605] OF: graph: no port node found in /soc/audio-controller@44004000/pcm5102a
    [ 94.582875] OF: graph: no port node found in /soc/audio-controller@44004000/pcm5102a
    [ 94.589293] OF: graph: no port node found in /soc/audio-controller@44004000/pcm5102a
    [ 94.815024] Modules linked in: snd_soc_audio_graph_card snd_soc_simple_card_utils brcmfmac stm32_dcmipp cfg80211 hci_uart btbcm brcmutil stm32_crc32 bluetooth st_mipid02 gc2145 v4l2_fwnode v4l2_async stm32_cryp ecdh_generic videodev libdes ecc crypto_engine libaes mc stm32_adc_core ucsi_stm32g0 typec_ucsi typec sch_fq_codel ip_tables x_tables ipv6
    [ 96.602222] OF: graph: no port node found in /soc/audio-controller@44004000/pcm5102a
    [ 96.608640] OF: graph: no port node found in /soc/audio-controller@44004000/pcm5102a
    [ 96.729081] OF: graph: no port node found in /soc/audio-controller@44004000/pcm5102a
    [ 96.755746] Modules linked in: dcmipp_bytecap(+) videobuf2_dma_contig videobuf2_memops videobuf2_v4l2 videobuf2_common dcmipp_parallel dcmipp_byteproc stm32_adc(+) stm32_timer_trigger stm32_lptimer_trigger snd_soc_audio_graph_card snd_soc_simple_card_utils brcmfmac stm32_dcmipp cfg80211 hci_uart btbcm brcmutil stm32_crc32 bluetooth st_mipid02 gc2145 v4l2_fwnode v4l2_async stm32_cryp ecdh_generic videodev libdes ecc crypto_engine libaes mc stm32_adc_core ucsi_stm32g0 typec_ucsi typec sch_fq_codel ip_tables x_tables ipv6
    [ 96.826275] OF: graph: no port node found in /soc/audio-controller@44004000/pcm5102a
    [ 96.930105] OF: graph: no port node found in /soc/audio-controller@44004000/pcm5102a
    [ 96.978668] OF: graph: no port node found in /soc/audio-controller@44004000/pcm5102a
    [ 97.810640] OF: graph: no port node found in /soc/audio-controller@44004000/pcm5102a
    [ 97.868132] OF: graph: no port node found in /soc/audio-controller@44004000/pcm5102a

    Do you have any advice on what to do next?

    AJank.2Author
    Graduate
    June 19, 2023

    Again, the message below:

     

    OF: graph: no port node found in /soc/audio-controller@44004000/pcm5102a

     

    made me think that maybe the problem is in the codec node of the Device Tree. Indeed after swapping below

     

     codec_port: pcm5102a_port {
     codec_endpoint: endpoint {
     remote-endpoint = <&i2s1_endpoint>;
     };
     };

     

    to

     

     codec_port: port {
     codec_endpoint: endpoint {
     remote-endpoint = <&i2s1_endpoint>;
     };
     };

     

     The OF message disappeared, now the only remaining dmesg output regarding audio is below:

     

    [ 3.601352] st,stm32-i2s 44004000.audio-controller: No cache defaults, reading back from HW
    [ 3.883381] st,stm32-i2s 44004000.audio-controller: No cache defaults, reading back from HW
    [ 93.945497] brcmfmac mmc1:0001:1: Direct firmware load for brcm/brcmfmac43430-sdio.st,stm32mp135f-audio_test_cubemx-mx.bin failed with error -2

     

    Once again, do you have any advice on to fix that?

    Technical Moderator
    June 26, 2023

    Hello @AJank.2 ,
    Sorry for the delay, I was out of office.

    Concerning the 2 remaining I2S messages in dmsg, they looks normal. We always have the same on our standard deliveries.

    Do you still face troubles with your setup ?

    Kind regards,
    Erwan.

    AJank.2Author
    Graduate
    June 22, 2023

    @Erwan SZYMANSKI @PatrickF could I get some help with this? Is STMicroelectronics support closed this week?

    Technical Moderator
    June 22, 2023

    Hi @AJank.2 thank you for following up on your question. 

    Please apologize for the delay in response, we are just catching up after the migration to the new platform. 

    I escalated your question to some audio expert. We will come back to you ASAP. 

    Olivier 

     

    AJank.2Author
    Graduate
    June 26, 2023

    Hi @Erwan SZYMANSKI, the main problem is that there are no sound cards discovered by ALSA - that I haven't fixed yet. With that simple kind of codec it seems that nothing more from what I set up already should be configured meaning that I don't know what else could be missing.

    Technical Moderator
    June 26, 2023

    Hi @AJank.2 ,
    Can you share me your complete device tree ? I will try to review it and see if I can highlight some problems inside.

    Rgs,
    Erwan.

    AJank.2Author
    Graduate
    June 26, 2023

    Yes, the files generated by CubeMX with my modifications to the device tree is in the attached audio_test.tar.

    Actually for some reason I'm having problems with attaching the tar archive. The error says that the file doesn't match it's type:

    The attachment's audio_test.tar content type (application/x-tar) does not match its file extension and has been removed.

    I'll try again in the next reply.

    AJank.2Author
    Graduate
    June 26, 2023

    Okay, decided to sent just the Device Tree, here it is with changed extension, from .dts to .txt.

    Technical Moderator
    June 26, 2023

    @AJank.2 ,
    Just to be sure, in the kernel menuconfig, did you well activate your codec as a module ? (It seems strange to not see nor soundcard or dmesg error appearing).
    the config is CONFIG_SND_SOC_PCM5102A=m

    Kind regards,
    Erwan.

     

    Technical Moderator
    June 26, 2023

    Moreover, As the codec is not driven by nor I2C or SPI, its node should be placed in the root node of your device tree, for example, below you sound node. (I do not know the impact if you place it in the i2s node).

    Rgs,
    Erwan.

    AJank.2Author
    Graduate
    June 28, 2023

    Thank you for help @Erwan SZYMANSKI, I managed to add the dapm MCLK supply widget to the codec driver and it does show up in the output of aplay -l. There some issues with playback with speaker-test, so perhaps the configuration isn't perfect yet, but there's definitely some progress made.
    Thanks!

    AJank.2Author
    Graduate
    July 5, 2023

    Interestingly is seems that creating a new DAPM supply node isn't the only solution. Deleting the routing part from the audio-graph sound card device tree node seems to make things work as well. I got speaker-test to work with the audio-graph sound card and the pcm5102a.c codec.

    like below:

     sound {
     compatible = "audio-graph-card";
     label = "STM32MP1-audio-test-card";
     dais = <&i2s1_port>;
     status = "okay";
     };
    Visitor II
    July 5, 2023

    Hi AJank.2,

    I try Your dts configuration and Your last suggestion but for me, it's not working. Do You use hardware like

    MWoo2_0-1688589080289.jpeg

    If yes which lines have You connected?

    Do this configuration is correct?

    &i2s1{
    	pinctrl-names = "default", "sleep";
    	pinctrl-0 = <&i2s1_pins_mx>;
    	pinctrl-1 = <&i2s1_sleep_pins_mx>;
    	status = "okay";
    
    	/* USER CODE BEGIN i2s1 */
     #clock-cells = <0>;
     clocks = <&rcc SPI1>, <&rcc SPI1_K>, <&scmi_clk CK_SCMI_PLL3_Q>, <&scmi_clk CK_SCMI_PLL3_R>;
     clock-names = "pclk", "i2sclk", "x8k", "x11k";
     #sound-dai-cells = <1>;
    
    	i2s1_port: port {
     #address-cells = <1>;
     #size-cells = <0>;
    		i2s1_endpoint: endpoint {
     /* system-clock-frequency = <48000>; */
     /* system-clock-direction-out; */
     /* frame-master; */
     /* bitclock-master; */
    			format = "i2s";
    			mclk-fs = <256>;
     remote-endpoint = <&codec_endpoint>;
    		};
    	};
    
     codec: pcm5102a {
     compatible = "ti,pcm5102a";
     #sound-dai-cells = <0>;
     clocks = <&i2s1>; /* The codec is a consumer of I2S2 master clock */
     clock-names = "MCLK"; /* Feed MCLK codec clock with I2S2 master clock provider */
    
     codec_port: port {
     codec_endpoint: endpoint {
     remote-endpoint = <&i2s1_endpoint>;
     };
     };
     };
    	/* USER CODE END i2s1 */
    };

    Thanks in advanced

    BR Michal

    AJank.2Author
    Graduate
    July 6, 2023

    This discussion was quite extensive, so I guess it's not easy to read through all of it :D
    My hardware is different, it's the STM32MP135F-DK board.
    The main outcomes of the discussion are that the codec node has to be defined in the root node of the Device Tree, so you should move it outside of the I2S1 node. The other thing is that the default audio-graph sound card doesn't really require the routing section for it to work - just delete it. The routing may actually make things harder for you (it did for me, it required the DAPM supply node). Try below:

     

    /{ /* this is the root node */
     sound {
     compatible = "audio-graph-card";
     label = "STM32MP1-audio-test-card";
     dais = <&i2s1_port>;
     status = "okay";
     };
    
     codec: pcm5102a-codec {
     compatible = "ti,pcm5102a";
     #sound-dai-cells = <0>;
     clocks = <&i2s1>; /* The codec is a consumer of I2S2 master clock */
     clock-names = "MCLK"; /* Feed MCLK codec clock with I2S2 master clock provider */
    
     codec_port: port {
     codec_endpoint: endpoint {
     remote-endpoint = <&i2s1_endpoint>;
     };
     };
     };
    }; /* root node closes here */

     

    Leave the I2S1I node configuration as is and I think you're good to go.