Skip to main content
Visitor II
August 27, 2020
Question

how to connect stm32mp157c-dk2 with WM8960 Audio HAT

  • August 27, 2020
  • 2 replies
  • 3542 views

Hello everyone, I would like to connect the stm32mp157c-dk2 card with the wm8960 audio codec,here is the device tree configuration I made.

/* sound card*/
 
 snd_i2s2: snd_i2s2 {
 
 compatible = "audio-graph-card";
 widgets =
 "Microphone", "Mic Jack",
 "Line", "Line In",
 "Line", "Line Out",
 "Speaker", "Speaker",
 "Headphone", "Headphone Jack";
 
 
 routing =
 "Headphone Jack", "HP_L",
 "Headphone Jack", "HP_R",
 "Speaker", "SPK_LP",
 "Speaker", "SPK_LN",
 "LINPUT1", "Mic Jack",
 "LINPUT3", "Mic Jack",
 "RINPUT1", "Mic Jack",
 "RINPUT2", "Mic Jack";
 
 
 dais = <&i2s3_port>;
 status = "okay";
 };
 
/* i2s3 pin definition */
 
&pinctrl {
 
		i2s3_pins_a: i2s3-0 {
		
			pins1 {
				pinmux = <STM32_PINMUX('E', 12, AF5)>, /* SCK */
					<STM32_PINMUX('E', 14, AF5)>; /* SDI */
					bias-disable;
					drive-push-pull;
					slew-rate = <1>;
				};
 
				pins2 {
					pinmux = <STM32_PINMUX('E', 13, AF5)>; /* SDO */
					bias-disable;
				};
		};
 
		i2s3_pins_sleep_a:i2s3-1{
			pins {
				pinmux = <STM32_PINMUX('E', 12, ANALOG)>, /* SCK */
					 <STM32_PINMUX('E', 13, ANALOG)>, /* SDI */
					<STM32_PINMUX('E', 14, ANALOG)>; /* SDO */
			};
		};
 
 
};
 
/* codec control using i2c5*/
 
&i2c5 {
		pinctrl-names = "default", "sleep";
		pinctrl-0 = <&i2c5_pins_a>;
		pinctrl-1 = <&i2c5_pins_sleep_a>;
		i2c-scl-rising-time-ns = <185>;
		i2c-scl-falling-time-ns = <20>;
		status = "okay";
		/delete-property/dmas;
		/delete-property/dma-names;
		 
		// Device tree node for Audio Codec
 
		wm8960: wm8960@1a { 
				compatible = "wlf,wm8960";
				reg = <0x1a>;
				AVDD-supply = <&v3v3>;
				clocks = <&rcc SPI3>;
				clock-names = "mclk";
				wlf,shared-lrclk;
				 
				codec_port: port@0 {
					codec_endpoint: endpoint {
						remote-endpoint = <&i2s3_endpoint>;
					};
				};
 
		};
 
};
 
 
 
 
/* audio dai */
 
&i2s3 {
		clocks = <&rcc SPI3>, <&rcc SPI3_K>, <&rcc PLL3_Q>, <&rcc PLL3_R>;
		clock-names = "pclk", "i2sclk", "x8k", "x11k";
		pinctrl-names = "default", "sleep";
		pinctrl-0 = <&i2s3_pins_a>;
		pinctrl-1 = <&i2s3_pins_sleep_a>;
		status = "okay";
		 
		i2s3_port: port {
			i2s3_endpoint: endpoint {
				remote-endpoint = <&codec_endpoint>;
				format = "i2s";
				mclk-fs = <256>;
			};
		};
};

I have the following error showing when I try to record audio.

arecord: pcm_read:2143: read error: input/output error

[   2.215178] st,stm32-i2s 4000c000.audio-controller: No cache defaults, reading back from HW

