RK3588 & Android13 调试RTL8852BS(WIFI&BT)

avatar
作者
筋斗云
阅读量:0

前言

最近在搞广告机项目,用到RTL8852BS的模块,发现这个模块的相关文章比较少(大多都是AP的),虽然wifi-bt的调试都差不多,但是还是想记录一下调试的过程,做一下总结,如有错误之处,还望各位大佬指教!

平台:RK3588 & Android13 & kernel-5.10

模块芯片:RTL8852BS

接口:SDIO & UART

内容:调试RTL8852BS模块的WiFi以及BT功能

一、WIFI

1. dst配置

调试的第一步,先根据原理图配置dts,让sdio可以扫描到模块,部分原理图如下:

sdio及wifi节点的相关配置

/* SDIO接口Wi-Fi专用配置: WIFI_REG_ON: Wi-Fi的电源使能PIN脚 */  	sdio_pwrseq: sdio-pwrseq { 		compatible = "mmc-pwrseq-simple"; 		clocks = <&hym8563>; // 外部时钟,蓝牙需要 		clock-names = "ext_clock"; 		pinctrl-names = "default"; 		pinctrl-0 = <&wifi_enable_h>; 		reset-gpios = <&gpio2 RK_PB5 GPIO_ACTIVE_LOW>;  /*跟电源使能状态恰好相反:高有效为LOW,低有效则为HIGH。切记:这个配置跟下面的WIFI,poweren_gpio是互斥的,不能同时配置!!!*/ 		 		 /*特别注意:reset-gpios的GPIO_ACTIVE 配置跟poweren_gpio配置的电源使能状态恰好是相反的*/ 	};      /* Wi-Fi节点 */ 	wireless_wlan: wireless-wlan { 		compatible = "wlan-platdata"; 		wifi_chip_type = "rtl8852bs"; 		pinctrl-names = "default"; 		pinctrl-0 = <&wifi_host_wake_irq>; 		WIFI,host_wake_irq = <&gpio2 RK_PB4 GPIO_ACTIVE_HIGH>; 		//WIFI,poweren_gpio = <&gpio2 RK_PB5 GPIO_ACTIVE_HIGH>; 		status = "okay"; 	};    &sdio { 	max-frequency = <100000000>;/* sdio接口的最大频率,可调整 */ 	supports-sdio; 	bus-width = <4>;/* 4线模式 */ 	disable-wp; 	cap-sd-highspeed; 	cap-sdio-irq; 	keep-power-in-suspend; 	mmc-pwrseq = <&sdio_pwrseq>; 	non-removable; 	num-slots = <1>; 	rockchip,default-sample-phase = <90>;   	pinctrl-names = "default"; 	pinctrl-0 = <&sdiom0_pins>; 	sd-uhs-sdr50;     sd-uhs-sdr104;/* 支持SDIO3.0 */ 	status = "okay"; };  /* SDIO接口Wi-Fi专用配置:WIFI_REG_ON脚的pinctrl的配置 */ /* WIFI_WAKE_HOST脚的pinctrl的配置 */ &pinctrl { 	sdio-pwrseq { 		wifi_enable_h: wifi-enable-h { 			rockchip,pins = 			/* 对应上面的WIFI_REG_ON,关掉上下拉,防止不能拉高或拉低 */ 			<0 RK_PA2 RK_FUNC_GPIO &pcfg_pull_none>; 		}; 	};      wireless-wlan { 		wifi_host_wake_irq: wifi-host-wake-irq { 			rockchip,pins = <2 RK_PB4 RK_FUNC_GPIO &pcfg_pull_down>; 		}; 	}; };

理论上配好这些以后sdio就能扫到模块了,可以这样查看

console:/ # ls /sys/bus/sdio/devices/                                           mmc0:0001:1 

还可以查看模块的pid 以及 vid,后续加载对应驱动需要用

console:/ # cat /sys/bus/sdio/devices/mmc0\:0001\:1/uevent                      DRIVER=rtl8852bs SDIO_CLASS=07 SDIO_ID=024C:B852 SDIO_REVISION=0.0 MODALIAS=sdio:c07v024CdB852 

2. 驱动移植

sdio扫到设备以后下一步就是移植驱动,这个很简单,把驱动添加到源码根目录下的

external/wifi_driver 

然后修改Makefile编译驱动即可,仿照已适配的模块去改;需要注意的是,驱动里面的Makefile文件也需要修改,改到RK平台,具体可以参考这篇博客驱动编译报错相关章节

RK3588 & Android12 调试 RTL8852BE(wifi篇)_rk3588 android12调试rtl8852bs-CSDN博客

3. framework层修改

驱动移植成功以后,下一步就需要让系统去加载对应的驱动,主要修改framework的一些文件,具体参考下面这篇博客

RK3588 & Android12 调试 RTL8852BE(wifi篇)_rk3588 android12调试rtl8852bs-CSDN博客

到这里WiFi功能理论上就可以使用了

二、蓝牙

1. dts配置

/* 蓝牙节点 */ /* 注意下面关于UART的配置:uart9_xfer/uart9_rts/uart9_ctsn * 每个平台的名字可能不一样,要在对应芯片平台的dts/dtsi里面找下对 * 应的uart写法,比如uart9_ctsn有些平台的名字为uart9_cts. */ wireless_bluetooth: wireless-bluetooth { 		compatible = "bluetooth-platdata"; 		//clocks = <&hym8563>;    //时钟在sdio_pwrseq里面配置了这里就不要重复配置 		clock-names = "ext_clock";         /* 这里要配置对应主控UART的RTS脚 */ 		uart_rts_gpios = <&gpio4 RK_PC4 GPIO_ACTIVE_LOW>; 		pinctrl-names = "default", "rts_gpio"; 		pinctrl-0 = <&uart9m0_rtsn>, <&bt_reset_gpio>, <&bt_irq_gpio>; 		pinctrl-1 = <&uart9_gpios>;         /* BT_REG_ON 蓝牙电源的开关 */ 		BT,reset_gpio    = <&gpio2 RK_PB6 GPIO_ACTIVE_HIGH>; 		//BT,wake_gpio     = <&gpio0 RK_PC5 GPIO_ACTIVE_HIGH>; 		BT,wake_host_irq = <&gpio2 RK_PC1 GPIO_ACTIVE_HIGH>; 		status = "okay"; 	};  /* 打开对应的UART配置 */ &uart9 { 	status = "okay"; 	pinctrl-names = "default";     /* 这里配置对应主控UART的TX/RX/CTS PIN ,不要配置RTS PIN*/ 	pinctrl-0 = <&uart9m0_xfer &uart9m0_ctsn>; };  /* uart9_rts_gpio */ wireless-bluetooth { 		uart9_gpios: uart9-gpios { 			rockchip,pins = <4 RK_PC4 RK_FUNC_GPIO &pcfg_pull_none>; 		};  		bt_reset_gpio: bt-reset-gpio { 			rockchip,pins = <2 RK_PB6 RK_FUNC_GPIO &pcfg_pull_none>; 		};  		bt_irq_gpio: bt-irq-gpio { 			rockchip,pins = <2 RK_PC1 RK_FUNC_GPIO &pcfg_pull_none>; 		}; 	}; 

配置完这些,dts部分就完成了,理论上dev下面会生成对应的uart设备文件

console:/ # ls /dev/ttyS*                                                       /dev/ttyS7  /dev/ttyS9 

 2. hardware配置

2.1添加蓝牙固件文件

rk3588_an13/hardware/realtek/rtkbt/vendor/firmware$ git status . On branch  Your branch is up to date with   Changes to be committed:   (use "git reset HEAD <file>..." to unstage)  	modified:   BT_Firmware.mk  Untracked files:   (use "git add <file>..." to include in what will be committed)  	rtl8852bs_config 	rtl8852bs_fw 

对应mk文件修改如下,其实就是为了编译的时候copy蓝牙固件文件到系统对应位置

diff --git a/rk3588_an13/hardware/realtek/rtkbt/vendor/firmware/BT_Firmware.mk b/rk3588_an13/hardware/realtek/rtkbt/vendor/firmware/BT_Firmware.mk index 5d4f87b135d..cc515fb6e2a 100755 --- a/rk3588_an13/hardware/realtek/rtkbt/vendor/firmware/BT_Firmware.mk +++ b/rk3588_an13/hardware/realtek/rtkbt/vendor/firmware/BT_Firmware.mk @@ -65,3 +65,5 @@ PRODUCT_COPY_FILES += \         $(LOCAL_PATH)/Firmware/BT/rtl8852as_fw:$(TARGET_COPY_OUT_VENDOR)/firmware/rtl8852as_fw \         $(LOCAL_PATH)/Firmware/BT/rtl8852au_config:$(TARGET_COPY_OUT_VENDOR)/firmware/rtl8852au_config \         $(LOCAL_PATH)/Firmware/BT/rtl8852au_fw:$(TARGET_COPY_OUT_VENDOR)/firmware/rtl8852au_fw \ +       $(LOCAL_PATH)/Firmware/BT/rtl8852bs_config:$(TARGET_COPY_OUT_VENDOR)/firmware/rtl8852bs_config \ +       $(LOCAL_PATH)/Firmware/BT/rtl8852bs_fw:$(TARGET_COPY_OUT_VENDOR)/firmware/rtl8852bs_fw \ 

 注:如果嫌麻烦,直接把蓝牙固件文件丢到vendor/rockchip/common/wifi/firmware/也行

2.2 指定UART

蓝牙固件文件加入以后,还要指定蓝牙使用的UART,patch如下: 

hardware:

rk3588_an13/hardware$ git diff . diff --git a/rk3588_an13/hardware/broadcom/libbt/include/vnd_rksdk.txt b/rk3588_an13/hardware/broadcom/libbt/include/vnd_rksdk.txt old mode 100644 new mode 100755 index 7d3f8104d0c..bf0c98b69ce --- a/rk3588_an13/hardware/broadcom/libbt/include/vnd_rksdk.txt +++ b/rk3588_an13/hardware/broadcom/libbt/include/vnd_rksdk.txt @@ -1,4 +1,4 @@ -BLUETOOTH_UART_DEVICE_PORT = "/dev/ttyS0" +BLUETOOTH_UART_DEVICE_PORT = "/dev/ttyS9"  FW_PATCHFILE_LOCATION = "/vendor/etc/firmware/"  VENDOR_LIB_CONF_FILE = "/vendor/etc/bluetooth/bt_vendor.conf"  UART_TARGET_BAUD_RATE = 1500000 diff --git a/rk3588_an13/hardware/broadcom/libbt/src/hardware.c b/rk3588_an13/hardware/broadcom/libbt/src/hardware.c old mode 100644 new mode 100755 diff --git a/rk3588_an13/hardware/realtek/rtkbt/vendor/etc/bluetooth/rtkbt.conf b/rk3588_an13/hardware/realtek/rtkbt/vendor/etc/bluetooth/rtkbt.conf index a1e9b393613..3f2bbffd259 100755 --- a/rk3588_an13/hardware/realtek/rtkbt/vendor/etc/bluetooth/rtkbt.conf +++ b/rk3588_an13/hardware/realtek/rtkbt/vendor/etc/bluetooth/rtkbt.conf @@ -9,7 +9,7 @@ DevClassMinorClass=0x1C    #Indicate USB or UART driver bluetooth  #BtDeviceNode=/dev/rtkbt_dev -BtDeviceNode=?/dev/ttyS1:H5 +BtDeviceNode=?/dev/ttyS9:H5    # BtSnoop log output file  BtSnoopFileName=/data/misc/bluedroid/btsnoop_hci.cfa diff --git a/rk3588_an13/hardware/realtek/rtkbt/vendor/etc/bluetooth/rtkbt_S0.conf b/rk3588_an13/hardware/realtek/rtkbt/vendor/etc/bluetooth/rtkbt_S0.conf index 87a8241f179..bb13aea7240 100755 --- a/rk3588_an13/hardware/realtek/rtkbt/vendor/etc/bluetooth/rtkbt_S0.conf +++ b/rk3588_an13/hardware/realtek/rtkbt/vendor/etc/bluetooth/rtkbt_S0.conf @@ -9,7 +9,7 @@ DevClassMinorClass=0x1C    #Indicate USB or UART driver bluetooth  #BtDeviceNode=/dev/rtk_btusb -BtDeviceNode=?/dev/ttyS0:H5 +BtDeviceNode=?/dev/ttyS9:H5    # Enable BtSnoop logging function  # valid value : true, false 

device: 

/rk3588_an13/device/rockchip/rk3588/rk3588_t$ git diff . diff --git a/rk3588_an13/device/rockchip/rk3588/rk3588_t/bt_vendor.conf b/rk3588_an13/device/rockchip/rk3588/rk3588_t/bt_vendor.conf old mode 100644 new mode 100755 index d98c62e94fe..793e90a39f7 --- a/rk3588_an13/device/rockchip/rk3588/rk3588_t/bt_vendor.conf +++ b/rk3588_an13/device/rockchip/rk3588/rk3588_t/bt_vendor.conf @@ -1,5 +1,5 @@  # UART device port where Bluetooth controller is attached -UartPort = /dev/ttyS8 +UartPort = /dev/ttyS9    # Firmware patch file location  FwPatchFilePath = /vendor/etc/firmware/ 

 到这里,蓝牙功能的配置就完成了,理论上蓝牙就能用了!

三、遇到的问题

3.1 sdio扫不到模块

在根据如上步骤配置完成以后,sdio居然没有扫描到模块!后检查发现原因是硬件将clk和cmd搞反了!

最后交叉飞线就可以了,所以一定要仔细对每一个引脚,确认硬件无误!

3.2. 蓝牙打不开

点击开启蓝牙以后logcat会有如下信息

04-18 09:08:43.572  5657  5657 I bt_userial_vendor: userial vendor open: opening /dev/ttyS1 04-18 09:08:43.572  5657  5657 E bt_userial_vendor: userial vendor open: unable to open /dev/ttyS1

原因就是蓝牙使用的uart没有指定对!按照上面第二节的2.2修改就好了

四、小结 

wifi配置主要就是:sdio -> WIFI_REG_ON -> 驱动移植 -> 加载驱动

bt配置主要就是:clock -> BT_REG_ON -> uart ->  固件文件移植 -> 加载固件文件

都是一些简单的东西。

五、参考文章

【RK3588 开发笔记——wifi蓝牙调试】_rk3588 wifi-CSDN博客

 Rockchip Android13 x3588蓝牙wifi/bt调试心得_android13 wifi唤醒-CSDN博客

六、资料包

链接:https://pan.baidu.com/s/1uOC6MVjQibJwHvq9R_1hXQ  提取码:wh8s

    广告一刻

    为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!