This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

  • Resolved

Linux/AM3359: I2S microphone configuration

Prodigy 200 points

Replies: 54

Views: 9664

Part Number: AM3359

Tool/software: Linux

I am trying to interface an I2S microphone (https://www.adafruit.com/product/3421) with BeagleBone Black. I followed the article (http://www.ti.com/lit/an/sprac97/sprac97.pdf), and able to update the device tree, and the Linux kernel as suggested in the article. 

The I2S component (for microphone) of the device tree is included as a dtsi in the main device tree source. The content of the dtsi is as below


&am33xx_pinmux {
        mcasp1_pins: mcasp1_pins {
             pinctrl-single,pins = <
                /* sink must enable receivers */
                0x1a0 0x23
                /* P9_42 mcasp1_aclkx - bit clock */
                0x1a4 0x23
                /* P9_27 mcasp1_fsx - frame sync */
                0x1a8 0x23
                /* P9_41 mcasp1_axr0 - i2s input */
             >;
        };
};

&mcasp1 {
        #sound-dai-cells = <0>;
        pinctrl-names = "default";
        pinctrl-0 = <&mcasp1_pins>;
        status = "okay";
        op-mode = <0>;
        tdm-slots = <2>;
        num-serializer = <4>;
        serial-dir = < /* 1 TX 2 RX 0 unused */
                2 0 0 0
                >;
        rx-num-evt = <1>;
        tx-num-evt = <1>;
};

/ {
        pcm5102a: pcm5102a {
                #sound-dai-cells = <0>;
                compatible = "ti,pcm5102a";
                status = "okay";
        };

        sound1: sound@1 {
                compatible = "simple-audio-card";
                simple-audio-card,name = "PCM5102a";
                simple-audio-card,format = "i2s";
                simple-audio-card,bitclock-master = <&sound1_master>;
                simple-audio-card,frame-master = <&sound1_master>;
                simple-audio-card,bitclock-inversion;

                simple-audio-card,cpu {
                        sound-dai = <&mcasp1>;
                };

                sound1_master: simple-audio-card,codec {
                #sound-dai-cells = <0>;
                sound-dai = <&pcm5102a>;
                clocks = <&mcasp1_fck>;
                clock-names = "mclk";
                };
        };
};


I have also compiled the kernel with a new driver pcm5102 as suggested in the document. Finally, I see the driver listed in the output of the arecord command.

root@arm:/sys/class/gpio# arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: PCM5102a [PCM5102a], device 0: davinci-mcasp.0-pcm5102a-hifi pcm5102a-hifi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0


However whenever I try to record audio, I am not getting any audio data. The audio file is formed, but the file size is always 44 bytes irrespective of how long I try to record audio for. Clearly no data is there in the file. 

Recording using arecord command gives error as below

arecord -d 10 -Dhw:0,0 -f dat audio.wav
Recording WAVE 'audio.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
arecord: pcm_read:2032: read error: Input/output error

Moreover, whenever I try to connect the clock (MCASP1_ACLKR (Bit Clock) - P9_42) with my oscilloscope, I don't see any pulses. Looks like there is no proper clock signal on this pin. What can I do to debug, and fix this?

Any ideas?

Parag

 
  • Hi Parag,

    Parag Sharma
    mcasp1_pins: mcasp1_pins { pinctrl-single,pins = < /* sink must enable receivers */ 0x1a0 0x23 /* P9_42 mcasp1_aclkx - bit clock */

    Parag Sharma
    simple-audio-card,bitclock-master = <&sound1_master>;

    Parag Sharma
    sound1_master: simple-audio-card,codec { #sound-dai-cells = <0>; sound-dai = <&pcm5102a>; clocks = <&mcasp1_fck>; clock-names = "mclk"; };

    Parag Sharma
    Moreover, whenever I try to connect the clock (MCASP1_ACLKR (Bit Clock) - P9_42) with my oscilloscope, I don't see any pulses. Looks like there is no proper clock signal on this pin. What can I do to debug, and fix this?

    You configure your AM335x McASP1 module as slave, thus you need to provide the bit clock from PCM5102A dummy codec to AM335x pin B12 MCASP0_ACLKR.mcasp1_aclkx

    Check in user space (with devmem2 or omapconf tool) that you have the correct value in register CONF_MCASP0_ACLKR/0x44E109A0.

    The bit clock scheme of the link you have provided is:

    PCM1864 ADC --> C5517 DSP J29_Pin3 --> AM335x McASP1 P9_42/B12

    Your bit clock scheme should be:

    Adafruit MIC --> AM335x McASP1 P9_42/B12

    Check also below pointers for audio debug guidelines:

    http://processors.wiki.ti.com/index.php/Linux_Core_Audio_User's_Guide#If_there.27s_an_issue

    Regards,
    Pavel



  • In reply to Pavel Botev:

    Hi Pavel,

    Thanks for your help in figuring this out. However is it possible to configure AM335x McASP1 module as master instead of slave so it itself can drive the clock?

  • In reply to Parag Sharma:

    Parag,

    Yes, you can configure AM335x McASP module as a master.

    SND_SOC_DAIFMT_CBS_CFS - McASP is master for bit clock and frame sync

    Refer to the below pointers for more info:

    www.ti.com/.../sprac09a.pdf
    5.2 Data Format and Clocking
    5.3 Example: McASP3 in I2S Mode

    processors.wiki.ti.com/.../Sitara_Linux_Audio_DAC_Example


    Regards,
    Pavel



  • In reply to Pavel Botev:

    Hi ,Pavel

    I Configured the Mcasp0 and device tree according to the processors.wiki.ti.com/.../Sitara_Linux_Audio_DAC_Example

    I am seeing clock out on both bclk and fsclk and data is being transmitted ,but

    when i try to configure it in Capture mode the bitclock is present but it is not of the required form and the fsclk is entirely missing.

    Please suggest a solution.

  • In reply to AJINKYA PRABHU:

    Ajinkya,

    Which version of AM335x TI PSDK (if any) you are using?

    processors.wiki.ti.com/.../Sitara_Linux_Audio_DAC_Example

    This wiki is valid for old kernel versions. For latest (4.9) kernel versions, you should use DTS files. See the below doc, it is more up to date:

    www.ti.com/.../sprac97.pdf

    If issue remains, please attach your latest DTS file for review.

    Regards,
    Pavel



  • In reply to Pavel Botev:

    /*
     * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
     *
     * This program is free software; you can redistribute it and/or modify
     * it under the terms of the GNU General Public License version 2 as
     * published by the Free Software Foundation.
     */
    /dts-v1/;
     
    #include "am33xx.dtsi"
    #include "am335x-bone-common.dtsi"
     
    &ldo3_reg {
    	regulator-min-microvolt = <1800000>;
    	regulator-max-microvolt = <3300000>;
    	regulator-always-on;
    };
     
    &mmc1 {
    	vmmc-supply = <&ldo3_reg>;
    };
     
    &am33xx_pinmux {
    	mcasp0_pins: mcasp0_pins {
    		pinctrl-single,pins = <
    			0x190 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)	/* mcasp0_aclkx */
    			0x194 (PIN_OUTPUT_PULLDOWN | MUX_MODE0)	/* mcasp0_fsx*/
    			0x198 (PIN_INPUT_PULLDOWN | MUX_MODE0)	/* mcasp0_axr0 */
    		>;
    	};
    };
     
    &mcasp0 {
    		pinctrl-names = "default";
    		pinctrl-0 = <&mcasp0_pins>;
    		status = "okay";
    		op-mode = <0>;          /* MCASP_IIS_MODE */
    		tdm-slots = <2>;
    		/* 16 serializer */
    		serial-dir = <  /* 0: INACTIVE, 1: TX, 2: RX */
    			2 1 0 0
    		>;
    		tx-num-evt = <32>;
    		rx-num-evt = <32>;
    };
     
    / {
     
    	pcm5102a: pcm5102a {
    		compatible = "ti,pcm5102a";
    	};
     
    	sound {
    		compatible = "ti,pcm5102a-evm-audio";
    		ti,model = "TI PCM5102A";
    		ti,audio-codec = <&pcm5102a>;
    		ti,mcasp-controller = <&mcasp0>;
    		ti,codec-clock-rate = <24000000>;
    	};
     
    };

    Hi Pavel I am using ti-processor-sdk-linux-am335x-evm-04.03.00.05

    and the dts I am using is

  • In reply to AJINKYA PRABHU:

    AJINKYA PRABHU
    sound { compatible = "ti,pcm5102a-evm-audio";

    You should use "simple-audio-card"

    sound {
            compatible = "simple-audio-card";

    Refer to the below e2e thread for more info:

    Regards,
    Pavel



  • In reply to Pavel Botev:

    changing it from

    sound { compatible = "ti,pcm5102a-evm-audio";

    to

    sound { compatible = "simple-audio-card";

    causes this :

    sh-3.2# arecord -l
    arecord: device_list:268: no soundcards found...
    sh-3.2# aplay -l
    aplay: device_list:268: no soundcards found...
    

    using pcm5102a-evm-audio gives this

    sh-3.2# aplay -l
    **** List of PLAYBACK Hardware Devices ****
    card 0: PCM5102A [TI PCM5102A], device 0: Capture pcm5102a-hifi-0 []
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    sh-3.2# arecord -l
    **** List of CAPTURE Hardware Devices ****
    card 0: PCM5102A [TI PCM5102A], device 0: Capture pcm5102a-hifi-0 []
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    

    using pcm5102a-evm-audio give both clocks for aplay

    and BCLK

    But arecord gives:

    (arecord -Dhw:0,0 -f dat asddd.wav)

    for FSCLK

    BCLK

  • In reply to AJINKYA PRABHU:

    AJINKYA PRABHU

    changing it from

    sound { compatible = "ti,pcm5102a-evm-audio";

    to

    sound { compatible = "simple-audio-card";

    causes this :

    sh-3.2# arecord -l
    arecord: device_list:268: no soundcards found...
    sh-3.2# aplay -l
    aplay: device_list:268: no soundcards found...

    This is because you change only "compatible", but that is not enough. You should change more things in DTS, as explained in sprac97.pdf

    4.2.3.1 Simple Audio Card
    Plumbing between the PCM5102A device driver and the AM335X processor is done in the device tree with the simple-audio-card device tree bindings. For more information about available simple-audio-card device tree properties, see the following kernel documentation:

    Documentation/devicetree/bindings/sound/simple-card.txt

    pcm5102a: pcm5102a {
        #sound-dai-cells = <0>;
        compatible = "ti,pcm5102a";
        status = "okay";
    };

    sound1: sound@1 {
        compatible = "simple-audio-card";
        simple-audio-card,name = "PCM5102a";
        simple-audio-card,format = "i2s";
        simple-audio-card,bitclock-master = <&sound1_master>;
        simple-audio-card,frame-master = <&sound1_master>;
        simple-audio-card,bitclock-inversion;
        
        simple-audio-card,cpu {
            sound-dai = <&mcasp1>;
        };

    sound1_master: simple-audio-card,codec {
        #sound-dai-cells = <0>;
        sound-dai = <&pcm5102a>;
        clocks = <&mcasp1_fck>;
        clock-names = "mclk";
    };



  • In reply to AJINKYA PRABHU:

    AJINKYA PRABHU

    using pcm5102a-evm-audio gives this

    sh-3.2# aplay -l
    **** List of PLAYBACK Hardware Devices ****
    card 0: PCM5102A [TI PCM5102A], device 0: Capture pcm5102a-hifi-0 []
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    sh-3.2# arecord -l
    **** List of CAPTURE Hardware Devices ****
    card 0: PCM5102A [TI PCM5102A], device 0: Capture pcm5102a-hifi-0 []
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    

    using pcm5102a-evm-audio give both clocks for aplay

    Who is supposed to provide the FS and BCLK signals? Is it AM335x device?

    Please provide full console log of arecord and aplay commands. Provide also register dump of McASP pinmux registers and McASP module registers.

    Regard,
    Pavel



This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.