thank you in advance

    This topic has been closed for replies.

    2 replies

    ST Employee
    August 27, 2020

    Hello @l_Homme​ ,

    Could you please confirm that you reworked your board to be able to use IIS from Rpi connector ?

    • SB1, SB2, SB3 and SB4 have to be unsoldered (in order to disconnect embedded audio codec)
    • SB13, SB14, SB15 and SB16 have to be closed to connect IIS to SAI2.

    The schematic available in the wiki : Link.

    I'am not sure to understand the i2s3 entry in the DT, because I think that codec_endpoint needs to be connected to SAI.

    	wm8960: wm8960{
    	[...]
    		ports {
    			[...]
    			wm8960_tx_endpoint: port@0 {
    				reg = <0>;
    				remote-endpoint = <&sai2a_endpoint>;
    			};
     
    			wm8960_rx_endpoint: port@1 {
    				reg = <1>;
    				remote-endpoint = <&sai2b_endpoint>;
    			};
    		};
    	};

    And connect them to SAI like the hereafter patch :

     		sai2a_port: port {
     			sai2a_endpoint: endpoint {
    -				remote-endpoint = <&cs42l51_tx_endpoint>;
    +				remote-endpoint = <&wm8960_tx_endpoint>;
     				format = "i2s";
     				mclk-fs = <256>;
     				dai-tdm-slot-num = <2>;
     				dai-tdm-slot-width = <32>;
     			};
     
     
     		sai2b_port: port {
     			sai2b_endpoint: endpoint {
    -				remote-endpoint = <&cs42l51_rx_endpoint>;
    +				remote-endpoint = <&wm8960_rx_endpoint>;
     				format = "i2s";
     				mclk-fs = <256>;
     				dai-tdm-slot-num = <2>;
     				dai-tdm-slot-width = <32>;
     			};
     		};

    BR,

    Christophe

    l_HommeAuthor
    Visitor II
    August 27, 2020

    thanks for your answer,

    however i want to use both codecs, that of the stm32mp1 card (CS42L51) and my new external codec.

    so replace the remote-endpoint = <& cs42l51_rx_endpoint>; by remote-endpoint = <& wm8960_rx_endpoint>; don't bother me. you offer me what solution? thank you

    Visitor II
    September 5, 2020

    hello,

    Have you solved the problem? I have the same problem as you。

     sound: sound {
     compatible = "audio-graph-card";
     label = "STM32MP1-DK";
     
     widgets =
     "Microphone", "Mic Jack",
     "Line", "Line In",
     "Line", "Line Out",
     "Speaker", "Speaker",
     "Headphone", "Headphone Jack";
     
     routing =
     "Headphone Jack", "HP_L",
     "Headphone Jack", "HP_R",
     "Speaker", "SPK_LP",
     "Speaker", "SPK_LN",
     "Speaker", "SPK_RP",
     "Speaker", "SPK_RN",
     "LINPUT1", "Mic Jack",
     "LINPUT3", "Mic Jack",
     "RINPUT1", "Mic Jack",
     "RINPUT2", "Mic Jack";
     
     dais = <&sai2a_port &sai2b_port &sai4a_port &spdifrx_port &i2s2_port>;
     status = "okay";
     };
     
    &sai2 {
     clocks = <&rcc SAI2>, <&rcc PLL3_Q>, <&rcc PLL3_R>;
     clock-names = "pclk", "x8k", "x11k";
     pinctrl-names = "default", "sleep";
     pinctrl-0 = <&sai2a_pins_a>, <&sai2b_pins_b>;
     pinctrl-1 = <&sai2a_sleep_pins_a>, <&sai2b_sleep_pins_b>;
     status = "okay";
     
     sai2a: audio-controller@4400b004 {
     #clock-cells = <0>;
     dma-names = "tx";
     clocks = <&rcc SAI2_K>;
     clock-names = "sai_ck";
     status = "okay";
     
     sai2a_port: port {
     sai2a_endpoint: endpoint {
     remote-endpoint = <&wm8960_tx_endpoint>;
     format = "i2s";
     mclk-fs = <256>;
     dai-tdm-slot-num = <2>;
     dai-tdm-slot-width = <32>;
     };
     };
     };
     sai2b: audio-controller@4400b024 {
     dma-names = "rx";
     st,sync = <&sai2a 2>;
     clocks = <&rcc SAI2_K>, <&sai2a>;
     clock-names = "sai_ck", "MCLK";
     status = "okay";
     
     sai2b_port: port {
     sai2b_endpoint: endpoint {
     remote-endpoint = <&wm8960_rx_endpoint>;
     format = "i2s";
     mclk-fs = <256>;
     dai-tdm-slot-num = <2>;
     dai-tdm-slot-width = <32>;
     };
     };
     };
    };
     wm8960: wm8960@1a {
     compatible = "wlf,wm8960";
     reg = <0x1a>;
     #sound-dai-cells = <0>;
     status = "okay";
     //wlf,shared-lrclk;
     wlf,capless;
     clocks = <&sai2a>;
     clock-names = "MCLK1";
     
     ports {
     #address-cells = <1>;
     #size-cells = <0>;
     
     wm8960_tx_port: port@0 {
     reg = <0>;
     wm8960_tx_endpoint: endpoint {
     remote-endpoint = <&sai2a_endpoint>;
     };
     };
     
     wm8960_rx_port: port@1 {
     reg = <1>;
     wm8960_rx_endpoint: endpoint {
     remote-endpoint = <&sai2b_endpoint>;
     };
     };
     };

    I have the following error showing when I try to record audio.

    arecord: pcm_read:2143: read error: input/output error

    [  4.369396] st,stm32-i2s 4000b000.audio-controller: No cache defaults, reading back from HW