文章目录
- 1、环境介绍
- 2、目标
- 3、海华AW-CM358SM
- 3.1、基本信息
- 3.2、支持SDIO3.0
- 3.3、电气特性
- 4、适配流程步骤
- 5、让SDIO控制器工作,且可以扫到WIFI卡
- 5.1、dts配置
- 5.2、验证
- 6、Wi-Fi 适配
- 6.1、dts配置
- 6.2、驱动移植
- 6.2.1、kernel menuconfig
- 6.2.2、传统驱动移植
- 6.2.3、RK SDK WIFI/BT驱动独立编译
- 7、Wi-Fi 功能验证
- 7.1、加载驱动
- 7.2、STA模式测试
- 7.3、AP测试
- 8、蓝牙适配
- 8.1、dts配置
- 8.2、驱动移植
- 9、蓝牙功能验证
1、环境介绍
硬件:飞凌ok3568-c开发板
软件:原厂rk356x sdk
2、目标
调试海华AW-CM358SM WIFI/BT模组,可以正常上网、使用蓝牙。
3、海华AW-CM358SM
3.1、基本信息
[外链图片转存中…(img-52nV7zF1-1734873834365)]
-
主芯片:NXP的88W8987
-
Wi-Fi接口:SDIO
-
BT接口:UART
3.2、支持SDIO3.0
3.3、电气特性
AW-CM358SM的VDDIO为1.8V:
所以,RK3568的SDIO接口的工作电压也要是1.8V,请检查设备树电源域&pmu_io_domains
节点vccio6是否配置为1.8v(同时,SDIO3.0模式必须为1.8v):
4、适配流程步骤
- 配置设备树,让SDIO控制器工作。
- 配置设备树,让SDIO控制器可以发现WIFI/BT模组。
- Wi-Fi适配:配置设备树,移植设备驱动。
- 验证Wi-Fi功能。
- 蓝牙适配:配置设备树。
- 验证蓝牙功能。
5、让SDIO控制器工作,且可以扫到WIFI卡
现在先解决“适配流程步骤”的第1,第2点。即让SDIO控制器工作,且可以扫到WIFI卡。
5.1、dts配置
从下面两幅原理图可以得出:
- WIFI模组的WIFI_REG_ON引脚接到了RK3568的GPIO3_D4。
- WIFI模组的SDIO接口接到了RK3568的SDMMC2接口。
设备树配置如下:
/* WL_REG_ON 由 sdio_pwrseq 节点进行管理控制 */
&sdio_pwrseq {
compatible = "mmc-pwrseq-simple";
pinctrl-names = "default";
pinctrl-0 = <&wifi_enable_h>;
/*
* On the module itself this is one of these (depending
* on the actual card populated):
* - SDIO_RESET_L_WL_REG_ON
* - PDN (power down when low)
*/
post-power-on-delay-ms = <200>;
/* 这里配置的是WL_REG_ON引脚 */
reset-gpios = <&gpio3 RK_PD4 GPIO_ACTIVE_LOW>;
};
&pinctrl {
sdio-pwrseq {
wifi_enable_h: wifi-enable-h {
/* 这里配置的是WL_REG_ON引脚 */
rockchip,pins = <3 RK_PD4 RK_FUNC_GPIO &pcfg_pull_none>;
};
};
};
/* SDIO接口Wi-Fi专用配置:SDIO接口节点 */
&sdmmc2 {
max-frequency = <150000000>; /* sdio接口的最大频率,可调整 */
supports-sdio;
bus-width = <4>; /* 4线模式,可调整1线模式 */
disable-wp;
cap-sd-highspeed;
cap-sdio-irq;
keep-power-in-suspend;
mmc-pwrseq = <&sdio_pwrseq>; /* WL_REG_ON 管理 */
non-removable;
pinctrl-names = "default";
pinctrl-0 = <&sdmmc2m0_bus4 &sdmmc2m0_cmd &sdmmc2m0_clk>;
sd-uhs-sdr104; /* 支持SDIO3.0 */
status = "okay";
};
5.2、验证
编译内核,打包,更新镜像后,查看kernel log:
- 验证“适配流程步骤”的第1点:让SDIO控制器工作:
# 注意 mmc3: 3的数字是不固定的,也可能是0/1/2; fe000000:表示控制器的地址,不同平台也是不一样的
# 解析dts的mmc-pwrseq节点,获取WL_REG_ON
dwmmc_rockchip fe000000.dwmmc: allocated mmc-pwrseq
# 低频初始化
mmc_host mmc3: Bus speed (slot 0) = 375000Hz (slot req 400000Hz, actual 375000HZ div = 0)
# 高频工作模式
mmc_host mmc3: Bus speed (slot 0) = 148500000Hz (slot req 150000000Hz, actual 148500000HZ div = 0)
- 验证“适配流程步骤”的第2点:让SDIO控制器可以发现WIFI/BT模组:
# SDIO 3.0
mmc3: new ultra high speed SDR104 SDIO card at address 0001
# 如果是SDIO 2.0
mmcX: new high speed SDIO card at address 0001
同时查看/sys/bus/mmc/devices/
目录下的sdio设备:
mmc3:0001对应的基址是fe000000,可以回到设备树查看,就是sdmmc2接口:
如果没有如上对应的log输出,/sys/bus/mmc/devices/
目录下也没出现对应的sdio设备,说明sdio控制器没有扫到wifi卡,请重新检查设备树配置和对应PIN脚的电平状态及CLK频率是否正确。
6、Wi-Fi 适配
现在SDIO控制器可以识别到WiFi卡,但是还没有wlan节点出来,因为还没有驱动。
6.1、dts配置
从下面原理图可以得出:
- WIFI模组的WIFI_HOST_WAKE_B引脚接到了RK3568的GPIO0_D4。
设备树继续添加wlan节点,同时配置pinctrl节点:
&wireless_wlan {
compatible = "wlan-platdata";
rockchip,grf = <&grf>;
pinctrl-names = "default";
pinctrl-0 = <&wifi_host_wake_irq>;
/* 注意:如果排查发现Wi-Fi模块没有32.768K波形,且硬件上是由
* RK PMU供给的,则打开下面的clock属性,按照实际使用的PMU型号填写,
* 否在SDIO/Wi-Fi无法使用.
*
* 海华AW-CM358SM使用的是外部晶振,无需打开clock属性。
*/
//clocks = <&rk809 1>; //如果使用RK809,只能配置一个
//clocks = <&hym8563>; //如果使用hym8563,只能配置一个
//clock-names = "ext_clock";
/* 按实际名字填写(但这里的名字我随便写的,听说海华和正基是兼容的,所以填了这个名字) */
wifi_chip_type = "ap6256";
/* 这里配置的是WIFI_HOST_WAKE_B引脚 */
WIFI,host_wake_irq = <&gpio0 RK_PD4 GPIO_ACTIVE_HIGH>;
status = "okay";
};
&pinctrl {
...
wireless-wlan {
wifi_host_wake_irq: wifi-host-wake-irq {
/* 这里配置的是WIFI_HOST_WAKE_B引脚 */
rockchip,pins = <0 RK_PD4 RK_FUNC_GPIO &pcfg_pull_down>;
};
};
};
其实实测发现,对于海华AW-CM358SM来说,不配置这个&wireless_wlan
节点最终也会有wifi节点出来。
6.2、驱动移植
6.2.1、kernel menuconfig
6.2.2、传统驱动移植
- 进入内核驱动目录,将驱动文件复制进来:
cd <sdk>/kernel/drivers/net/wireless
cp nxp ./
- 修改Kconfig:
vi Kconfig
/* Kconfig */
...
config MXMWIFIEX
tristate "NXP MxM WiFi Driver"
depends on CFG80211
help
This driver is multi-chip-multi-interface driver
(indicating Multi-Chip x Multi-Interface support) based on
NXP 802.11n/ac chipsets. If you choose to build it as a module,
it will be build 2 modules moal.ko and mlan.ko.
...
- 修改Makefile:
vi Makefile
/* Makefile */
...
obj-$(CONFIG_MXMWIFIEX) += nxp/
...
- 修改defconfig:
- 在sdk根目录执行如下命令编译内核:
./build.sh kernel
至此,驱动已经编译完成。但是驱动的安装需要固件,可以自行通过文件系统overlay的方式将固件放到/lib/firmware/
目录下。
6.2.3、RK SDK WIFI/BT驱动独立编译
RK SDK把wifibt的编译独立了出来,所以这里我们体验一下这种方法。注意!经过实测,要先按照上面将驱动移植进内核,才可以使用下面的独立编译。
- /external/rkwifibt/目录结构说明:
- firmware目录:包含各个厂家WiFiBT的firmware文件
- drivers目录:包含各个厂家的WiFiBT驱动
- bin目录:主要是原厂预置的一些二进制文件
- sh目录:主要是开机的WIFIBT的加载脚本,及测试脚本等
我们暂时只关注firmware和drivers目录。
- 进入drivers目录,创建aw-cm358sm文件夹,将驱动文件复制进来:
cd <sdk>/external/rkwifibt/drivers
mkdir aw-cm358sm
cd aw-cm358sm
cp nxp/* ./
- 进入firmware目录,创建azurewave文件夹。进入azureware目录,继续创建AW-CM358SM文件夹,将固件拷贝到该文件夹。
cd <sdk>/external/rkwifibt/firmware
mkdir azurewave
cd azurewave
mkdir AW-CM358SM
cd AW-CM358SM
cp xxxx ./
- 修改/device/rockchip/common/scripts/post-wifibt.sh
修改1:增加aw-cm358sm驱动的编译:
/* <sdk>/device/rockchip/common/scripts/post-wifibt.sh */
...
if [[ "$RK_WIFIBT_CHIP" = "AW-CM358SM" ]];then
echo "building aw-cm358sm driver"
$KMAKE M=$RKWIFIBT_DIR/drivers/aw-cm358sm modules
fi
...
修改2:将编译好的ko文件和固件拷贝到output目录,以备后面打包进rootfs。
/* <sdk>/device/rockchip/common/scripts/post-wifibt.sh */
...
if [[ "$RK_WIFIBT_CHIP" == "AW-CM358SM" ]];then
echo "Copy AW-CM358SM file to rootfs"
cp $RKWIFIBT_DIR/firmware/azurewave/$RK_WIFIBT_CHIP/* \
$TARGET_DIR/lib/firmware/
cp $RKWIFIBT_DIR/drivers/aw-cm358sm/*.ko $TARGET_DIR/lib/modules/
fi
...
- 修改板级配置文件,添加
$RK_WIFIBT_CHIP
环境变量:
- 在sdk根目录执行如下命令单独编译wifibt:
./build.sh wifibt
- 编译buildroot,更新rootfs。打包固件。
./build.sh buildroot && ./build.sh firmware
7、Wi-Fi 功能验证
7.1、加载驱动
- 更新镜像后,登入系统,查看一下未安装驱动前的ifconfig:
- 进入/lib/modules目录,按顺序安装驱动(该驱动有两个ko文件需要安装):
cd /lib/modules
insmod mlan.ko
insmod moal.ko
驱动加载成功:
7.2、STA模式测试
这里使用wpa_supplicant工具测试,需要在buildroot里提前安装。
- 修改wpa_supplicant.conf配置文件,将ssid和psk替换成待连接的wifi名称和密码:
vi /etc/wpa_supplicant.conf
- 开启wpa_supplicant进程:
# 开启wpa_supplicant进程
# -c 后面接的是配置文件的路径
wpa_supplicant -B -i mlan0 -c /etc/wpa_supplicant.conf
# 动态获取IP
dhcpcd
- ping测试:
ping -I mlan0 baidu.com
7.3、AP测试
略。
8、蓝牙适配
8.1、dts配置
配置uart8:
&uart8 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&uart8m0_xfer &uart8m0_ctsn &uart8m0_rtsn>;
};
8.2、驱动移植
kernel menuconfig开启BT_HCIUART
:
9、蓝牙功能验证
buildroot要添加bluez蓝牙工具软件包。
登入系统后,执行如下命令查看hci0节点:
# 还是要先加载wifi驱动
insmod /lib/modules/mlan.ko
insmod /lib/modules/moal.ko
# 使能hci0
export DBUS_SESSION_BUS_ADDRESS=unix:path=/var/run/dbus/system_bus_socket
hciattach /dev/ttyS8 any -s 115200 115200 flow > /dev/null
hciconfig hci0 up
启动蓝牙服务:
# 启动蓝牙服务
/usr/libexec/bluetooth/bluetoothd &
/usr/libexec/bluetooth/obexd -a -r /root &
和手机配对测试:
root@rk3568-buildroot:/# bluetoothctl # 打开bluez蓝牙工具
Agent registered
[bluetooth]# power on # 启动蓝牙设备
[CHG] Controller 36:DC:25:54:7C:CB Class: 0x00100000
Changing power on succeeded
[CHG] Controller 36:DC:25:54:7C:CB Powered: yes
[bluetooth]# pairable on # 设置为配对模式
Changing pairable on succeeded
[bluetooth]# discoverable on # 设置为可发现模式
Changing discoverable on succeeded
[CHG] Controller 36:DC:25:54:7C:CB Discoverable: yes
[bluetooth]# agent on # 启动代理
Agent is already registered
[bluetooth]# default-agent
Default agent request successful
# 此时,打开手机蓝牙进行扫描,如果长时间未扫描到请重复执行
[bluetooth]# discoverable on # 设置当前代理为默认
# 点击BlueZ 5.68进行配对,手机端和开发板分别进行密码验证,选择“YES”。
Changing discoverable on succeeded
[CHG] Controller 28:D0:43:15:75:E6 Discoverable: no
[NEW] Device A4:50:46:A5:9D:08 bluetoothTest
Request confirmation
[agent] Confirm passkey 248678 (yes/no): yes
[CHG] Device A4:50:46:A5:9D:08 Bonded: yes
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 00001112-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 Modalias: bluetooth:v038Fp1200d1436
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 00001105-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 00001112-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 00001115-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 00001116-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 0000112f-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 00001132-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 00009955-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 ServicesResolved: yes
[CHG] Device A4:50:46:A5:9D:08 Paired: yes
Authorize service
[agent] Authorize service 00001108-0000-1000-8000-00805f9b34fb (yes/no): yes
Authorize service
[agent] Authorize service 0000110d-0000-1000-8000-00805f9b34fb (yes/no): yesW: [pulseaudio] module-loopback.c: Configured latency of 200.00 ms is smaller than minimum latency, using minimum instead
W: [pulseaudio] module-loopback.c: Cannot set requested sink latency of 66.67 ms, adjusting to 250.00 ms
W: [pulseaudio] module-loopback.c: Cannot set requested source latency of 16.00 ms, adjusting to 39.91 ms
W: [pulseaudio] module-loopback.c: Configured latency of 200.00 ms is smaller than minimum latency, using minimum instead
W: [pulseaudio] module-loopback.c: Cannot set requested sink latency of 35.20 ms, adjusting to 39.91 ms
W: [pulseaudio] module-loopback.c: Cannot set requested source latency of 66.67 ms, adjusting to 250.00 ms
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 00001105-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 0000110d-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 00001112-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 00001115-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 00001116-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 0000112f-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 00001132-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device A4:50:46:A5:9D:08 UUIDs: 00009955-0000-1000-8000-00805f9b34fb
[NEW] Transport /org/bluez/hci0/dev_A4_50_46_A5_9D_08/fd0
[NEW] Endpoint /org/bluez/hci0/dev_A4_50_46_A5_9D_08/sep1
[ 1558.607240] input: bluetoothTest (AVRCP) as /devices/virtual/input/input5
[NEW] Player /org/bluez/hci0/dev_A4_50_46_A5_9D_08/player0 [default]
[09:25:59.443] event5 - bluetoothTest (AVRCP): is tagged by udev as: Keyboard
[09:25:59.444] event5 - bluetoothTest (AVRCP): device is a keyboard
[09:25:59.444] libinput: configuring device "bluetoothTest (AVRCP)".
[09:25:59.444] associating input device event5 with output DSI-1 (none by udev)
[CHG] Player /org/bluez/hci0/dev_A4_50_46_A5_9D_08/player0 Status: paused
[CHG] Player /org/bluez/hci0/dev_A4_50_46_A5_9D_08/player0 Track Key: Title
[CHG] Player /org/bluez/hci0/dev_A4_50_46_A5_9D_08/player0 Track Value:
[CHG] Player /org/bluez/hci0/dev_A4_50_46_A5_9D_08/player0 Track Key: TrackNumber
[CHG] Player /org/bluez/hci0/dev_A4_50_46_A5_9D_08/player0 Track Value: 0x00000000 (0)
[CHG] Player /org/bluez/hci0/dev_A4_50_46_A5_9D_08/player0 Track Key: NumberOfTracks
[CHG] Player /org/bluez/hci0/dev_A4_50_46_A5_9D_08/player0 Track Value: 0x00000000 (0)
[CHG] Player /org/bluez/hci0/dev_A4_50_46_A5_9D_08/player0 Track Key: Duration
[CHG] Player /org/bluez/hci0/dev_A4_50_46_A5_9D_08/player0 Track Value: 0x00000000 (0)
[CHG] Player /org/bluez/hci0/dev_A4_50_46_A5_9D_08/player0 Track Key: Album
[CHG] Player /org/bluez/hci0/dev_A4_50_46_A5_9D_08/player0 Track Value:
[CHG] Player /org/bluez/hci0/dev_A4_50_46_A5_9D_08/player0 Track Key: Artist
[CHG] Player /org/bluez/hci0/dev_A4_50_46_A5_9D_08/player0 Track Value:
[CHG] Player /org/bluez/hci0/dev_A4_50_46_A5_9D_08/player0 Track Key: Genre
[CHG] Player /org/bluez/hci0/dev_A4_50_46_A5_9D_08/player0 Track Value:
[CHG] Player /org/bluez/hci0/dev_A4_50_46_A5_9D_08/player0 Position: 0x00000000 (0)
[CHG] Player /org/bluez/hci0/dev_A4_50_46_A5_9D_08/player0 Position: 0x00000000 (0)
[bluetoothTest]#
自行进行文件互传测试。