JVM面试题1

震惊!!!华为爆出这本惊天Redis宝典,原来Redis的性能可压榨到极致!

  返回  

蓝牙调试

2021/7/21 13:21:06 浏览:

蓝牙调试

文章目录

  • 蓝牙调试
  • 1、基础知识
    • 蓝牙模块类型
      • 经典蓝牙模块BT
      • 低功耗蓝牙模块BLE
    • 蓝牙传输速度
    • 蓝牙协议
      • BlueDroid
    • 蓝牙模式
    • 常见蓝牙模块型号
    • Device Io
    • 蓝牙MAC地址
  • 2、平台配置
    • 2.1、瑞芯微平台
      • 串口DTS配置
      • 蓝牙DTS配置
      • 配置蓝牙串口号、蓝牙固件目录
      • 开启蓝牙设备(默认开启)
      • Buildroot蓝牙配置
    • 2.2、全志平台
      • Linux3.10
      • Linux4.9
      • Android配置
  • 3、调试技巧
    • hciconfig
    • hcitool
    • brcm_patchram_plus
    • 手动控制蓝牙电源
    • 配置蓝牙设备名称
    • 提高蓝牙传输速度
  • 4、蓝牙系统框架
    • rfkill
    • Libbt
    • BlueDroid
    • Bluetooth.apk
  • 5、常见问题
    • 5.0、硬件问题排查
    • 5.1、设置中没有蓝牙开关选项
    • 5.2、蓝牙打开失败
      • 找不到HCD文件
      • 加载HCD文件失败
      • 串口通讯失败
      • RFKILL驱动加载失败
      • 检查硬件电路
    • 5.3、bluedroid初始化失败
    • 5.4、Buildroot蓝牙打开失败
      • 蓝牙初始化失败
      • 蓝牙不稳定
      • RTL蓝牙模块初始化失败
    • 5.5、蓝牙音频
      • 蓝牙音乐播放卡顿

1、基础知识

蓝牙模块类型

经典蓝牙模块BT

低功耗蓝牙模块BLE

蓝牙传输速度

蓝牙传输速率 取决于 串口速率 、

蓝牙协议

Android4.2之前使用BlueZ协议

Android4.2之后使用BlueDroid协议

BlueDroid

蓝牙模式

  • 主模式

    用途:

  • 从模式

    用途:车机蓝牙音箱

常见蓝牙模块型号

  • Realtek 瑞昱

    RTL8723BS

  • Broadcom 博通

    AP6256

Device Io

  • 作用

    Deviceio是RK提供的应用开发库,屏蔽底层复杂的WIFI/BT操作

  • 使用详细

    参考 docs\Linux\Wifibt 目录下的文档

    WIFI开发: Rockchip_Developer_Guide_DeviceIo_WIFI_CN.pdf

    蓝牙开发: Rockchip_Developer_Guide_DeviceIo_Bluetooth_CN.pdf

    配网开发(BLE/SOFTAP): Rockchip_Developer_Guide_Network_Config_CN.pdf

蓝牙MAC地址

蓝牙会从/dev/vflash里读取MAC地址,只要用工具将MAC地址写入vflash分区即可

默认情况下,所有设备的蓝牙MAC地址是相同的

  • 读取MAC地址实现代码

    system/bt/btif/src/btif_core.c

2、平台配置

2.1、瑞芯微平台

串口DTS配置

&uart0 {
	status = "okay";
};

蓝牙DTS配置

  • 配置WIFI蓝牙模组型号(相同品牌即可兼容)
wireless-wlan {
    compatible = "wlan-platdata";
    wifi_chip_type ="ap6255"; 			//或者 如”rtl8723ds”;
    WIFI,host_wake_irq = <&gpio0 GPIO_D4 GPIO_ACTIVE_HIGH>;
    status = "okay";
};

系统会根据wifi_chip_type加载不同的libbt库

目前主要使用的是broadcom或realtek,两者不能同时兼容

示例:若配置ap6255,就会加载broadcom库,可兼容broadcom全系列蓝牙模块

  • 配置蓝牙GPIO
wireless-bluetooth {
    compatible = "bluetooth-platdata";
    clocks = <&rk808 1>;
    clock-names = "ext_clock";
    //wifi-bt-power-toggle;
    uart_rts_gpios = <&gpio2 19 GPIO_ACTIVE_LOW>;
    pinctrl-names = "default", "rts_gpio";
    pinctrl-0 = <&uart0_rts>;
    pinctrl-1 = <&uart0_gpios>;
    //BT,power_gpio = <&gpio3 19 GPIO_ACTIVE_HIGH>;
    BT,reset_gpio = <&gpio0 9 GPIO_ACTIVE_HIGH>;
    BT,wake_gpio = <&gpio2 26 GPIO_ACTIVE_HIGH>;
    BT,wake_host_irq = <&gpio0 4 GPIO_ACTIVE_HIGH>;
    status = "okay";
};

