Adding Bluetooth Support to Embedded Linux
Background
A brief introduction to the entire Bluetooth framework in Linux was provided earlier:
Today, we will briefly discuss how to add Bluetooth support in Embedded Linux.
Kernel Part
The kernel part is mainly divided into two sections: module drivers and the in-kernel Bluetooth protocol stack.
Here, we take the serial Bluetooth RTL8723DS as an example.
In-Kernel Bluetooth Protocol Stack
To add support for the Bluetooth subsystem in the kernel, you only need to enable the relevant configurations, such as:
CONFIG_BT=y
CONFIG_BT_BREDR=y
CONFIG_BT_RFCOMM=y
CONFIG_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_LE=y
Feature configurations can be added according to your needs, such as BLE, BREDR, RFCOMM, etc.
Module Driver
The serial Bluetooth driver is generally divided into two parts: the driver and the hciattach tool.
- • Compile the driver module: for example, here is
<span>hci_uart.ko</span>
- • Compile the hciattach tool: for example, here is
<span>rtk_hciattach</span>
hciattach is a tool used to initialize the Bluetooth chip and connect it to the host. It is part of the BlueZ Bluetooth protocol stack and is mainly used to configure the Bluetooth controller on a serial interface (such as UART) and start HCI (Host Controller Interface) layer communication. With hciattach, you can specify the type of Bluetooth device, baud rate, and other necessary parameters so that the operating system can correctly recognize and operate the Bluetooth hardware.
## File System Part
This part mainly includes the protocol stack <span>bluez</span>
and related dependency services, such as <span>Dbus</span>
. Here, we use buildroot to build, which is much simpler than compiling each one manually; you just need to enable Bluetooth-related configurations, such as:
BR2_SYSTEM_ENABLE_NLS=y
BR2_PACKAGE_BLUEZ_TOOLS=y
BR2_PACKAGE_BLUEZ5_UTILS=y
BR2_PACKAGE_BLUEZ5_UTILS_CLIENT=y
BR2_PACKAGE_BLUEZ5_UTILS_TOOLS=y
BR2_PACKAGE_BLUEZ5_UTILS_DEPRECATED=y
BR2_PACKAGE_BLUEZ5_UTILS_EXPERIMENTAL=y
BR2_PACKAGE_BLUEZ_ALSA=y
Specific configurations should also be enabled according to your needs.
Usage and Testing
Confirm Power Management and rfkill
Confirm to enable the sleep pin (such as the <span>BT_REG_ON</span>
) and the reset pin. Sometimes, <span>rfkill</span>
is used to control the enabling and disabling of Bluetooth, which will not be elaborated here.
Confirm Firmware and Configuration
Confirm the firmware and configuration directory, and place it in the corresponding location. The default directory here is: <span>/lib/firmware/rtlbt</span>
, which can be determined according to the path specified in the <span>hciattach</span>
tool.
Auto-Start Related Services
Auto-start related services, mainly the <span>dbus</span>
and <span>bluetoothd</span>
daemon processes, are generally configured by default after buildroot compilation; just confirm:
#dbus:
dbus-daemon --system --print-pid --print-address
# External BlueZ protocol stack daemon
/usr/libexec/bluetooth/bluetoothd -n -d &
Load Driver Modules
Load the relevant driver modules and configure to start the serial Bluetooth controller (specific to serial Bluetooth):
# Load kernel protocol stack, etc. If already built-in the kernel, no need to load
insmod bluetooth.ko
# Load module driver module
insmod hci_uart.ko
# Configure the serial Bluetooth controller and start HCI layer communication
./rtk_hciattach -n -s 115200 ttyS0 rtk_h5 &
Start and Test
# hciconfig, enable HCI interface
hciconfig hci0 up
# Perform simple tests, such as enabling BLE advertising
hciconfig hci0 leadv
Later, you can use tools like hcitool, bluetoothctl, or btmgmt for testing. You can also implement related functions through code.
Summary
This article mainly outlines the entire process of adding Bluetooth functionality in Embedded Linux, without going into too many specific details.
References
- • https://blog.csdn.net/qq_28877125/article/details/133910777
- • https://blog.csdn.net/qq_28877125/article/details/134043288
Welcome to follow:
Feel free to add WeChat to join the discussion group:
For more, please click the bottom left corner Read the original text!