Linux平台移植音频芯片实战记录

发表时间:2024-05-17 09:41

本文详细记录在NXP I.MX6ULL+Linux平台下进行WM8960音频芯片移植的过程,其他平台操作方法类似,希望为大家提供帮助。

1. 环境准备

平台: HD6ULL-IOT开发板

要求: 外接一个WM8960模块。要求能正常播放音频文件。

2. 原理图及相关资料

将模块飞线到底板J17上,接法如下;且模块1脚 接了J17的1脚(3.3V); 然后模块的3脚(GND)接的J17的29脚地。

20240517




WM8960资料:

https://www.waveshare.net/wiki/WM8960_Audio_Board

3. 内核以及设备树调试

内核需要勾选WM8960相关配置,可以make menuconfig后/搜索8960然后勾上就行。       

设备树注意三点:

①. 客户飞线WM8960是挂载到i2c1上的。

sound {compatible = "fsl,imx6ul-evk-wm8960","fsl,imx-audio-wm8960";model = "wm8960-audio";cpu-dai = <&sai2>;audio-codec = <&codec>;asrc-controller = <&asrc>;codec-master;gpr = <&gpr>;/*not support* hp-det = <hp-det-pin hp-det-polarity>;* hp-det-pin: JD1 JD2   or JD3* hp-det-polarity = 0: hp detect high for headphone* hp-det-polarity = 1: hp detect high for speakerhp-det = <3 0>;hp-det-gpios = <&gpio5 4 0>;mic-det-gpios = <&gpio5 4 0>;*/audio-routing ="Headphone Jack", "HP_L","Headphone Jack", "HP_R","Ext Spk", "SPK_LP","Ext Spk", "SPK_LN","Ext Spk", "SPK_RP","Ext Spk", "SPK_RN","LINPUT2", "Mic Jack","LINPUT3", "Mic Jack","RINPUT1", "Main MIC","RINPUT2", "Main MIC","Mic Jack", "MICB","Main MIC", "MICB","CPU-Playback", "ASRC-Playback","Playback", "CPU-Playback","ASRC-Capture", "CPU-Capture","CPU-Capture", "Capture";};};&sai2 {pinctrl-names = "default";pinctrl-0 = <&pinctrl_sai2>;assigned-clocks = <&clks IMX6UL_CLK_SAI2_SEL>,<&clks IMX6UL_CLK_SAI2>;assigned-clock-parents = <&clks IMX6UL_CLK_PLL4_AUDIO_DIV>;assigned-clock-rates = <0>, <12288000>;status = "okay";};pinctrl_sai2: sai2grp {fsl,pins = <MX6UL_PAD_JTAG_TDI__SAI2_TX_BCLK0x17088MX6UL_PAD_JTAG_TDO__SAI2_TX_SYNC0x17088MX6UL_PAD_JTAG_TRST_B__SAI2_TX_DATA0x11088MX6UL_PAD_JTAG_TCK__SAI2_RX_DATA0x11088MX6UL_PAD_JTAG_TMS__SAI2_MCLK0x17088MX6UL_PAD_SNVS_TAMPER4__GPIO5_IO040x17059>;};&i2c1 {clock-frequency = <100000>;pinctrl-names = "default";pinctrl-0 = <&pinctrl_i2c1>;status = "okay";codec: wm8960@1a {compatible = "wlf,wm8960";reg = <0x1a>;clocks = <&clks IMX6UL_CLK_SAI2>;clock-names = "mclk";wlf,shared-lrclk;};};pinctrl_i2c1: i2c1grp {fsl,pins = <MX6UL_PAD_CSI_PIXCLK__I2C1_SCL 0x4001b8b0MX6UL_PAD_CSI_MCLK__I2C1_SDA 0x4001b8b0>;};

②. 时钟线(SCL)和数据线(SDA)是飞线到J17的3,4脚(UART6_TXD,UART6_RXD),对应的CSI_MCLK与CSI_PIXCLK,我们需要将其复用成I2C1_SCL,I2C1_SDA功能。(需要查询对应的引脚功能列表和datasheet)