&pinctrl {
    wireless-bluetooth {
    	uart0_gpios: uart0-gpios {
    		rockchip,pins = <2 19 RK_FUNC_GPIO &pcfg_pull_none>;
    	};
    };
};

配置蓝牙串口号、蓝牙固件目录

参考Libbt

开启蓝牙设备(默认开启)

$ vim device/rockchip/rk3399pro/BoardConfig.mk
	BOARD_HAVE_BLUETOOTH = true

Buildroot蓝牙配置

  • 配置蓝牙型号、蓝牙串口号

  • BSA配置

    Realtek使用Linux标准bluez协议栈

    正基使用私有协议栈broadcom_bsa

    海华使用私有协议栈cypress_bsa

$ cd buildroot
$ source build/envsetup.sh
$ make ARCH=arm64 menuconfig

$ make rkwifibt-dirclean && make rkwifibt-rebuild

$ make broadcom_bsa-dirclean && make broadcom_bsa-rebuild

2.2、全志平台

Linux3.10

  • 内核配置
> Networking support
	> Bluetooth subsystem support		蓝牙功能配置项
		> Bluetooth device drivers
			> Broadcom Bluetooth Low Power Manager Support
  • 配置sys_config.fex
[uart1]

[bt_para]
    BT_RST_N
    BT_WAKE_AP
    AP_WAKE_BT

Linux4.9

  • DTS配置
bt:bt {
        compatible    = "allwinner,sunxi-bt";
        clocks        = <&clk_losc_out>;
        bt_power      = "axp858-dcdc1";
        bt_io_regulator = "axp858-cldo2";
        bt_rst_n      = <&pio PG 14 1 0xffffffff 0xffffffff 0>;
        status        = "okay";
};


btlpm:btlpm {
        compatible  = "allwinner,sunxi-btlpm";
        uart_index  = <0x1>;
        bt_wake     = <&pio PE 7 1 0xffffffff 0xffffffff 1>;
        bt_hostwake = <&pio PE 6 6 0xffffffff 0xffffffff 0>;
        status      = "okay";
};

bt_rst_n复位引脚

bt_wake唤醒蓝牙引脚

bt_hostwake唤醒主机引脚

uart_index串口编号

Android配置

3、调试技巧

hciconfig

$ hciconfig -a
    hci0:    Type: Primary  Bus: UART
        BD Address: 22:22:BA:D5:73:E9  ACL MTU: 1021:8  SCO MTU: 255:12
        UP RUNNING 
        RX bytes:2227 acl:0 sco:0 events:65 errors:0
        TX bytes:1893 acl:0 sco:0 commands:66 errors:0
        Features: 0xff 0xff 0xff 0xfe 0xdb 0xfd 0x7b 0x87
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
        Link policy: RSWITCH HOLD SNIFF PARK 
        Link mode: SLAVE ACCEPT 
        Name: 'BlueZ 5.50'
        Class: 0x000000
        Service Classes: Unspecified
        Device Class: Miscellaneous, 
        HCI Version: 4.1 (0x7)  Revision: 0xaa6b
        LMP Version: 4.1 (0x7)  Subversion: 0x274f
        Manufacturer: Realtek Semiconductor Corporation (93)
$ hciconfig hci0 up

hcitool

hcitool scan

brcm_patchram_plus

手动控制蓝牙电源

参考rfkill

配置蓝牙设备名称

$ vim device/rockchip/rk3399pro/bluetooth/bdroid_buildcfg.h
    #ifndef _BDROID_BUILDCFG_H
    #define _BDROID_BUILDCFG_H

    #define BTM_DEF_LOCAL_NAME      "rk3399"			//蓝牙设备名称
    #define BTA_DM_COD {0x1A, 0x01, 0x10}
    #define BLE_PRIVACY_SPT FALSE
    #define KERNEL_MISSING_CLOCK_BOOTTIME_ALARM TRUE
    #endif

提高蓝牙传输速度

$ vim hardware/broadcom/libbt/include/vnd_rk30sdk.txt
	UART_TARGET_BAUD_RATE = 1500000			//1500000改成3000000

4、蓝牙系统框架

rfkill

蓝牙电源控制驱动

