当前文档版本为 v0.4.1,您可以访问当前页面的 开发中 版本以获取最近可能的更新。

Bluetooth: HCI UART

1 功能概述

此项目演示单BLE Controller的功能,支持 HCI UART,可以通过串口发送HCI命令,用于 DTM,或者配合外部 Host 使用。

2 环境要求

  • board: pan1080a_afld_evb

  • uart: hci uart (8n1, 115200)

  • 测试软件: Panchip Serial Assistant (或其他串口软件)

3 编译和烧录

项目位置:zephyr\samples_panchip\bluetooth\hci_uart

目前可使用ZAL工具或quick build脚本进行编译和下载。

脚本位置:quick_build_samples\bluetooth\hci_uart.bat

打开脚本后默认会编译项目,编译完成时,可输入字符进行后续下载等操作:

Input the keyword to continue:
  'b' build                         编译项目
  'r' make clean and rebuild        重新编译项目
  'f' flash download                下载
  'e' erase chip                    擦除芯片
  'o' open project by VS Code       打开 `VS Code`,可查看源码,执行编译下载等
  others exit                       退出
wait input:

4 演示说明

  1. HCI_Reset

    串口发送 (0x) 01 03 0C 00

    串口返回 (0x) 04 0E 04 01 03 0C 00

  2. LE Transmitter Test

    串口发送 (0x) 01 1E 20 03 00 25 00

    串口返回 (0x) 04 0E 04 01 1E 20 00

  3. LE Test End

    串口发送 (0x) 01 1F 20 00

    串口返回 (0x) 04 0E 06 01 1F 20 00 00 00

有关DTM测试流程请参考Core Specification v5.3 Volume 6 Part F.

5 Host Controller Interface

主机控制器接口(HCI)提供了访问蓝牙控制器功能的统一接口方法。有关接口的细节可以参考 Core Specification v5.3 Volume 4.

5.1 HCI Command packet

The HCI Command packet is used to send commands to the Controller from the Host.

image

HCI Command Packet

Figure 1 HCI Command packet

OpCode: (Size: 2 octets)

Value

Parameter Description

0xXXXX

OGF Range (6 bits): 0x00 to 0x3F (0x3F reserved for vendor-specific debug commands)
OCF Range (10 bits): 0x0000 to 0x03FF

HCI OpCode Group Field (OGF)

Value

Description

BT_OGF_LINK_CTRL

0x01

Link Control commands

BT_OGF_BASEBAND

0x03

Controller & Baseband commands

BT_OGF_INFO

0x04

Informational parameters

BT_OGF_STATUS

0x05

Status parameters

BT_OGF_LE

0x08

LE Controller commands

Parameter_Total_Length: (Size: 1 octet)

Value

Parameter Description

0xXX

Lengths of all of the parameters contained in this packet measured in octets. (N.B.: total length of parameters, not number of parameters)

Parameter 0 - N: (Size: Parameter Total Length)

Value

Parameter Description

0xXX

Lengths of all of the parameters contained in this packet measured in octets. (N.B.: total length of parameters, not number of parameters)

5.2 HCI Event packet

The HCI Event packet is used by the Controller to notify the Host when events occur.

image

HCI Event Packet

Figure 2 HCI Event packet

Event Code: (Size: 1 octet)

Value

Parameter Description

0xXX

Each event is assigned a 1-Octet event code used to uniquely identify different types of events.
Range: 0x00 to 0xFF (The event code 0xFF is reserved for the event code used for vendor-specific debug events.)

Parameter_Total_Length: (Size: 1 octet)

Value

Parameter Description

0xXX

Length of all of the parameters contained in this packet, measured in octets.

Event_Parameter 0 - N: (Size: Parameter_Total_Length)

Value

Parameter Description

0xXX

Each event has a specific number of parameters associated with it. These parameters and the size of each of the parameters are defined for each event. Each parameter is an integer number of octets in size.