开发环境
- Linux SDK:LubanCat_Linux_rk356x_SDK_20260418
开发环境配置
安装ssh
sudo apt install openssh-server -y
安装依赖
sudo apt install git ssh make gcc libssl-dev liblz4-tool u-boot-tools curl \expect g++ patchelf chrpath gawk texinfo chrpath diffstat binfmt-support \qemu-user-static live-build bison flex fakeroot cmake gcc-multilib g++-multilib \unzip device-tree-compiler python3-pip libncurses5-dev python3-pyelftools dpkg-devsudo apt install gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu
安装repo
mkdir ~/bincurl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repochmod a+x ~/bin/repoecho PATH=~/bin:$PATH >> ~/.bashrcsource ~/.bashrcrepo --version
切换默认python版本
sudo ln -sf /usr/bin/python3 /usr/bin/python
Git配置
git config --global user.name "your name"git config --global user.email "your mail"
系统编译
加载SDK代码
mkdir ~/LubanCat_SDKmv LubanCat_Linux_rk356x_SDK_20260418.tar LubanCat_SDK/cd ~/LubanCat_SDKtar -xvf LubanCat_Linux_rk356x_SDK_20260418.tarrm -rf LubanCat_Linux_rk356x_SDK_20260418.tar.repo/repo/repo sync -l
构建Linux版本
./build.sh lunchWhich would you like? [0]: 5sudo dpkg -i ubuntu/ubuntu-build-service/packages/*sudo apt-get install -f./build.sh
编译产物位于rockdev/目录下update.img。 使用RKDevTools烧录即可。
让ssh支持root登录
sudo sh -c 'echo "PermitRootLogin yes" >> /etc/ssh/sshd_config'sudo systemctl restart sshd
I2S3声卡驱动
I2S3设备树
创建文件LubanCat_SDK\kernel\arch\arm64\boot\dts\rockchip\overlay\i2s3-max98357a-overlay.dts:
/dts-v1/;/plugin/;/ { compatible = "rockchip,rk3568"; fragment@0 { target = <&i2s3_2ch>; __overlay__ { status = "okay"; pinctrl-names = "default"; pinctrl-0 = <&i2s3m1_sclk &i2s3m1_lrck &i2s3m1_sdi &i2s3m1_sdo>; }; }; fragment@1 { target-path = "/"; __overlay__ { dummy_codec: dummy-codec { compatible = "rockchip,dummy-codec"; #sound-dai-cells = <0>; status = "okay"; }; }; }; fragment@2 { target-path = "/"; __overlay__ { i2s3_sound_card: i2s3-sound-card { status = "okay"; compatible = "simple-audio-card"; simple-audio-card,name = "I2S3 Dummy Sound Card"; simple-audio-card,format = "i2s"; simple-audio-card,mclk-fs = <256>; simple-audio-card,cpu { sound-dai = <&i2s3_2ch>; }; simple-audio-card,codec { sound-dai = <&dummy_codec>; }; }; }; };};
物理连线(RK2566 --> MAX98357A):
编译设备树
在LubanCat_SDK\kernel\中执行:
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- lubancat2_defconfigmake ARCH=arm64 -j4 CROSS_COMPILE=aarch64-linux-gnu- dtbs
把生成的~/LubanCat_SDK/kernel/arch/arm64/boot/dts/rockchip/overlay/i2s3-max98357a-overlay.dtbo推到开发板的/boot/dtb/overlay/下。 然后在/boot/uEnv/uEnvLubanCat1.txt添加:
dtoverlay=/dtb/overlay/i2s3-max98357a-overlay.dtbo
重启。
I2S3声卡测试
root@lubancat:~# aplay -l**** List of PLAYBACK Hardware Devices ****card 0: Card [I2S3 Dummy Sound Card], device 0: fe430000.i2s-dummy_codec dummy-codec-0 [fe430000.i2s-dummy_codec dummy-codec-0] Subdevices: 1/1 Subdevice #0: subdevice #0card 1: rockchiphdmi [rockchip,hdmi], device 0: fe400000.i2s-i2s-hifi i2s-hifi-0 [fe400000.i2s-i2s-hifi i2s-hifi-0] Subdevices: 1/1 Subdevice #0: subdevice #0card 2: rockchiprk809co [rockchip,rk809-codec], device 0: fe410000.i2s-rk817-hifi rk817-hifi-0 [fe410000.i2s-rk817-hifi rk817-hifi-0] Subdevices: 1/1 Subdevice #0: subdevice #0
可以看到I2S3声卡注册成功了,使用下面的命令播放测试:
speaker-test -t sine -f 500 -D hw:0,0 -c 2speaker-test -t wav -D hw:0,0 -c 2
正常能够听到左声道声音,但是起播和停播会有爆破音,这是由于SD_MODE一直高电平,不播放的时候应该拉低静音,我们需要使用MAX98357A驱动来控制SD_MODE。
MAX98357A驱动
设备树修改
修改i2s3-max98357a-overlay.dts:
/dts-v1/;/plugin/;#include<dt-bindings/gpio/gpio.h>#include<dt-bindings/pinctrl/rockchip.h>/ { // 鲁班猫1(RK3566)的兼容型号 compatible = "rockchip,rk3568"; // 片段0:启用 I2S3 控制器 fragment@0 { target = <&i2s3_2ch>; __overlay__ { status = "okay"; // 配置引脚复用。请根据实际接线确认是 M0 还是 M1 组引脚 pinctrl-names = "default"; pinctrl-0 = <&i2s3m1_sclk &i2s3m1_lrck &i2s3m1_sdi &i2s3m1_sdo>; }; }; // 片段1:创建 max98357a Codec 节点 fragment@1 { target-path = "/"; // 在根节点下添加 __overlay__ { max98357a: max98357a { compatible = "maxim,max98357a"; #sound-dai-cells = <0>; sdmode-gpios = <&gpio1 RK_PB2 GPIO_ACTIVE_HIGH>; status = "okay"; }; }; }; // 片段2:添加 simple-audio-card 进行绑定 fragment@2 { target-path = "/"; // 在根节点下添加声卡节点 __overlay__ { i2s3_sound_card: i2s3-sound-card { status = "okay"; compatible = "simple-audio-card"; // 声明使用通用声卡驱动框架 simple-audio-card,name = "I2S3 MAX98357A Sound Card"; // 声卡名称 simple-audio-card,format = "i2s"; // 音频数据格式 simple-audio-card,mclk-fs = <256>; // 绑定 CPU 侧:指向片段0启用的 I2S3 控制器 simple-audio-card,cpu { sound-dai = <&i2s3_2ch>; }; // 绑定 Codec 侧:指向片段1定义的 max98357a 节点 simple-audio-card,codec { sound-dai = <&max98357a>; }; }; }; };};
MAX98357A驱动
在LubanCat_SDK\kernel\sound\soc\codecs\Makefile添加:
obj-m += snd-soc-max98357a.o
编译驱动
在LubanCat_SDK\kernel\中执行:
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- lubancat2_defconfigmake ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- M=sound/soc/codecs modules
把LubanCat_SDK/kernel/sound/soc/codecs/snd-soc-max98357a.ko推送到开发板的/root/下,然后在/root/下执行:
insmod snd-soc-max98357a.ko
再次测试,现在播放正常了。