源码目录:kernel/net/rfkill/rfkill-bt.c

设备节点:/sys/class/rfkill/rfkill0/state(根据模块注册顺序,查看具体rfkill编号)

  • 手动上电蓝牙模块(系统启动过程会自动执行上电流程)

    $ echo 1 > /sys/class/rfkill/rfkill0/state
    
  • 手动下电蓝牙模块(驱动加载失败后执行下电流程)

    $ echo 0 > /sys/class/rfkill/rfkill0/state
    

Libbt

作用:初始化蓝牙模块,加载蓝牙固件

Libbt目前主要有broadcom、realtek,根据模组型号配置,参考蓝牙DTS配置

  • 博通Libbt

    源码目录:hardware/broadcom/libbt/

    配置蓝牙串口号、蓝牙固件目录

    $ vim hardware/broadcom/libbt/conf/rockchip/rksdk/bt_vendor.conf
        # UART device port where Bluetooth controller is attached
        UartPort = /dev/ttyS0
    
        # Firmware patch file location
        FwPatchFilePath = /vendor/etc/firmware/
    
  • RTL Libbt

    源码目录: hardware/realtek/rtkbt/code/libbt-vendor/

    配置蓝牙串口号、蓝牙固件目录

    $ vim hardware/realtek/rtkbt/code/libbt-vendor/include/vnd_buildcfg.h
        #ifndef _VND_BUILDCFG_H
        #define _VND_BUILDCFG_H
        #define BLUETOOTH_UART_DEVICE_PORT   "/dev/ttyS1"
        #define FW_PATCHFILE_LOCATION   "/etc/firmware/"
        #define LPM_IDLE_TIMEOUT_MULTIPLE   5
        #define SCO_USE_I2S_INTERFACE   TRUE
        #define BTVND_DBG   TRUE
        #define BTHW_DBG   TRUE
        #define VNDUSERIAL_DBG   TRUE
        #define UPIO_DBG   TRUE
        #endif
    

BlueDroid

源码目录:system/bt/

Bluetooth.apk

5、常见问题

5.0、硬件问题排查

  1. 确认蓝牙供电是否正常

    VBAT(9脚)供电3.3V

    WIFI打开成功也表示VBAT脚有供电

  2. 确认32k时钟是否准确

    WIFI工作不需要32K时钟

    万用表测LPO(24脚)电压1.5V

    示波器测信号频率32K

  3. 确认串口通讯是否正常

    TX、RX交叉连接,可尝试加上拉电阻

    RTS、CTS交叉连接

    开启硬件流控(RTS、CTS)

  4. GPIO配置

    RST引脚

    WAKE_BT引脚

    HOST_WAKE引脚

5.1、设置中没有蓝牙开关选项

参考开启蓝牙设备(默认开启)

5.2、蓝牙打开失败

找不到HCD文件

  • 原因分析

加载HCD文件失败

串口通讯失败

  • 原因分析

    1. 参考串口DTS配置

    2. 确认是否存在节点

    $ ls /dev/ttyS*
    
    1. 串口访问权限
    $ vim device/rockchip/common/ueventd.rockchip.rc
    	/dev/ttyS0                0660   bluetooth  net_bt_stack
    
    1. TX/RX是否有上拉

RFKILL驱动加载失败

  • 驱动加载成功LOG

    [    3.859992] [BT_RFKILL]: Enter rfkill_rk_init
    [    3.860690] [BT_RFKILL]: bluetooth_platdata_parse_dt: get property: uart_rts_gpios = 83.
    [    3.860772] [BT_RFKILL]: bluetooth_platdata_parse_dt: get property: BT,reset_gpio = 92.
    [    3.860833] [BT_RFKILL]: bluetooth_platdata_parse_dt: get property: BT,wake_gpio = 90.
    [    3.860875] [BT_RFKILL]: bluetooth_platdata_parse_dt: get property: BT,wake_host_irq = 5.
    [    3.861303] [BT_RFKILL]: Request irq for bt wakeup host
    [    3.861398] [BT_RFKILL]: ** disable irq
    [    3.861598] [BT_RFKILL]: bt_default device registered.
    
  • 驱动加载成功生成RFKILL节点

    $ /sys/class/rfkill/rfkill*
    
  • 原因分析

    1、检查GPIO配置,电源、复位、RTS

    2、万用表测量GPIO,是否受控

检查硬件电路

