4.3 HCI Application
Introduction
This document aims to provide a concise guide on developing Human-Computer Interaction (HCI) applications utilizing the Bluetooth® Low Energy (BLE) UART transport interface.
In the context of HCI with BLE UART, communication is established using the BLE protocol along with a Universal Asynchronous Receiver-Transmitter (UART) interface. BLE is a wireless communication standard designed for short-range communication between devices, offering lower power consumption than classic Bluetooth. UART is a hardware communication protocol that enables serial communication by transmitting data as a sequence of individual bits.
Combining BLE with UART allows for seamless and efficient data transmission between devices like microcontrollers, computers, and mobile phones without requiring a lot of power. This setup is particularly beneficial for applications where small data packets are exchanged frequently over moderate distances, such as in wearable devices, home automation systems and other IoT applications.
Thus, using BLE UART in HCI applications enables developers to create interfaces that can communicate wirelessly with user input and output devices, enhancing the user experience by integrating physical computing devices smoothly into human activities.
Users have the option to either execute the pre-built application example hex file on the WBZ351 Curiosity Board for an immediate demonstration or to delve into the detailed process of building the application from the ground up.
For an optimal learning experience, it is recommended to approach the examples sequentially, starting with fundamental concepts and gradually advancing to more complex topics.
Recommended Reads
Hardware Requirement
Tool |
Quantity |
---|---|
WBZ351 Curiosity Board |
1 |
Micro USB cable |
1 |
FTDI Cable | 1 |
SDK Setup
Software Requirement
Programming the Precompiled Hex File or Application Example
Steps to programming the hex file using MPLAB X IPE:
- Import and program the precompiled hex
file:
<Harmony Content Path>\wireless_apps_pic32cxbz3_wbz35\apps\ble\building_blocks\HCI\wbz351_ble_uart_app\hex
. - For more details on the steps, go
to Programming A Device.Note: Ensure to choose the correct device and tool information.
Steps to programming the Application using MPLAB X IDE:
- Follow the steps mentioned in Running a Precompiled Example.
- Open and program the application:
HCI_application.X.production.x
located in<Harmony Content Path>\wireless_apps_pic32cxbz3_wbz35\apps\ble\building_blocks\HCI\wbz351_ble_uart_app\firmware
using MPLABX IDE.
For more details on how to find the Harmony Content Path, refer to Installing MCC Plugin.
Demo Description
This application example showcases the implementation of Human-Computer Interaction (HCI) capabilities. The testing phase of the application involves using a WBZ351 Curiosity Board as the host device, which is interfaced with a Linux desktop computer. Once the setup is correctly configured, communication with the BLE_UART is established through the transmission of HCI commands. This allows for the evaluation and demonstration of the application's HCI features in a controlled environment.
Developing the Application from Scratch Using the MPLAB Code Configurator
This section explains the steps required by a user to develop this application example from scratch using the MPLAB Code Configurator.
- Create a new MCC Harmony Project For more details, refer to Creating a New MCC Harmony Project.
- To setup the basic components and
configuration required to develop this application, import component configuration:
The imported file is of format
.mc3
and is located in the path<Harmony Content Path>\wireless_apps_pic32cxbz3_wbz35\apps\ble\building_blocks\peripheral\legacy_ADV_Pathloss\firmware\legacy_ADV_Pathloss.X
For more details, refer to Import existing App Example Configuration.Note: Import and export functionality of the Harmony component configuration will help users to start from a known working setup of the MCC configuration. - To accept dependencies or satisfiers, select “Yes”.
- Verify if the project graph window has all the expected configuration.
Verifying Configurations
Components Present in the Project Graph
- Select BLE_Stack component in
project graph.
- Enable BLE Controller Only option by clicking the tick on the checkbox.
- Select Systemcomponent in
project graph.
- Choose DIRECT in SERCOM0 Direct Pin Enable option.
- Select SERCOM0 component in
project graph.
- Ensure that the following configuration has done.
Verifying the DMA Configuration
- Select the drop-down symbol for the Plug-ins option and select DMA Configuration.
- Select the Channel Number DMAC
Channel 0 from the Active Channels List .
- Once you select DMAC Channel 0, the respective channel’s settings will populate the right side of the Active Channel List.
- Ensure that the settings match those shown in the following figure.
- Select the Channel Number DMAC
Channel 1 from the Active Channels List .
- Once you select DMAC Channel 1, the respective channel’s settings will populate the right side of the Active Channel List.
- Ensure that the settings match those shown in the following figure.
- Enable Run Channel in Standby Mode for DMAC Channel 0 and 1 in the System Component Configuration.
NVIC Configuration
- Click the drop-down symbol for the Plugins option and select NVIC Configuration.
- Set DMA priority as 3 for DMAC_0_3
(DMA Channel 0..3).
- Tick the enable check box.
- Set the Priority to 3.
- Set the handler name to DMAC_0_3_InterruptHandler.
PIN Configurations
- Click the drop-down symbol for the Plug-ins option and select PIN Configuration.
- Configure RA5 and RA6 as GPIO pins and set these UART Rx/Tx pins to pull high.
Generating a Code
For more details on code generation, refer to MPLAB Code Configurator (MCC) Code Generation.
Files and Routines Automatically Generated by the MCC
After generating the program source from MCC interface by clicking Generate Code, the BLE configuration can be found in the following project directories.
User Application Development
- Include
- User action is required as mentioned in User Action
definitions.h
in all the files where UART will be used to print debug informationNote: Thedefinitions.h
is not specific to just UART peripheral, instead it should be included in all application source files where peripheral functionality will be exercised.
- In the
App.h file
, reduce the msgData array size in the APP_Msg_T structure.Modify the size of msgData to 32 bytes from the default size of 256 bytes. This change is recommended because when the App task sends a message, it disables all interrupts. A smaller message size can reduce the duration of the critical section. - How to process received HCI commands and
ACL packets:
- Define the UART packet type – The HCI
MCC configuration is transport independent and requires the creation of the packet
type definition when deciding to use UART transport.
HCI Packet Type HCI Packet Indicator HCI Command Packet 0x01 HCI ACL Data Packet 0x02 HCI Synchronous Data Packet 0x03 HCI Event Packet 0x04 HCI ISO Data Packet 0x05
Example: - Define the UART packet type – The HCI
MCC configuration is transport independent and requires the creation of the packet
type definition when deciding to use UART transport.
- Parse incoming UART data to identify the
packet type and the corresponding format to determine the packet length. This is crucial
to ensure the receipt of the complete packet (refer to the Reference section for the HCI
packet format).Example of receiving a packet:
- Invoke
DMAC_ChannelTransfer()
with a block size of 4 bytes to capture the first 4 bytes, which include the packet type and header. - Verify the packet type and extract the length (note that the buffer size is currently 251 bytes; the upper byte is always 0x00, so extracting the first byte of length from the ACL packet is sufficient).
- Use
DMAC_ChannelTransfer()
again to collect the remaining data based on the length specified in the packet header. - Once a complete HCI packet is received via the UART DMA RX callback, send a message containing the command or ACL packet to the App layer.
- Depending on the packet type,
invoke
HCI_Cmd()
orHCI_AclTx()
API to pass the received packet to the controller.
- Invoke
- How to process and output HCI events and
ACL packets:
- Implement the code to output packets
via UART in the A
PP_BleStackEvtHandler()
section ofapp_ble_hci.c
File
- Implement the code to output packets
via UART in the A
- Handle HCI vendor commands by parsing and
processing them in the
APP_BleStackEvtHandler()
section ofapp_ble_hci.c
file.
Use the HCI_AppCmdComplEvt()
or HCI_AppCmdStatusEvt()
APIs
to respond to vendor commands.
Different BLE Stack Memory Configuration
There are three build option examples on how to reduce memory size if it is a concern; otherwise, use the default setting to maintain full functionality.
Feature |
Define |
Default Setting |
Common Memory Size |
Note |
Baud Rate |
---|---|---|---|---|---|
Central role high throughput |
APP_CEN_SINGLE_HIG_THROUGH |
Disable |
16KB |
ACL Tx buffer number = 12 |
921600 |
Central role low throughput |
APP_CEN_SINGLE_LOW_THROUGH |
Disable |
14KB |
ACL Tx buffer number = 4 |
115200 |
Peripheral role low throughput |
APP_PER_SINGLE_LOW_THROUGH |
Disable |
14KB |
ACL Tx buffer number = 4 |
115200 |
Full function |
Enable |
28KB |
ACL Tx buffer number = 12 |
115200 |
- The values for common memory size mentioned above are obtained from the BLE Memory Usage. If additional features are added, please refer to this section and increase the common memory size (Data memory) in initialization.c.
- When using high throughput for the
Central, set the UART baud rate to 921600; otherwise, set it to 115200 in the
plib_sercom0_usart.c
file.
Rework HCI Interface for WBZ351 Curiosity Board
Reworks Steps:
1.Remove R1 and R2.
2.Add a Jumper in R1 and R2.
3.Add an external pin for TP9 and TP10.
- When we need to input the UART data in TP9(RXD) and TP10(TXD), we need to remove R1 and R2 jumper to disconnect MCP2200.
- If we use TP9 and TP10 to input UART data and do not removing the R1 and R2 jumpers, the UART data will be affected by the MCP2200, and the data may be incorrect.
- When we need to update HEX file, we need to connect the R1 and R2 jumper.
FTDI |
WBZ351 |
VCCIO |
X |
TXD |
RX |
RXD |
TX |
RTS |
CTS |
GND |
GND |
CTS |
RTS |
References
Op_Code: Size: 2 octets
Value | Parameter Description |
---|---|
0xXXXX |
OGF Range (6 bits): 0x00-0x3F (0x3F reserved for vendor-specific debug commands) OCF Range (10 bits): 0x0000-0x03FF |
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) |
Handle: Size: 12 bits
Value | Parameter Description |
---|---|
0xXXX |
Connection_Handle to be used for transmitting a data packet or segment over a Primary Controller. Logical_Link_Handle to be used for transmitting a data packet over an AMP Controller. On the receiving side (AMP Controller to Host), the least significant 8 bits of the Handle is the Physical_Link_Handle and the most significant 4 bits are reserved. (This is because certain AMP Controllers might not be able to provide the logical link context on the receiving side, and the Host does not require it.) Range: 0x000-0xEFF (0xF00 - 0xFFF Reserved for future use) |
Value | Parameter Description | ACL-U | AMP-U | LE-U | |
---|---|---|---|---|---|
0x00 |
First non-automatically flushable packet of Higher Layer Message (start of a non- automatically flushable L2CAPPOU) from Host to Controller. Shall not be used on a BR/EOR Controller from Controller to Host. |
Host to Controller |
Allowed |
Not allowed |
Allowed |
Controller to Host |
Not allowed (except during loop- back) | Not allowed | Not allowed | ||
01 |
Continuing fragment of Higher Layer Message | Host to Controller | Allowed | Not allowed | Allowed |
Controller to Host | Allowed | Not allowed | Allowed | ||
10 | First automatically flushable packet of Higher Layer Message (start of an automatically flushable L2CAP PDU) | Host to Controller | Allowed | Not allowed | Not allowed |
Controller to Host | Allowed | Not allowed | Allowed | ||
11 | A complete L2CAP PDU. Automatically flushable | Host to Controller | Allowed | Allowed | Not allowed |
Controller to Host | Not allowed | Allowed | Not allowed |