完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>
1.实验原理
FS-MP1A使用的是CS42L51音频芯片,SoC通过I2C和SAI与其进行数据交互,原理图如下: SAI2管脚对应关系: I2C5管脚对应关系: 芯片复位管脚对应关系:
参考文档: Documentation/devicetree/bindings/sound/st,stm32-sai.txt 内核中ST对STM32MP15x系列芯片的设备树资源了做了定义,可参见: sai2: sai@4400b000 { compatible = "st,stm32h7-sai"; #address-cells = <1>; #size-cells = <1>; ranges = <0 0x4400b000 0x400>; reg = <0x4400b000 0x4>, <0x4400b3f0 0x10>; interrupts = resets = <&rcc SAI2_R>; status = "disabled"; sai2a: audio-controller@4400b004 { #sound-dai-cells = <0>; compatible = "st,stm32-sai-sub-a"; reg = <0x4 0x1c>; clocks = <&rcc SAI2_K>; clock-names = "sai_ck"; dmas = <&dmamux1 89 0x400 0x01>; status = "disabled"; }; sai2b: audio-controller@4400b024 { #sound-dai-cells = <0>; compatible = "st,stm32-sai-sub-b"; reg = <0x24 0x1c>; clocks = <&rcc SAI2_K>; clock-names = "sai_ck"; dmas = <&dmamux1 90 0x400 0x01>; status = "disabled"; }; }; 上述代码只对SAI2做了基本的初始化,并没有针对不同的硬件设计做适配,所以需结合硬件补全设备树节点信息。 参考stm32mp15xx-dkx.dtsi对于SAI2设备节点的描述,增加SAI2内容如下: &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 = <&cs42l51_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 = <&cs42l51_rx_endpoint>; format = "i2s"; mclk-fs = <256>; dai-tdm-slot-num = <2>; dai-tdm-slot-width = <32>; }; }; }; }; 由于stm32mp15-pinctrl.dtsi中对于SAI2管脚的定义与FS-MP1A实际使用管脚一致,所以无需修改。
由于前文中已经增加过I2C5的节点信息,本节就不再重复,在原有I2C5节点添加CS42L51内容即可。 参考文档: Documentation/devicetree/bindings/sound/cs42l51.txt 参考stm32mp15xx-dkx.dtsi对于codec芯片设备节点的描述,增加内容如下: cs42l51: cs42l51@4a { compatible = "cirrus,cs42l51"; reg = <0x4a>; #sound-dai-cells = <0>; VL-supply = <&v3v3>; VD-supply = <&v1v8_audio>; VA-supply = <&v1v8_audio>; VAHP-supply = <&v1v8_audio>; reset-gpios = <&gpioc 0 GPIO_ACTIVE_LOW>; clocks = <&sai2a>; clock-names = "MCLK"; status = "okay"; cs42l51_port: port { #address-cells = <1>; #size-cells = <0>; cs42l51_tx_endpoint: endpoint@0 { reg = <0>; remote-endpoint = <&sai2a_endpoint>; frame-master; bitclock-master; }; cs42l51_rx_endpoint: endpoint@1 { reg = <1>; remote-endpoint = <&sai2b_endpoint>; frame-master; bitclock-master; }; }; };
前文已经说过如何添加电源节点,本节不再重复,在根节点添加&v1v8_audio节点,内容如下: v1v8_audio: regulator-v1v8_audio { compatible = "regulator-fixed"; regulator-name = "v1v8_audio"; regulator-min-microvolt = <1800000>; regulator-max-microvolt = <1800000>; regulator-always-on; regulator-boot-on; };
内核中包含audio-graph-card驱动,驱动将声卡各个部分关联起来,驱动正常工作需添加对应设备树节点。 参考文档: Documentation/devicetree/bindings/sound/audio-graph-card.txt 在根节点写下添加sound节点: sound { compatible = "audio-graph-card"; label = "STM32MP1-FSMP1A"; routing = "Playback" , "MCLK", "Capture" , "MCLK", "MICL" , "Mic Bias"; dais = <&sai2a_port &sai2b_port>; status = "okay"; }; 2.实验平台 华清远见开发环境,FS-MP1A平台; 3.实验目的 熟悉基于Linux操作系统下的音频设备驱动移植配置过程。 4.实验步骤
linux@ubuntu:$ source /opt/st/stm32mp1/3.1-openstlinux-5.4-dunfell-mp1-20-06-24/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
修改arch/arm/boot/dts/stm32mp15xx-fsmp1x.dtsi文件,在文件末尾添加如下内容: &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 = <&cs42l51_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 = <&cs42l51_rx_endpoint>; format = "i2s"; mclk-fs = <256>; dai-tdm-slot-num = <2>; dai-tdm-slot-width = <32>; }; }; }; };
修改arch/arm/boot/dts/stm32mp15xx-fsmp1x.dtsi文件,在I2C5节点中添加如下内容: cs42l51: cs42l51@4a { compatible = "cirrus,cs42l51"; reg = <0x4a>; #sound-dai-cells = <0>; VL-supply = <&v3v3>; VD-supply = <&v1v8_audio>; VA-supply = <&v1v8_audio>; VAHP-supply = <&v1v8_audio>; reset-gpios = <&gpioc 0 GPIO_ACTIVE_LOW>; clocks = <&sai2a>; clock-names = "MCLK"; status = "okay"; cs42l51_port: port { #address-cells = <1>; #size-cells = <0>; cs42l51_tx_endpoint: endpoint@0 { reg = <0>; remote-endpoint = <&sai2a_endpoint>; frame-master; bitclock-master; }; cs42l51_rx_endpoint: endpoint@1 { reg = <1>; remote-endpoint = <&sai2b_endpoint>; frame-master; bitclock-master; }; }; };
修改arch/arm/boot/dts/stm32mp15xx-fsmp1x.dtsi文件,在根节点中添加如下内容: v1v8_audio: regulator-v1v8_audio { compatible = "regulator-fixed"; regulator-name = "v1v8_audio"; regulator-min-microvolt = <1800000>; regulator-max-microvolt = <1800000>; regulator-always-on; regulator-boot-on; };
修改arch/arm/boot/dts/stm32mp15xx-fsmp1x.dtsi文件,在根节点中添加如下内容: sound { compatible = "audio-graph-card"; label = "STM32MP1-FSMP1A"; routing = "Playback" , "MCLK", "Capture" , "MCLK", "MICL" , "Mic Bias"; dais = <&sai2a_port &sai2b_port>; status = "okay"; };
由于内核源码默认配置以及支持CS42L51,本节列出主要选项,如下: linux@ubuntu:$ make menuconfig Device Drivers ---> <*> Sound card support ---> <*> Advanced Linux Sound Architecture ---> <*> ALSA for SoC audio support ---> STMicroelectronics STM32 SOC audio support ---> <*> STM32 SAI interface (Serial Audio Interface) support CODEC drivers ---> <*> Cirrus Logic CS42L51 CODEC (I2C) <*> ASoC Audio Graph sound card support
linux@ubuntu:$ make -j4 uImage dtbs LOADADDR=0xC2000040
将编译好的设备树和内核镜像拷贝到/tftpboot目录下,通过tftp引导内核,启动后启动信息中出现如下内容: 插上耳机,终端输入录音命令: root@fsmp1a:# arecord -D record_codec -f S16_LE -d 10 test.wav 终端输入播放命令: root@fsmp1a:# aplay test.wav 注意:由于3.5mm的4段式耳机接口还分为两种,一种是美标版(CTIA),也称为“苹果标准”,同时小米、魅族也是使用这种标准;另外一种是国标版(OMTP),也称为“诺基亚标准”,现在绝大多数诺基亚和大多数国产手机都是使用这种标准。FS-MP1A使用的是国标版,所以部分耳机并不能正常实现录播功能。 |
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
只有小组成员才能发言,加入小组>>
3143 浏览9 评论
2838 浏览16 评论
3345 浏览1 评论
8724 浏览16 评论
3941 浏览18 评论
9556浏览3评论
899浏览3评论
464浏览2评论
const uint16_t Tab[10]={0}; const uint16_t *p; p = Tab;//报错是怎么回事?
462浏览2评论
用NUC131单片机UART3作为打印口,但printf没有输出东西是什么原因?
2184浏览2评论
小黑屋|手机版|Archiver|德赢Vwin官网(湘ICP备2023018690号)
GMT+8, 2024-8-24 14:24, Processed in 0.988462 second(s), Total 79, Slave 60 queries .
Powered by德赢Vwin官网 网
© 2015bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号