参考硬件问题排查

  • 报错LOG

    I bt_osi_thread: run_thread: thread id 944, thread name stack_manager started
    I bt_stack_manager: event_init_stack is initializing the stack
    E         : [0916/100003.799297:ERROR:config.cc(74)] config_new: unable to open file '/data/misc/bluedroid/bt_config.conf': No such file or directory
    W bt_btif_config: init unable to load config file: /data/misc/bluedroid/bt_config.conf; using backup.
    E         : [0916/100003.799474:ERROR:config.cc(74)] config_new: unable to open file '/data/misc/bluedroid/bt_config.bak': No such file or directory
    W bt_btif_config: init unable to load backup; attempting to transcode legacy file.
    E bt_btif_config_transcode: btif_config_transcode unable to load XML file '/data/misc/bluedroid/bt_config.xml': 3
    E bt_btif_config: init unable to transcode legacy file; creating empty config.
    E bt_osi_alarm: timer_create_internal unable to create timer with clock 9: Unknown error 524
    E bt_osi_alarm: The kernel might not have support for timer_create(CLOCK_BOOTTIME_ALARM): https://lwn.net/Articles/429925/
    E bt_osi_alarm: See following patches: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/log/?qt=grep&q=CLOCK_BOOTTIME_ALARM
    F         : [0916/100003.800342:FATAL:alarm.cc(179)] Check failed: false. 
    F libc    : Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 944 (stack_manager), pid 927 (droid.bluetooth)
    
  • 解决方法

    $ vim system\bt\osi\src\alarm.cc
        + #define KERNEL_MISSING_CLOCK_BOOTTIME_ALARM TRUE    /*add by wugk*/
        #if (KERNEL_MISSING_CLOCK_BOOTTIME_ALARM == TRUE)
    

5.3、bluedroid初始化失败

  • 初始化成功LOG
02-10 01:15:56.438 I/        ( 1257): BTE_InitTraceLevels -- TRC_HCI
02-10 01:15:56.438 I/        ( 1257): BTE_InitTraceLevels -- TRC_L2CAP
02-10 01:15:56.438 I/        ( 1257): BTE_InitTraceLevels -- TRC_RFCOMM
02-10 01:15:56.438 I/        ( 1257): BTE_InitTraceLevels -- TRC_AVDT
02-10 01:15:56.438 I/        ( 1257): BTE_InitTraceLevels -- TRC_AVRC
02-10 01:15:56.438 I/        ( 1257): BTE_InitTraceLevels -- TRC_A2D
02-10 01:15:56.438 I/        ( 1257): BTE_InitTraceLevels -- TRC_BNEP
02-10 01:15:56.438 I/        ( 1257): BTE_InitTraceLevels -- TRC_BTM
02-10 01:15:56.438 I/        ( 1257): BTE_InitTraceLevels -- TRC_GAP
02-10 01:15:56.438 I/        ( 1257): BTE_InitTraceLevels -- TRC_PAN
02-10 01:15:56.438 I/        ( 1257): BTE_InitTraceLevels -- TRC_SDP
02-10 01:15:56.438 I/        ( 1257): BTE_InitTraceLevels -- TRC_GATT
02-10 01:15:56.438 I/        ( 1257): BTE_InitTraceLevels -- TRC_SMP
02-10 01:15:56.438 I/        ( 1257): BTE_InitTraceLevels -- TRC_BTAPP
02-10 01:15:56.438 I/        ( 1257): BTE_InitTraceLevels -- TRC_BTIF
  • 失败原因分析

    1、

5.4、Buildroot蓝牙打开失败

  • Buildroot蓝牙驱动加载LOG分析
// 打印蓝牙HCD的路径、蓝牙串口
// HCD文件必须与蓝牙模块型号匹配
// 串口号必须对照原理图
hcd_file = /vendor/etc/firmware/BCM4345C0.hcd
ttys_dev = /dev/ttyS8

// 博通系列蓝牙在初始化前会kill掉这个服务
killall: brcm_patchram_plus1: no process killed
killall: bsa_server: no process killed

//蓝牙初始化
[   16.560680] [BT_RFKILL]: bt shut off power
[   17.569283] [BT_RFKILL]: rfkill_rk_set_power: set bt wake_host high!
[   17.620171] [BT_RFKILL]: ENABLE UART_RTS
[   17.726769] [BT_RFKILL]: DISABLE UART_RTS
[   17.726867] [BT_RFKILL]: bt turn on power
[   17.726931] [BT_RFKILL]: Request irq for bt wakeup host
[   17.727004] [BT_RFKILL]: ** disable irq

蓝牙初始化失败

  • 报错LOG
