cancel
Showing results for 
Search instead for 
Did you mean: 

stm32mp135 - pcm5102a - sai1a

MWoło.2
Senior II

Hello,

I try to connect a popular Arduino board PCM5102a with my board which is base on STM32MP135.

MWoo2_0-1688975337399.jpeg

I read some documentation from the link

but pcm, i2s and sound topics are something I have only a base knowledge of, so please give some advice and hints.

My dts looks like

 

/ {
    sound {
        compatible = "audio-graph-card";
        label = "STM32MP1-audio-test-card";
		routing =
			"Playback" , "MCLK",
			"Capture" , "MCLK",
			"MICL" , "Mic Bias";
		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>;
				frame-master;    /* Set codec as master of SAI1A for FS clock. */
				bitclock-master; /* Set codec as master of SAI1A for SCK clock. */
            };
        };
    };
};

	sai1a_pins_mx: sai1a_mx-0 {
		pins {
			pinmux = <STM32_PINMUX('C', 0, AF2)>, /* SAI1_SCK_A */
					 <STM32_PINMUX('C', 3, AF10)>, /* SAI1_MCLK_A */
					 <STM32_PINMUX('E', 11, AF6)>, /* SAI1_FS_A */
					 <STM32_PINMUX('F', 12, AF6)>; /* SAI1_SD_A */
			bias-disable;
			drive-push-pull;
			slew-rate = <0>;
		};
	};

	sai1a_sleep_pins_mx: sai1a_sleep_mx-0 {
		pins {
			pinmux = <STM32_PINMUX('C', 0, ANALOG)>, /* SAI1_SCK_A */
					 <STM32_PINMUX('C', 3, ANALOG)>, /* SAI1_MCLK_A */
					 <STM32_PINMUX('E', 11, ANALOG)>, /* SAI1_FS_A */
					 <STM32_PINMUX('F', 12, ANALOG)>; /* SAI1_SD_A */
		};
	};

&sai1{
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&sai1a_pins_mx>;
	pinctrl-1 = <&sai1a_sleep_pins_mx>;
	status = "okay";

	/* USER CODE BEGIN sai1 */
    #clock-cells = <0>;
    clocks = <&rcc SAI1>, <&scmi_clk CK_SCMI_PLL3_Q>, <&scmi_clk CK_SCMI_PLL3_R>;
    clock-names = "pclk", "x8k", "x11k";
    #sound-dai-cells = <1>;
	/* USER CODE END sai1 */

	sai1a:audio-controller@4400a004{
		status = "okay";

		/* USER CODE BEGIN sai1a */
		compatible = "st,stm32-sai-sub-a";
		reg = <0x4 0x1C>;
		clocks = <&rcc SAI1>;
		clock-names = "sai_ck";
		#clock-cells = <0>;
		dma-names = "tx";
		/*dmas = <&dmamux1 1 87 0x400 0x0>;*/
		/*dma-names = "tx";*/
		i2s1_port: port {
			i2s1_endpoint: endpoint {
				remote-endpoint = <&codec_endpoint>;
				format = "i2s";
				mclk-fs = <256>;
			};
		};
		/* USER CODE END sai1a */
	};
};

 

 I get an error like

 

root@mp1-sagittarius:~# dmesg | grep audio
[    0.057703] OF: /pcm5102a-codec: could not get #clock-cells for /soc/audio-controller@44004000
[   35.535330] platform 4400a004.audio-controller: Fixing up cyclic dependency with pcm5102a-codec
[   39.684607] OF: /pcm5102a-codec: could not get #clock-cells for /soc/audio-controller@44004000
[   39.692414] st,stm32-sai-sub 4400a004.audio-controller: Missing dma channel for stream: 0
[   39.836205] st,stm32-sai-sub 4400a004.audio-controller: ASoC: error at snd_soc_pcm_component_new on 4400a004.audio-controller: -22
[   39.923241] asoc-audio-graph-card sound: ASoC: can't create pcm 4400a004.audio-controller-pcm5102a-hifi :-22
[   39.932041] asoc-audio-graph-card sound: parse error -22
[   40.049044] asoc-audio-graph-card: probe of sound failed with error -22
root@mp1-sagittarius:~# 

 

in optte dts I use CLK_SAI1_PLL4Q for SAI1a.

BR Michal

 

 

11 REPLIES 11
Erwan SZYMANSKI
ST Employee

Hello @MWoło.2 ,
Do you want to use SAI interface or I2S interface ? 
For this codec, I2S seems to be the most "natural" to use, and you can find an example of configuration on this thread.

