RTL8723bs (SD Card Shape Module) Driver Development
RTL8723BS is a highly integrated single-chip Wi-Fi and Bluetooth combo module. This tutorial will guide you on connecting the RTL8723BS SD card-shaped module to Luckfox Pico Plus, enabling external network connectivity, and conducting Wi-Fi bandwidth testing. Both Luckfox Pico Plus and Luckfox Pico Mini B (without pin headers) can directly interface with the module.
Original source: RTL8723bs (SD card-shaped module) driver development
1.Introduction
1.1 Hardware
- Development Board: LuckFox Pico Plus (RV1103 as the main controller)
- Wi-Fi Module: Wi-Fi+BT module (TF card shape, SDIO interface)
1.2 Hardware Analysis
SD card interface hardware schematic
External pins 21~27 Pins 21~27 on the LuckFox Pico Plus development board are connected to the SD card slot
WiFi+BT module
TF WiFi schematic
Observations:
- Pin 12 (WL_DSI/WL_REG) is directly pulled up.
- Pin 13 (WL_HOST_WAKE) is directly pulled up.
1.3 Summary
If you want to use the WiFi module in the SD card slot on the LuckFox Pico Plus development board, treat it as an SD card. The subsequent device tree is also based on this.
2.Configuration Modification
2.1 Modified Content
Item | File Path |
---|---|
Kernel WiFi Driver Support | <SDK Directory>/sysdrv/source/kernel/arch/arm/configs/luckfox_rv1106_linux_defconfig |
Kernel Device Tree | <SDK Directory>/sysdrv/source/kernel/arch/arm/boot/dts/rv1103g-luckfox-pico-plus.dts |
<SDK Directory>/sysdrv/source/kernel/arch/arm/boot/dts/rv1103-luckfox-pico-plus-ipc.dtsi | |
SDK Global Configuration | <SDK Directory>/project/cfg/BoardConfig_IPC/BoardConfig-SPI_NAND-NONE-RV1103_Luckfox_Pico_Plus-IPC.mk |
Global Build Script | <SDK Directory>/project/build.sh |
2.2 Kernel WiFi Driver Support
Open the kernel configuration interface and navigate to "Rockchip Wireless LAN support". Configure it to compile into a
.ko
file by selecting "Y" to enable it (please refer to the detailed steps in the kernel configuration section of the SDK environment deployment).Use "/" to search for "RTL8723BS" and configure support for the WiFi module model. Select "M" to enable it.
2.3 Kernel Device Tree Support
File Path
<SDK Directory>/sysdrv/source/kernel/arch/arm/boot/dts/rv1103g-luckfox-pico-plus.dts
<SDK Directory>/sysdrv/source/kernel/arch/arm/boot/dts/rv1103-luckfox-pico-plusModification 1:rv1103g-luckfox-pico-plus.dts
/ {
model = "Luckfox Pico Plus";
compatible = "rockchip,rv1103g-38x38-ipc-v10", "rockchip,rv1103";
vcc_1v8: vcc-1v8 {
compatible = "regulator-fixed";
regulator-name = "vcc_1v8";
regulator-always-on;
regulator-boot-on;
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
};
vcc_3v3: vcc-3v3 {
compatible = "regulator-fixed";
regulator-name = "vcc_3v3";
regulator-always-on;
regulator-boot-on;
regulator-min-microvolt = <3300000>;
regulator-max-microvolt = <3300000>;
};
};
/**********GPIO**********/
&pinctrl {
};
&sdmmc {
max-frequency = <20000000>;
bus-width = <4>;
cap-sd-highspeed;
cap-sdio-irq;
keep-power-in-suspend;
non-removable;
sd-uhs-sdr50;
no-1-8-v;
supports-sdio;
pinctrl-names = "default";
pinctrl-0 = <&sdmmc0_clk &sdmmc0_cmd &sdmmc0_det &sdmmc0_bus4>;
status = "okay";
};
/**********ETH**********/
&gmac {
status = "disabled";
};Modification 2:rv1103-luckfox-pico-plus-ipc.dtsi
// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
* Copyright (c) 2022 Rockchip Electronics Co., Ltd.
*/
#include "rv1106-amp.dtsi"
/ {
chosen {
bootargs = "earlycon=uart8250,mmio32,0xff4c0000 console=ttyFIQ0 rootwait snd_soc_core.prealloc_buffer_size_kbytes=16 coherent_pool=0";
};
};
&sfc {
status = "okay";
flash@0 {
compatible = "spi-nand";
reg = <0>;
spi-max-frequency = <80000000>;
spi-rx-bus-width = <4>;
spi-tx-bus-width = <1>;
};
};
2.4 SDK Global Configuration
Here, wpa_supplicant package has been added primarily, and its location is in <SDK directory>/project/app/wifi_app
. Once configured, the compilation process will take place in this directory. Afterward, a 'out' directory will be generated within this directory. During the packaging phase, the files from this 'out' directory will be copied into the file system. This effectively adds the wpa_supplicant package to your system.
File Path
<SDK Directory>/project/cfg/BoardConfig_IPC/BoardConfig-SPI_NAND-NONE-RV1103_Luckfox_Pico_Plus-IPC.mk
Add the following content:
export RK_ENABLE_WIFI=y
2.5 Global Build Script
File Path
<SDK Directory>/project/build.sh
Modification 1:Compile logic
function build_app() {
check_config RK_APP_TYPE || return 0
build_meta --export --media_dir $RK_PROJECT_PATH_MEDIA # export meta header files
test -d ${SDK_APP_DIR} && make -C ${SDK_APP_DIR}
finish_build
}
function build_meta(){
msg_info "============Start building meta============"
if [ -n "$RK_META_SIZE" ];then
if [ -d "${RK_PROJECT_TOP_DIR}/make_meta" ];then
__meta_param="$RK_META_PARAM $RK_CAMERA_PARAM --meta_part_size=$RK_META_SIZE"
${RK_PROJECT_TOP_DIR}/make_meta/build_meta.sh $@ \
--cam_iqfile ${RK_CAMERA_SENSOR_IQFILES} \
--meta_param $__meta_param \
--output $RK_PROJECT_OUTPUT_IMAGE \
--rootfs_dir $RK_PROJECT_PACKAGE_ROOTFS_DIR \
--media_dir $RK_PROJECT_PATH_MEDIA \
--pc_tools_dir $RK_PROJECT_PATH_PC_TOOLS \
--tiny_meta $RK_TINY_META
fi
fi
finish_build
}Modification 2: Copy the WiFi firmware into the file system
Added
__COPY_FILES $SDK_ROOT_DIR/external $RK_PROJECT_PACKAGE_ROOTFS_DIR
function __PACKAGE_ROOTFS()
{
local rootfs_tarball _target_dir _install_dir
rootfs_tarball="$RK_PROJECT_PATH_SYSDRV/rootfs_${RK_LIBC_TPYE}_${RK_CHIP}.tar"
if [ -f $rootfs_tarball ]; then
tar xf $rootfs_tarball -C $RK_PROJECT_OUTPUT
else
msg_error "Not found rootfs tarball: $rootfs_tarball"
exit 1
fi
build_get_sdk_version
cat > $RK_PROJECT_PACKAGE_ROOTFS_DIR/bin/sdkinfo <<EOF
#!/bin/sh
echo Build Time: `date "+%Y-%m-%d-%T"`
echo SDK Version: ${GLOBAL_SDK_VERSION}
EOF
chmod a+x $RK_PROJECT_PACKAGE_ROOTFS_DIR/bin/sdkinfo
__COPY_FILES $RK_PROJECT_PATH_APP/root $RK_PROJECT_PACKAGE_ROOTFS_DIR
__COPY_FILES $RK_PROJECT_PATH_MEDIA/root $RK_PROJECT_PACKAGE_ROOTFS_DIR
# liefyuan: add wifi firmware /lib/firmware/rtlwifi/
__COPY_FILES $SDK_ROOT_DIR/external $RK_PROJECT_PACKAGE_ROOTFS_DIR
if [ -d "$RK_PROJECT_PACKAGE_ROOTFS_DIR/usr/share/iqfiles" ];then
(cd $RK_PROJECT_PACKAGE_ROOTFS_DIR/etc; ln -sf ../usr/share/iqfiles ./)
fi
if [ -f $RK_PROJECT_FILE_ROOTFS_SCRIPT ];then
chmod a+x $RK_PROJECT_FILE_ROOTFS_SCRIPT
cp -f $RK_PROJECT_FILE_ROOTFS_SCRIPT $RK_PROJECT_PACKAGE_ROOTFS_DIR/etc/init.d
fi
}Copy rtl8723bs firmware
In the root file packaging logic, copy the
<SDK directory>/external/lib/firmware/rtlwifi/rtl8723bs_nic.bin
firmware to the root file system. Note:- Add a directory to the sdk root directory:
mkdir -p external/lib/firmware/rtlwifi/
- WiFi firmware download address:
https://raw.githubusercontent.com/wkennington/linux-firmware/master/rtlwifi/rtl8723bs_nic.bin
- Copy the downloaded WiFi firmware into the
sdk/external/lib/firmware/rtlwifi/
directory
- Add a directory to the sdk root directory:
3.Reburn Firmware
3.1 Compile the Kernel
Compile by selecting the branch and specifying the development board model
luckfox@luckfox:~/luckfox-pico$ ./build.sh lunch
Compile
luckfox@luckfox:~/Luckfox-Pico/luckfox-pico$ ./build.sh
Reflash the firmware
After compiling, reflash the firmware.
4.WiFi test
4.1 Install driver ko module
Manually install the driver ko module after power on – it will be automatically loaded later.
# Enter the board's root file system
# Install driver module
cd /oem/usr/ko
insmod libarc4.ko
insmod cfg80211.ko
insmod mac80211.ko
insmod r8723bs.koInstalled module information
# cd oem/usr/ko/
# ls
aes_generic.ko rve.ko
gcm.ko insmod_ko.sh
os04a10.ko sc3336.ko
video_rkisp.ko video_rkcif.ko
atbm603x_.ko sc530ai.ko
hichannel.ko ssv6x5x.ko
insmod_wifi.sh ghash-generic.ko
libsha256.ko rga3.ko
sha256_generic.ko cfg80211.ko
libarc4.ko rockit.ko
atbm6041_wifi_sdio.ko mpp_vcodec.ko
ctr.ko release_version.txt
rknpu.ko sc4336.ko
8189fs.ko rk_dvbm.ko
hpmcu_wrap.bin gf128mul.ko
8188fu.ko phy-rockchip-csi2-dphy.ko
mac80211.ko r8723bs.ko
ccm.ko phy-rockchip-csi2-dphy-hw.ko
libaes.ko cmac.ko
ipv6.ko
# insmod libarc4.ko
# insmod cfg80211.ko
[ 63.210993] cfg80211: Loading compiled-in X.509 certificates for regulatory database
[ 63.212653] cfg80211: Problem loading in-kernel X.509 certificate (-22)
[ 63.214034] platform regulatory.0: Direct firmware load for regulatory.db failed with error -2
[ 63.214060] cfg80211: failed to load regulatory.db
# insmod mac80211.ko
# insmod r8723bs.ko
[ 64.480323] r8723bs: module is from the staging directory, the quality is unknown, you have been warned.
[ 64.491407] RTL8723BS: module init start
[ 64.491435] RTL8723BS: rtl8723bs v4.3.5.5_12290.20140916_BTCOEX20140507-4E40
[ 64.491444] RTL8723BS: rtl8723bs BT-Coex version = BTCOEX20140507-4E40
[ 64.491813] pnetdev = a1b3bae2
[ 64.517828] RTL8723BS: rtw_ndev_init(wlan0)
[ 64.527370] RTL8723BS: module init ret =0
#
#
# ifconfig -a
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
usb0 Link encap:Ethernet HWaddr DA:AD:93:D5:C0:24
inet addr:172.32.0.93 Bcast:172.32.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:225 errors:0 dropped:149 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:24043 (23.4 KiB) TX bytes:0 (0.0 B)
wlan0 Link encap:Ethernet HWaddr 84:20:96:AB:33:12
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)At this time, wlan0 has come out.
4.2 Turn on WiFi
ifconfig wlan0 up
4.3 Modify the configuration file (WiFi name and WiFi password in the configuration file)
vi /etc/wpa_supplicant.conf
Modification content:
ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
ap_scan=1
network={
ssid="KKKK"
scan_ssid=1
key_mgmt=WPA-EAP WPA-PSK IEEE8021X NONE
pairwise=TKIP CCMP
group=CCMP TKIP WEP104 WEP40
psk="99999999"
priority=5
}
4.4 Create a socket file for communication
mkdir -p /var/run/wpa_supplicant
4.5 Connect to WiFi
wpa_supplicant -B -c /etc/wpa_supplicant.conf -i wlan0
The effect is as follows:
# wpa_supplicant -B -c /etc/wpa_supplicant.conf -i wlan0
Successfully initialized wpa_supplicant
rfkill: Cannot open RFKILL control device
[ 670.124975] RTL8723BS: rtw_set_802_11_connect(wlan0) fw_state = 0x00000008
[ 678.988193] RTL8723BS: rtw_set_802_11_connect(wlan0) fw_state = 0x00000008
[ 688.127631] RTL8723BS: rtw_set_802_11_connect(wlan0) fw_state = 0x00000008
[ 697.804890] RTL8723BS: rtw_set_802_11_connect(wlan0) fw_state = 0x00000008
[ 698.446240] RTL8723BS: start auth
[ 698.466241] RTL8723BS: auth success, start assoc
[ 698.521065] RTL8723BS: rtw_cfg80211_indicate_connect(wlan0) BSS not found !!
[ 698.521119] RTL8723BS: assoc success
[ 698.598174] RTL8723BS: send eapol packet
[ 698.643221] RTL8723BS: send eapol packet
[ 698.644951] RTL8723BS: set pairwise key camid:4, addr:9e:a4:d3:f5:da:8d, kid:0, type:AES
[ 698.647953] RTL8723BS: set group key camid:5, addr:9e:a4:d3:f5:da:8d, kid:1, type:AES
4.6 Configure dynamic IP
udhcpc -i wlan0
The effect is as follows:
# udhcpc -i wlan0
udhcpc: started, v1.27.2
udhcpc: sending discover
udhcpc: sending select for 192.168.7.42
udhcpc: lease of 192.168.7.42 obtained, lease time 3599
deleting routers
adding dns 192.168.7.229
4.7 View network information
wpa_cli -iwlan0 status
The effect is as follows:
# wpa_cli -iwlan0 status
bssid=9e:a4:d3:f5:da:8d
freq=2437
ssid=liefyuan
id=0
mode=station
pairwise_cipher=CCMP
group_cipher=CCMP
key_mgmt=WPA2-PSK
wpa_state=COMPLETED
ip_address=192.168.7.42
address=84:20:96:ab:33:12
4.8 External network connection test
ping www.baidu.com
The effect is as follows:
# ping www.baidu.com
PING www.baidu.com (14.119.104.254): 56 data bytes
64 bytes from 14.119.104.254: seq=1 ttl=55 time=54.327 ms
64 bytes from 14.119.104.254: seq=2 ttl=55 time=35.489 ms
64 bytes from 14.119.104.254: seq=3 ttl=55 time=33.620 ms
64 bytes from 14.119.104.254: seq=4 ttl=55 time=28.683 ms
64 bytes from 14.119.104.254: seq=5 ttl=55 time=52.885 ms
64 bytes from 14.119.104.254: seq=6 ttl=55 time=376.766 ms
64 bytes from 14.119.104.254: seq=7 ttl=55 time=21.278 ms
64 bytes from 14.119.104.254: seq=8 ttl=55 time=50.338 ms
64 bytes from 14.119.104.254: seq=10 ttl=55 time=101.665 ms
64 bytes from 14.119.104.254: seq=11 ttl=55 time=213.840 ms
^C
--- www.baidu.com ping statistics ---
12 packets transmitted, 10 packets received, 16% packet loss
round-trip min/avg/max = 21.278/96.889/376.766 ms
4.9 WiFi bandwidth test
The tested Bitrate is about 15 Mbits/sec. The network speed is about 15 Mbits/sec (please do not open other applications before testing to avoid affecting the test speed)
Use Ubuntu virtual machine as server:
iperf -s
liefyuan@ubuntu:~/rv1103/luckfox-pico-main-origin$ iperf -s
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 128 KByte (default)
------------------------------------------------------------
[ 4] local 192.168.1.105 port 5001 connected with 192.168.1.107 port 59360
[ ID] Interval Transfer Bandwidth
[ 4] 0.0-10.1 sec 21.6 MBytes 18.0 Mbits/secBoard test:
iperf -c 192.168.1.105 -i 1
# cd /usr/bin/
# chmod 777 iperf
# iperf -c 192.168.1.105 -i 1
------------------------------------------------------------
Client connecting to 192.168.1.105, TCP port 5001
TCP window size: 43.8 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.1.107 port 59360 connected with 192.168.1.105 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0- 1.0 sec 2.50 MBytes 21.0 Mbits/sec
[ 3] 1.0- 2.0 sec 2.38 MBytes 19.9 Mbits/sec
[ 3] 2.0- 3.0 sec 2.38 MBytes 19.9 Mbits/sec
[ 3] 3.0- 4.0 sec 1.88 MBytes 15.7 Mbits/sec
[ 3] 4.0- 5.0 sec 2.38 MBytes 19.9 Mbits/sec
[ 3] 5.0- 6.0 sec 2.00 MBytes 16.8 Mbits/sec
[ 3] 6.0- 7.0 sec 2.00 MBytes 16.8 Mbits/sec
[ 3] 7.0- 8.0 sec 2.25 MBytes 18.9 Mbits/sec
[ 3] 8.0- 9.0 sec 1.88 MBytes 15.7 Mbits/sec
[ 3] 9.0-10.0 sec 1.88 MBytes 15.7 Mbits/sec
[ 3] 0.0-10.0 sec 21.6 MBytes 18.1 Mbits/secCommand analysis:
- -s: Indicates that the current device is used as a server.
- -c: Indicates that the current device is used as a client.
- 192.168.6.190: IP address of the server.
- -i: Trigger cycle.