BSA_trace 6@ 01/01 00h:00m:19s:241ms: uipc_cl_socket_connect: connect(/data/bsa/config/./bt-daemon-socket) failed(No such file or directory)
BSA_trace 7@ 01/01 00h:00m:19s:254ms: uipc_cl_control_open fails to connect control socket
BSA_trace 8@ 01/01 00h:00m:19s:263ms: BSA_MgtOpen UIPC_open fails (cannot connect to server)
  • 原因分析
    1. WIFI模块型号 或 串口号 配置错误
    2. BSA配置编译错误

蓝牙不稳定

RTL蓝牙模块初始化失败

5.5、蓝牙音频

蓝牙音乐播放卡顿

主要问题是硬件底层射频信号不好,特别是打开WIFI、WIFI扫描状态下特别严重

  • 硬件问题

    检查天线是否焊接正常

  • 软件问题

    确保WIFI驱动、固件更新到最新

  • 提高蓝牙射频优先级补丁(对蓝牙信号会有改善)

    --- a/system/bt/stack/include/hcidefs.h
    +++ b/system/bt/stack/include/hcidefs.h
    @@ -1074,6 +1074,10 @@ typedef struct
     #define HCI_BRCM_ACL_PRIORITY_LOW           0x00
     #define HCI_BRCM_ACL_PRIORITY_HIGH          0xFF
     #define HCI_BRCM_SET_ACL_PRIORITY           (0x0057 | HCI_GRP_VENDOR_SPECIFIC)
    +#define HCI_BRCM_SET_A2DP_PRIORITY          (0x011A | HCI_GRP_VENDOR_SPECIFIC)
    +#define HCI_BRCM_ACL_PRIORITY_NORMAL        0x00
    +#define HCI_BRCM_ACL_PRIORITY_A2DP          0x01
    +#define HCI_BRCM_ACL_PRIORITY_A2DP_PARAM_SIZE    4
     
     /* Define values for LMP Test Control parameters
     ** Test Scenario, Hopping Mode, Power Control Mode
    
    
    --- a/system/bt/stack/l2cap/l2c_utils.c
    +++ b/system/bt/stack/l2cap/l2c_utils.c
    @@ -2389,6 +2389,7 @@ BOOLEAN l2cu_set_acl_priority (BD_ADDR bd_addr, UINT8 priority, BOOLEAN reset_af
         UINT8               *pp;
    +    UINT8                type_param;
     
         APPL_TRACE_EVENT1("SET ACL PRIORITY %d", priority);
     
    @@ -2408,12 +2409,17 @@ BOOLEAN l2cu_set_acl_priority (BD_ADDR bd_addr, UINT8 priority, BOOLEAN reset_af
             {
                 pp = command;
     
    -            vs_param = (priority == L2CAP_PRIORITY_HIGH) ? HCI_BRCM_ACL_PRIORITY_HIGH : HCI_BRCM_ACL_PRIORITY_LOW;
    +            //vs_param = (priority == L2CAP_PRIORITY_HIGH) ? HCI_BRCM_ACL_PRIORITY_HIGH : HCI_BRCM_ACL_PRIORITY_LOW;
    +            vs_param = (priority == L2CAP_PRIORITY_HIGH) ? HCI_BRCM_ACL_PRIORITY_A2DP: HCI_BRCM_ACL_PRIORITY_NORMAL;
    +            type_param = 0x01;
     
    +            APPL_TRACE_ERROR1("Luke: SET ACL PRIORITY %d", priority);
                 UINT16_TO_STREAM (pp, p_lcb->handle);
                 UINT8_TO_STREAM  (pp, vs_param);
    +            UINT8_TO_STREAM  (pp, type_param);
     
    -            BTM_VendorSpecificCommand (HCI_BRCM_SET_ACL_PRIORITY, HCI_BRCM_ACL_PRIORITY_PARAM_SIZE, command, NULL);
    +            //BTM_VendorSpecificCommand (HCI_BRCM_SET_ACL_PRIORITY, HCI_BRCM_ACL_PRIORITY_PARAM_SIZE, command, NULL);
    +            BTM_VendorSpecificCommand (HCI_BRCM_SET_A2DP_PRIORITY, HCI_BRCM_ACL_PRIORITY_A2DP_PARAM_SIZE, command, NULL);
     
                 /* Adjust lmp buffer allocation for this channel if priority changed */
                 if (p_lcb->acl_priority != priority)
    

联系我们

如果您对我们的服务有兴趣,请及时和我们联系!

服务热线:18288888888
座机:18288888888
传真:
邮箱:888888@qq.com
地址:郑州市文化路红专路93号