在rk3308b平台移植rtl8821cs,rlt8821cs是wifi+bt一体的模组,主要记录下移植过程中需要注意的地方
将rtl8821cs的驱动包复制到rk的SDK内,路径如下rockchip_rk3308b_sdk/kernel/drivers/net/wireless/rockchip_wlan/cywdhd,并命名为bcmdhd
主要确认下wireless-bluetooth、wireless-wlan节点信息
wireless-bluetooth {
compatible = "bluetooth-platdata";
uart_rts_gpios = <&gpio4 RK_PA7 GPIO_ACTIVE_LOW>;
pinctrl-names = "default", "rts_gpio";
pinctrl-0 = <&uart4_rts>;
pinctrl-1 = <&uart4_rts_gpio>;
BT,power_gpio = <&gpio3 RK_PB0 GPIO_ACTIVE_HIGH>; // BT_REG_ON
BT,wake_host_irq = <&gpio2 RK_PB5 GPIO_ACTIVE_HIGH>; // BT_WAKE_HOST
status = "okay";
};
BT,power_gpio对应蓝牙的使能脚,BT,wake_host_irq是蓝牙唤醒脚
wireless-wlan {
compatible = "wlan-platdata";
rockchip,grf = <&grf>;
pinctrl-names = "default";
pinctrl-0 = <&wifi_wake_host>;
wifi_chip_type = "ap6275s";
WIFI,host_wake_irq = <&gpio0 RK_PA0 GPIO_ACTIVE_HIGH>;
status = "okay";
};
WIFI,host_wake_irq对应WiFi唤醒脚
&uart4 {
pinctrl-names = "default";
pinctrl-0 = <&uart4_xfer &uart4_cts>;
status = "okay";
};
&uart4_xfer 、&uart4_cts分别为uart4的TX、RX和cts脚。注意RK不同的平台cts的叫法不一样,要区分
内核配置文件没什么特别需要注意的地方,这里主要罗列下蓝牙相关的配置选项
CONFIG_BT=y
CONFIG_BT_BREDR=y
CONFIG_BT_HS=y
CONFIG_BT_LE=y
CONFIG_BT_DEBUGFS=y
CONFIG_BT_HCIUART=y
CONFIG_BT_HCIUART_H4=y
CONFIG_BT_RFCOMM=y
ONFIG_BT_RFCOMM_TTY=y
CONFIG_BT_BNEP=y
CONFIG_BT_BNEP_MC_FILTER=y
CONFIG_BT_BNEP_PROTO_FILTER=y
CONFIG_BT_HIDP=y
CONFIG_BT_L2CAP=y
CONFIG_BT_SCO=y
关于buildroot配置主要罗列下关于蓝牙的应用,使用的是Bluez5蓝牙协议栈
#BR2_PACKAGE_BLUEZ_ALSA=y
BR2_PACKAGE_BLUEZ5_UTILS=y
#BR2_PACKAGE_BLUEZ5_UTILS_OBEX=y
#BR2_PACKAGE_BLUEZ5_UTILS_CLIENT=y
#BR2_PACKAGE_BLUEZ5_UTILS_EXPERIMENTAL=y
BR2_PACKAGE_DBUS=y
BR2_PACKAGE_DBUS_GLIB=y
#BR2_PACKAGE_DBUS_CPP=y
#BR2_PACKAGE_DBUS_TRIGGERD=y
#BR2_PACKAGE_BLUEZ5_UTILS_GATTTOOL=y
前面带“#”的不是必选,可以选择性添加特定功能,RK推荐用的是BROADCOM_BSA协议,这里还是采用bluez5协议,如果要使用BROADCOM_BSA协议,则需要添加该协议的应用依赖(BR2_PACKAGE_BROADCOM_BSA=y BR2_PACKAGE_BROADCOM_BSA_AP6275S=y 路径为rockchip_rk3308b_sdk/buildroot/package/rockchip/broadcom_bsa/Config.in)。另外需要添加AP6275S的依赖和配置文件,添加AP6275S的信息,路径如下rockchip_rk3308b_sdk/buildroot/package/rockchip/rkwifibt/rkwifibt.mk
添加AP6275S的配置信息
ifeq ($(BR2_PACKAGE_RKWIFIBT_AP6275S),y)
CHIP_VENDOR = BROADCOM
CHIP_NAME = AP6275S
BT_FIRMWARE = BCM4362A2.hcd #蓝牙固件名
WIFI_KO = bcmdhd.ko
endif
选择编译AP6275S的相关应用
BR2_PACKAGE_RKWIFIBT_AP6275S=y
Symbol: BR2_PACKAGE_RKWIFIBT_AP6275S [=y]
Type : boolean
Prompt: AP6275S
Location:
-> Target packages
-> rockchip BSP packages (BR2_PACKAGE_ROCKCHIP [=y])
-> rkwifibt (BR2_PACKAGE_RKWIFIBT [=y])
(2) -> wifi chip support ( [=y])
Defined at package/rockchip/rkwifibt/Config.in:21
Depends on:
将驱动挂载后,使用ifconfig -a看看有没有相应的节点,如果有的话进行下一步功能的验证
[root@eufy /oem]$ ifconfig -a
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:73464 errors:0 dropped:0 overruns:0 frame:0
TX packets:73464 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:3673200 (3.5 MiB) TX bytes:3673200 (3.5 MiB)
wlan0 Link encap:Ethernet HWaddr 10:2C:6B:80:2D:16
inet6 addr: fe80::122c:6bff:fe80:2d16/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:648 (648.0 B)
手动修改 wpa_supplicant.conf 文件进行联网验证功能
1、启动 wpa_supplicant:wpa_supplicant -B -i wlan0 -c /data/cfg/wpa_supplicant.conf
2、修改wpa_supplicant.conf文件
/ # vi /data/cfg/wpa_supplicant.conf ctrl_interface=/var/run/wpa_supplicant ap_scan=1
ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
network={
scan_ssid=1
ssid="WFW"
psk="12345678"
key_mgmt=WPA-PSK
}
设置好文件后就重新读,wpa_cli reconfigure,并重新连接wpa_cli reconnect
最后ping下www.baidu.com看能否收到回复
蓝牙上层操作是基于bluez的各种工具,主要有hcitool、hciconfig 工具,简单介绍下
hciconfig工具
#要带上具体的蓝牙节点,我这以hci0节点为例
hciconfig hci0 up #激活蓝牙
hciconfig hci0 down #关闭蓝牙
hciconfig hci0 name XXX #修改蓝牙名
hciconfig hci0 class 0xXXXXXX 修改蓝牙类型
hciconfig hci0 piscan #允许被其它蓝牙扫描到,是PSCAN ISCAN组合
hciconfig hci0 leadv #开启ble蓝牙广播
hcitool工具
因为将该设备作为从设备,所以用到的也就是扫描命令,如下
hcitool scan # 扫描经典蓝牙
hcitool lescan # 扫描ble设备
启动蓝牙
mkdir -p /var/run/dbus/ #启动Dbus进程
dbus-daemon --system
echo 0 > /sys/class/rfkill/rfkill0/state #蓝牙使能脚拉低
sleep 1
echo 1 > /sys/class/rfkill/rfkill0/state #蓝牙使能脚拉高
brcm_patchram_plus -d --enable_hci --no2bytes --tosleep 200000 --baudrate 1500000 --patchram /system/etc/firmware/BCM4362A2.hcd /dev/ttyS4 & #下载固件
sleep 30
/usr/libexec/bluetooth/bluetoothd --compat -n & #启动蓝牙协议
sleep 3
hciconfig hci0 up #激活蓝牙
hciconfig hci0 piscan #允许被其它蓝牙设备扫描
几点说明
1、如果启动Dbus失败,那么在passwd添加如下内容
messagebus:x:500:500::/home/messagebus:/bin/sh
dbus:x:1000:1000:DBus messagebus user:/var/run/dbus:/bin/false
2、brcm_patchram_plus -d --enable_hci --no2bytes --tosleep 200000 --baudrate 1500000 --patchram /system/etc/firmware/BCM4362A2.hcd /dev/ttyS4 &
该命令是下载蓝牙固件,用的是brcm_patchram_plus应用程序,下载地址:brcm_patchram_plus,就一个c文件,交叉编译一下即可。如果下载失败请检查蓝牙使用的串口绑定对不对,AP6275S的rts和cts的初始状态对不对(rts低,cts要为高,如果状态不对,要采取上下拉电阻使其在正确的状态),如果下载成功,会出现下面类似的提示
received 7
04 0e 04 01 4c fc 00
writing
01 4c fc b2 8e 3e 16 00 00 e0 73 78 a3 74 20 46
16 f7 1f ff 28 b1 26 4b a2 7c 1b 78 9a 42 38 bf
a3 74 20 46 ff f7 e3 fe 20 46 be f6 6c f9 d0 b1
02 23 b5 f8 f2 20 94 f8 24 10 b5 f8 f0 00 db f6
04 f8 00 23 a5 f8 f0 00 84 f8 a0 30 b5 f8 f0 30
23 84 b5 f8 f2 30 63 84 02 23 84 f8 24 30 01 23
84 f8 25 30 06 e0 20 46 18 f7 09 fc 01 46 20 46
17 f7 22 fa 20 46 17 f7 0c fe 03 9a 3b 68 9a 42
01 d0 a5 f6 da fa 05 b0 bd e8 f0 8f 00 bf 90 08
20 00 50 30 20 00 78 6f 20 00 34 30 20 00 4a 30
20 00 a1 91 20 00 28 30 20 00 64 30 20 00 49 30
20 00 54 30 20 00
received 7
04 0e 04 01 4c fc 00
writing
01 4e fc 04 ff ff ff ff
received 7
04 0e 04 01 4e fc 00
writing
01 03 0c 00
writing
01 03 0c 00
received 7
04 0e 04 01 03 0c 00
writing
01 18 fc 06 00 00 60 e3 16 00
received 7
04 0e 04 01 18 fc 00
Done setting baudrate
Done setting line discpline
3、如果上述命令都执行成功的话,那么使用hciconfig命令是可以查看到蓝牙节点信息的,而且用其它的蓝牙设备也是能够搜索到的
[root@eufy /oem]$ hciconfig -a
hci0: Type: Primary Bus: UART
BD Address: 10:2C:6B:80:2D:17 ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING PSCAN ISCAN
RX bytes:1486 acl:0 sco:0 events:86 errors:0
TX bytes:1529 acl:0 sco:0 commands:86 errors:0
Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH SNIFF
Link mode: SLAVE ACCEPT
Name: 'BlueZ 5.50'
Class: 0x000000
Service Classes: Unspecified
Device Class: Miscellaneous,
HCI Version: (0xa) Revision: 0x17
LMP Version: (0xa) Subversion: 0x1111
Manufacturer: Broadcom Corporation (15)
开启ble服务
执行如下命令开启ble服务
my_ble & #基于bluez5的/tool/gatt-service.c编译的应用
hciconfig hci0 leadv #开启ble广播
创建了服务,可以使用ble蓝牙调试工具去扫描服务和进行简单的通讯检验,我使用的是IOS的nRF Connect工具