Ai-Thinker Ai-M62-CBS WIFI6 +BLE. 5.3 module(BL616 chip)use as SDIO / USB wireless nerwork card and BLE adapter

Tara Qiu(Ai-Thinker)
5 min readJul 25, 2024

--

#wifi6 #SDIO #USB WIFI adapter

The Ai-M62-CBS wireless network card module uses the Bouffalo BL616 chip solution, provides SDIO / USB interface, and can be used as a BLE HCI adapter through the UART / USB interface. This article takes the Raspberry Pi as an example to introduce the process of M62-CBS driver transplantation and networking.

Software and Hardware Requirements

Target board hardware requirements

1.1. Connect via USB interface

  • USB interface

1.2. Connect via SDIO interface

  • SDIO
  • UART(if BLE function is required)

Target board software requirements

  • Linux Kernel 3.10 ~ 5.15.79 (need to enable mac80211 related configuration options)
  • wpa_supplicant / hostapd 2.9+ (need to enable nl80211 option before compilation)
  • BlueZ 5 (if you need to use BLE function)

Development machine software requirements

  • Target board Linux kernel source code
  • Target board cross-compilation tool chain

Hardware connection

Your Linux development board can be connected to the Ai-M62-CBS module via the USB interface or the SDIO + UART interface. In order to facilitate user debugging, we have pre-designed the adapter board shown in the figure below, which can be connected by plugging it in. The corresponding project file we had update on LCSC platform is attached at the end of the article. When proofing, pay attention to setting the board thickness to 0.8mm, otherwise it will not fit into the SD card slot.

Driver compilation

For driver compilation methods, see the document “BL616 Linux Driver Porting and Usage Instructions” at the end and the README document under the driver source code. Here we focus on two points.

The driver Makefile is compiled using the Native tool chain by default, which means that the driver runs on the local machine (as shown below).

If you are cross-compiling, you need to modify the KERNELDIR variable, uncomment ARCH and CROSS_COMPILE and modify them to actual values. You also need to uncomment the make line.

If a compilation error occurs, please carefully check the error message and documentation to see if the kernel-related configuration options are enabled. For example, the bl_get_wireless_stats() function reports an error because the CONFIG_WIRELESS_EXT option is not enabled.

Install the driver to the target board

The driver supports three modes: STA/AP, STA+AP and Repeater. We will use the STA+AP coexistence mode as an example to explain the process. For the configuration parameters of the other two modes, please refer to the README document under the source code.

  1. Copy the kernel module (bl_sdio_drv.ko or bl_usb_drv.ko) and the corresponding module firmware to the target board file system, and put the corresponding module firmware (bl616_sd_combo.bin or bl616_usb_combo.bin) in the /lib/firmware folder.
  2. Execute insmod bl616_sd_combo.bin opmode=2 or insmod bl616_usb_combo.bin opmode=2 to load the kernel module.
  3. Use the ip addr command to check whether two new wireless network cards, wlan0 and ap0, have been added. If no wireless network card is detected, check the connection or use the dmesg command to view the kernel log to diagnose the cause.
  4. If rfkill is enabled, you need to use rfkill unblock all to enable the wireless network card.

Use wpa_supplicant to connect to Wi-Fi hotspot

1. Use ps -eF | grep wpa_supplicant command to check whether other wpa_supplicant is currently running. If it exists, you need to kill it first, otherwise it will fail.
2. Use the following command to set up Wi-Fi network

1 wpa_passphrase ABC 12345678 > bf.conf  # Replace ABC and 12345678 with the ssid and password of your actual WiFi.
2 wpa_supplicant -D nl80211 -i wlan0 -c bf.conf -B # Start wpa_supplicant to connect to the network, and replace wlan0 with the actual wireless network card interface
3 udhcpc -i wlan0 # Obtain an IP address via DHCP

3. After the connection is complete, use ip addr to check whether the IP address is obtained

4. Connect to a WPA3 encrypted WiFi hotspot

1 cat <<'EOF' > bf.conf
2 ctrl_interface=/var/run/wpa_supplicant
3 update_config=1
4
5 network={
6 ssid="ASUS_2.4"
7 scan_ssid=1
8 key_mgmt=SAE
9 psk="88888888"
10 ieee80211w=1
11 }
12 EOF

Use hostapd to enable Wi-Fi hotspot

  1. Check whether there is a network card named ap0
1 ip addr

2. Create a new hostapd configuration file

cat <<'EOF' > hostapd.conf
interface=ap0
drvier=nl80211

# Operation mode a = IEEE 802.11a (5 GHz), b = IEEE 802.11b (2.4 GHz),
# g = IEEE 802.11g (2.4 GHz), ad = IEEE 802.11ad (60 GHz);
# a/g options are used with IEEE 802.11n (HT), too, to specify band.
# For IEEE 802.11ac (VHT), this needs to be set to hw_mode=a.
# For IEEE 802.11ax (HE) on 6 GHz this needs to be set to hw_mode=a.
hw_mode=g

# Channels 1-13 are available in the 2.4GHz frequency band
channel=7

wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

#Your WIFIname
ssid=BL616

#Your password
wpa_passphrase=12345678
EOF

3. Run hostapd service

hostapd -B hostapd.conf

4. Configuring the IP address of the AP

ip address add 192.168.9.1/24 dev ap0

5. Configuring the AP’s DHCP Service

cat <<'EOF' > udhcpd.conf
interface ap0
start 192.168.9.100
end 192.168.9.200
max_leases 200
EOF

6. Start the DHCP Server

udhcpd udhcpd.conf &

7. Connect to the hotspot for testing, SSID BL616, password 12345678

BLE

1. Initialize Bluetooth (UART mode only, USB can be skipped)

# /dev/ttyUSB0:The serial port number that the module is connected to the Raspberry Pi should be replaced according to the actual serial port number.
hciattach -s 115200 /dev/ttyUSB0 any 115200 noflow nosleep

2. Query HCI

hciconfig

If devices such as hci0 appear, it means OK.

3. Turn on and restart the module Bluetooth

hciconfig hci0 up
hciconfig hci0 reset

4. (Optional) Configure BLE broadcast data. You can view it by clicking the scanned BLE device in the debugging assistant.

hcitool -i hci0 cmd 0x08 0x0008 1f 02 01 06 0b 09 42 54 42 4c 45 2d 44 45 56 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

5. (Optional) Configure BLE scan response data. You can view the data by clicking the scanned BLE device in the debugging assistant.

hcitool -i hci1 cmd 0x08 0x0009 1f 02 01 06 0a 09 42 54 42 4c 45 2d 44 45 56 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

6. Enable BLE broadcast

hciconfig hci1 leadv 0

7. Open the monitoring software

btmon

8. Stop broadcasting and broadcast again

hciconfig hci1 noleadv
hciconfig hci1 leadv 0

More information

1. Ai-M62 series module special topic
2. LCSC Ai-Thinker Technology Open Source Team

Contact us

Shenzhen Ai-Thinker Technology Co., Ltd
Room 403,408–410, Building C, Huafeng Intelligence Innovation Port, Gushu, Xixiang, Baoan District, Shenzhen China 518126
Business cooperation: tara@aithinker.com
Official website: http://en.ai-thinker.com
Official Forum: http://bbs.ai-thinker.com

Original link(Ai-Thinker FAE Team engineer Mr Zeng): https://blog.csdn.net/u011300834/article/details/136862884

--

--