首页 > 技术知识 > 正文

注:此文章为调试蓝牙时搜罗得到的调试笔记,觉得很有帮助,故保存,原作者连接已经找不到了,如有知晓请告知笔者,笔者将补全转贴来源

1 修改和编译内核

将驱动包中bluetooth_uart_driver文件夹下的文件直接拷贝(直接替换当前路径下的文件)到KERNEL/drivers/bluetooth。 make ARCH=arm CROSS_COMPILE=arm-himix100-linux- menuconfig

配置[Networking support >Bluetooth subsystem support]如下图所示,

bluetooth蓝牙移植记录-蓝牙设备已迁移是什么意思

配置[Networking support >Bluetooth subsystem support->Bluetooth device drivers]如下图所示,

bluetooth蓝牙移植记录-蓝牙设备已迁移是什么意思1

配置[Device Drivers > Input device support > Miscellaneous devices]如下图所示,

bluetooth蓝牙移植记录-蓝牙设备已迁移是什么意思2

配置[Device Drivers > HID support]如下图所示,

bluetooth蓝牙移植记录-蓝牙设备已迁移是什么意思3 make ARCH=arm CROSS_COMPILE=arm-himix100-linux-

生成rfcomm.ko、bnep.ko、uhid.ko、hci_uart.ko、hidp.ko等驱动文件。

make ARCH=arm CROSS_COMPILE=arm-himix100-linux- uImage

生成内核镜像文件uImage。

问题:scripts/kconfig/lxdialog/dialog.h:38:20: fatal error: curses.h: No such file or directory

解决办法:apt-get install libncurses5-dev

问题:”mkimage” command not found – U-Boot images will not be built

解决办法:sudo apt-get install u-boot-tools

2 编译rtk_hciattach

将rtk_hciattach文件夹拷贝到虚拟机, cd rtk_hciattach make CROSS_COMPILE=arm-himix100-linux- arm-himix100-linux-strip rtk_hciattach

3 创建相关目录

dbus-daemon、bluetoothd运行时会去相关目录找配置文件和生成临时文件,需要提前创建好相关目录。

根据编译过程中的配置,需要创建: /etc/dbus-1/system.d /tmp/var/run/dbus

由于板端的/tmp目录用于tmpfs文件系统,所以在制作文件系统的时候只创建/tmp,在挂载好tmpfs文件系统之后再创建var/run/dbus(mkdir -p tmp/var/run/dbus)。

4 拷贝可执行程序和库文件

拷贝配置文件和驱动固件

将rtl8723d_config、rtl8723d_fw拷贝到/lib/firmware/rtlbt文件夹下。

将bluetooth.conf(bluez-5.18/src/bluetooth.conf)拷贝到/etc/dbus-1/system.d文件夹下,将文件中的下列内容删除, <!– allow users of lp group (printing subsystem) to communicate with bluetoothd –> <policy group=”lp”> <allow send_destination=”org.bluez”/> </policy>

如果不将上述内容删除则运行时会报错,此时则需要执行”addgroup lp”消除错误。

将system.conf(dbus-1.8.0/bus/system.conf)拷贝到/etc/dbus-1文件夹下。

问题

:/home/BLUE # ./dbus-daemon —system

Failed to start message bus: Failed to open “/etc/dbus-1/system.conf”: No such file or directory

解决办法:dbus-daemon运行时会去找配置文件,配置文件存放的路径由编译dbus时的configure操作指定(由—sysconfdir=xxx确定)。需要把配置文件放到指定的路径下面才能成功。

问题:

/home/BLUE # ./dbus-daemon —system

Failed to start message bus: Failed to bind socket “/tmp/var/run/dbus/system_bus_socket”: No such file or directory

解决办法:dbus-daemon运行时会生成pid和socket文件,文件存放的路径由编译dbus时的configure操作指定(由—prefix=xxx确定)。需要在程序运行前创建好文件夹并指定相应权限才能成功。

问题

:/home/BLUE # ./dbus-daemon —system

Failed to start message bus: Could not get UID and GID for username “messagebus”

解决办法:编译dbus时的configure时如果不指定—with-dbus-user值,则默认以用户messagebus运行,如果当前系统没有该用户则报错,需要使用下面的命令添加用户,

addgroup -S messagebus

adduser -S messagebus -G messagebus

在编译dbus时的configure指定—with-dbus-user=root,则以root用于运行该程序。

问题:

/home/BLUE # ./bluetoothd -d -n &

/home/BLUE # bluetoothd[960]: Bluetooth daemon 5.18

D-Bus setup failed: Failed to connect to socket /tmp/var/run/dbus/system_bus_socket: No such file or directory

bluetoothd[960]: Unable to get on D-Bus

解决办法:bluetoothd运行时使用socket与dbus通信,所以编译dbus、bluez时configure的—prefix字段要一致,且在运行bluetoothd之前运行dbus-daemon。

5 修改蓝牙设备名字

默认名字为“BlueZ 5.18”。通过main.conf修改为指定的名字,创建/etc/bluetooth文件夹,将main.conf(bluez-5.18/src/main.conf

)拷贝到该文件夹,修改Name字段的值即可。

6 在板端运行

cd /home/BLUE && ./rtk_hciattach -n -s 115200 ttyAMA2 rtk_h5 & ./hciconfig ./hciconfig hci0 up //使能扫描和被扫描(配对)功能 ./hciconfig hci0 piscan ./dbus-daemon –system ./bluetoothd -d -n & ./hcitool scan

7 使用函数发现附近蓝牙设备(C程序)

通过test1.c(百度网盘)找到附近的蓝牙设备ID(MAC)和设备名字(Name);编译方式:arm-himix100-linux-gcc test1.c -o test1 -lbluetooth -L/usr/local/bluez/lib -I/usr/local/bluez/include;

8 连接打印机

参考:BTBook.pdf

打印机实现了SPP(依靠RFCOMM通信),所以板端只要实现RFCOMM通信的客户端即可。以下程序test2_client.c(百度网盘)是板端连接打印机并打印两行内容。

arm-himix100-linux-gcc test2_client.c -o test2_client -lbluetooth -L/tmp/lib -I/tmp/include

猜你喜欢