pinctrl_i2c1: i2c1grp {fsl,pins = <MX6UL_PAD_CSI_PIXCLK__I2C1_SCL0x4001b8b0MX6UL_PAD_CSI_MCLK__I2C1_SDA0x4001b8b0>;};

③. 由于底板上有一个耳机接口是从核心板直接引出的,我们需要禁掉他。

sound-mqs {compatible = "fsl,imx-audio-mqs";model = "mqs-audio";cpu-dai = <&sai1>;asrc-controller = <&asrc>;audio-codec = <&mqs>;status = "disabled";};&sai1 {assigned-clocks = <&clks IMX6UL_CLK_SAI1_SEL>,<&clks IMX6UL_CLK_SAI1>;assigned-clock-parents = <&clks IMX6UL_CLK_PLL4_AUDIO_DIV>;assigned-clock-rates = <0>, <24576000>;status = "disabled";};&mqs {pinctrl-names = "default";pinctrl-0 = <&pinctrl_mqs>;clocks = <&clks IMX6UL_CLK_SAI1>;clock-names = "mclk";status = "disabled";};

重新编译后替换设备树,然后cd /home/audio ./aplay 1.wav。插上耳机或者扬声器即有声音。

在调试过程中,可通过i2cdetect -y -a 0 (此处wm8960挂载在i2c1)检查音频设备是否挂载到i2c1上,或者dmesg | grep wm8960 检查驱动是否加载成功。

4. 录音测试

首先需要有arecord这个工具;

源码下载网址:https://www.alsa-project.org/wiki/Download#alsa-lib

编译参考网址: https://blog.csdn.net/gjy938815/article/details/11809269

编译好后:alsa-utils-1.2.9\aplay 这个目录下会生成aplay(145M),然后改名为arecord即可。

录音播放测试:

将arecord拷贝到U盘内,依次执行以下指令:cp/mnt/sda1/arecord /home/demo/chmoda+x /home/demo/arecordcd/home/audio/./amixercset numid=1 60 录音功能需设置录音控件的参数./amixercset numid=36 240 录音功能需设置录音控件的参数./amixercset numid=41 1 将麦克风输出信号同时记录在左右声道cd/home/demo执行下面这个指令时需要对着WM8960说话,会录音到/tmp/t.wav文件中。录音时间为10s./arecord-f cd -d 10 /tmp/t.wav播放录音文件(最好用耳机听声音)cd/home/audio/./aplay/tmp/t.wav

5. 音量调节

控制耳机音量大小:numid=11,iface=MIXER,name='Headphone Playback Volume'./amixer cset numid=11 80 (范围0~127, 80合适)控制喇叭音量大小:numid=13,iface=MIXER,name='Speaker Playback Volume' 这个配置./amixer cset numid=13 100 (范围0~127,但一般100声音就合适了)录音时配置:numid=36,iface=MIXER,name='ADC PCM Capture Volume'./amixer cset numid=36 190 (录音范围0~255,一般190左右合适,值过大杂声会有点大)numid=1,iface=MIXER,name='Capture Volume' (设置捕获的音量)./amixer cset numid=1 30     (范围0~63 ,可以选择30)

至此,我们完成移植、测试的全部工作。如您在开发过程中遇到问题,欢迎技术交流。





武汉万象奥科电子有限公司
服务热线:027-59610091
销售邮箱:sales@vanxoak.com
主营产品:ARM核心板、ARM工控板
工业网关、软硬件定制设计
地址:武汉东湖新技术开发区大学园路长城园路8号海容基孵化园B5

扫描二维码
关注公众号
产品及方案咨询
专业专注   合作共赢
移动电话:181 2058 0511 (湖北)
移动电话:175 7010 9551 (华南、华中)
移动电话:133 0386 9667 (华东、华北)
移动电话:187 3812 7320 (其他)