Kind regards,
Erwan.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hi Erwan,

I try and contact via the forum with the author. Unfortunately, I don't know how to connect mentioned Arduino module with I2S. When I use SAI I am able to find compatible signals like FS_A, SKC_A, SD_A. This is the only reason.

Exitst somewhere complete filled example how to use sai? In the link I attached above it's too many places with '...', very significant '...'. So let's try to find out what needs to be filled here.

Currently, I modified my sai in kernel dts to

 

&sai1{
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&sai1a_pins_mx>;
	pinctrl-1 = <&sai1a_sleep_pins_mx>;
	status = "okay";

	/* USER CODE BEGIN sai1 */
    #clock-cells = <0>;
    clocks = <&rcc SAI1>, <&scmi_clk CK_SCMI_PLL3_Q>, <&scmi_clk CK_SCMI_PLL3_R>;
    clock-names = "pclk", "x8k", "x11k";
    #sound-dai-cells = <1>;
	/* USER CODE END sai1 */

	sai1a:audio-controller@4400a004{
		status = "okay";
		dma-names = "tx";
		clocks = <&rcc SAI1_K>;
		clock-names = "sai_ck";
		i2s1_port: port {
			i2s1_endpoint: endpoint {
				remote-endpoint = <&codec_endpoint>;
				format = "i2s";
				mclk-fs = <256>;
			};
		};
		/* USER CODE END sai1a */
	};
};

 

And now it's look 

 

[   39.661471] st,stm32-sai-sub 4400a004.audio-controller: Missing dma channel for stream: 0
[   39.778031] st,stm32-sai-sub 4400a004.audio-controller: ASoC: error at snd_soc_pcm_component_new on 4400a004.audio-controller: -22

 

So the question is how to configure DMA correctly.

BR

Michal

Hello @MWoło.2 ,
I reproduced on my side and here you can find my corrections.

For your device tree:

 

	sound {
        compatible = "audio-graph-card";
        label = "STM32MP1-audio-test-card";
		routing =
			"Playback" , "MCLK";
		dais = <&sai1a_port>;
        status = "okay";
    };

    codec: pcm5102a-codec {
        compatible = "ti,pcm5102a";
        #sound-dai-cells = <0>;
        clocks = <&sai1a>;     /* 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 = <&sai1a_endpoint>;
				frame-master;    /* Set codec as master of SAI1A for FS clock. */
				bitclock-master; /* Set codec as master of SAI1A for SCK clock. */
            };
        };
    };
};

&sai1{
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&sai1_pins_a>;
	pinctrl-1 = <&sai1_sleep_pins_a>;
	status = "okay";

	/* USER CODE BEGIN sai1 */
    clocks = <&rcc SAI1>, <&scmi_clk CK_SCMI_PLL3_Q>, <&scmi_clk CK_SCMI_PLL3_R>;
    clock-names = "pclk", "x8k", "x11k";
    #sound-dai-cells = <1>;
	/* USER CODE END sai1 */

	sai1a:audio-controller@4400a004{
		status = "okay";
		dma-names = "tx";
		#clock-cells = <0>;
		clocks = <&rcc SAI1_K>;
		clock-names = "sai_ck";
		sai1a_port: port {
			sai1a_endpoint: endpoint {
				remote-endpoint = <&codec_endpoint>;
				format = "i2s";
				// mclk-fs = <256>;
			};
		};
		/* USER CODE END sai1a */
	};
};

 

Note: As you only use the "TX" cell of SAI, I removed the "Capture" route in sound node that is a "RX" functionality. You can modify it as you want.

For PCM5102A:

Find enclosed the patch I applied on the driver. Please consider that this a first step of what you probably need, but it maybe have to be improved regarding the cs41l52.c driver example.

I did not face your DMA issue, so be sure to have OSTL 4.1 without other modifications in other device trees.

I hope it will help you to go forward.
Kind regards,
Erwan.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hi,

I build the Openstlinux using

repo init -u https://github.com/STMicroelectronics/oe-manifest.git -b refs/tags/openstlinux-5.15-yocto-kirkstone-mp1-v22.11.23

but on building windows I see

