bluetooth蓝牙移植记录

在学了在学了! 2022-04-06 11:12:26 6779

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

1 修改和编译内核
将驱动包中bluetooth_uart_driver文件夹下的文件直接拷贝(直接替换当前路径下的文件)到KERNEL/drivers/bluetooth。

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

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

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

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

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

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

声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。
红包 点赞 收藏 评论 打赏
评论
0个
内容存在敏感词
手气红包
    易百纳技术社区暂无数据
相关专栏
置顶时间设置
结束时间
删除原因
  • 广告/SPAM
  • 恶意灌水
  • 违规内容
  • 文不对题
  • 重复发帖
打赏作者
易百纳技术社区
在学了在学了!
您的支持将鼓励我继续创作!
打赏金额:
¥1易百纳技术社区
¥5易百纳技术社区
¥10易百纳技术社区
¥50易百纳技术社区
¥100易百纳技术社区
支付方式:
微信支付
支付宝支付
易百纳技术社区微信支付
易百纳技术社区
打赏成功!

感谢您的打赏,如若您也想被打赏,可前往 发表专栏 哦~

举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

审核成功

发布时间设置
发布时间:
是否关联周任务-专栏模块

审核失败

失败原因
备注
拼手气红包 红包规则
祝福语
恭喜发财,大吉大利!
红包金额
红包最小金额不能低于5元
红包数量
红包数量范围10~50个
余额支付
当前余额:
可前往问答、专栏板块获取收益 去获取
取 消 确 定

小包子的红包

恭喜发财,大吉大利

已领取20/40,共1.6元 红包规则

    易百纳技术社区