Build Configuration:
BB_VERSION           = "2.0.0"
BUILD_SYS            = "x86_64-linux"
NATIVELSBSTRING      = "ubuntu-22.04"
TARGET_SYS           = "arm-ostl-linux-gnueabi"
MACHINE              = "mp1-sagittarius"
DISTRO               = "openstlinux-eglfs"
DISTRO_VERSION       = "4.0.4-snapshot-20230714"
TUNE_FEATURES        = "arm vfp cortexa7 neon vfpv4 thumb callconvention-hard"
TARGET_FPU           = "hard"
DISTRO_CODENAME      = "kirkstone"
ACCEPT_EULA_mp1-sagittarius = "0"
GCCVERSION           = "11.%"
PREFERRED_PROVIDER_virtual/kernel = "linux-stm32mp"
meta-sagittarius     = "kirkstone:4067e6030fdb6a63326e5e4cfbc52af472f4a886"
meta-st-stm32mp-addons = "HEAD:f1a18b73343afd8dd5f9aa7f5b605d139fb9e4a8"
meta-python          
meta-oe              
meta-gnome           
meta-initramfs       
meta-multimedia      
meta-networking      
meta-webserver       
meta-filesystems     
meta-perl            = "HEAD:05dcac98473402d87e0af73bbc2c5a6a840abe93"
meta-st-stm32mp      = "HEAD:ca501bd7dbe023682903ceedddaacd940b0898f4"
meta-qt5             = "HEAD:5b71df60e523423b9df6793de9387f87a149ac42"
meta-st-openstlinux  = "HEAD:cb736b403d0fef2a02390695613b6b4bb13ca1b7"
meta                 = "HEAD:f7766da462905ec67bf549d46b8017be36cd5b2a"

is it right?

 

Hello @MWoło.2 ,
It seems right for me for OSTL 4.1

Kind regards,
Erwan.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hi Erwan,

I think my problem is rather not directly related to DMA but to the clock or clocks. I remember a similar issue for ETH for STM32MP15x.

Now I connected SAI to PLL3Q and PLL3R. I'm curious about one thing. In the documentation, we can read

https://github.com/STMicroelectronics/linux/blob/v6.1-stm32mp/Documentation/devicetree/bindings/sound/st,stm32-sai.yaml

that 

          items:
            - description: pclk feeds the peripheral bus interface.
            - description: x8k, SAI parent clock for sampling rates multiple of 8kHz.
            - description: x11k, SAI parent clock for sampling rates multiple of 11.025kHz.

the clock should be multiplied by 8kHz and 11.025kHz accordingly.

I checked the clocks for DK2 and not match perfectly.

MWoo2_0-1689370432456.png

What do You think about it?

BR

Michal

MWoło.2
Senior II

After applying all suggestions and patching my log looks as follows

[   36.381276] platform 4400a004.audio-controller: Fixing up cyclic dependency with pcm5102a-codec
...
[   40.341794] stm32-dmamux 48002000.dma-router: Run out of free DMA requests
[   40.477203] stm32-dmamux 48002000.dma-router: Run out of free DMA requests
[   40.487823] st,stm32-sai-sub 4400a004.audio-controller: Missing dma channel for stream: 0
[   40.535104] st,stm32-sai-sub 4400a004.audio-controller: ASoC: error at snd_soc_pcm_component_new on 4400a004.audio-controller: -22
[   40.638737] asoc-audio-graph-card sound: ASoC: can't create pcm 4400a004.audio-controller-pcm5102a-hifi :-22
[   40.713549] asoc-audio-graph-card sound: parse error -22
[   40.717427] asoc-audio-graph-card: probe of sound failed with error -22
Erwan SZYMANSKI
ST Employee

@MWoło.2 ,
As you have a custom board, I think the issue now is linked to your DMA manipulation. Maybe too many drivers are using DMA and so you have not enough to use it with your audio codec.

To catch this, I point you another thread that deals with the same kind of issue here.

Kind regards,
Erwan.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hi Erwan,

You have right, I set too many interfaces like uart, i2c etc. Now I have no DMA issues.

After issue from command line aplay -l I get

root@mp1-sagittarius:~# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: STM32MP1audiote [STM32MP1-audio-test-card], device 0: 4400a004.audio-controller-pcm5102a-hifi pcm5102a-hifi-0 [4400a004.audio-controller-pcm5102a-hifi pcm5102a-hifi-0]
  Subdevices: 1/1

Now I'm curious how to play music using aplay or mpv, vlc etc.

When I issue from the command line alsamixer I get

root@mp1-sagittarius:~# alsamixer
ALSA lib ../../alsa-plugins-1.2.6/pulse/pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

cannot open mixer: Connection refused

the same with 

aplay -c 3 -t wav -r 44100 -f cd default.wav
ALSA lib ../../alsa-plugins-1.2.6/pulse/pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

aplay: main:831: audio open error: Connection refused

Hmmm, what's now?

BR

Michal