Using BLE Demo with the NAVQ Plus Linux BSP
This application note explains how to use a BLE demo with the NAVQ Plus Linix BSP.
The NAVQ Plus Linix BSP contains several BLE demos located in the ml_ble_platform
project.
BLE demos use a similar communications protocol for sending commands and receiving responses:
Commands are sent by writing to TX characteristic with
UUID=813dd366-179e-11eb-b214-a3729d689162
and thevalue handle=0x15
;The demo responds to a command by sending notifications in RX characteristic with
UUID=89accce6-179e-11eb-a4b6-e3d7b2402624
andvalue handle=0x17
.
In this application note the ml_ble_platform/sensor_base
demo is used as an example. This application provides a platform for supporting external sensors and logging raw sample values over BLE. IMU readings are sent as notifications on ACC_SAMPLES
(UUID=110d8470-2eb3-11eb-bf0c-8ff42f5dc2bc
and value handle=0x1d
) characteristic value change. Refer to “ML_BLE_Platform BLE Interface Specification” for more information.
1. Uploading a BLE Demo to the Target
BLE demos included in the NAVQ Plus Linix BSP consist of two parts: the bootloader and a working (“mission“) firmware.
Bootloader binaries are located in the build/core_drivers_ble_v3p2/CMakeProjects/bootloader
directory:
ls -l build/core_drivers_ble_v3p2/CMakeProjects/bootloader
total 44
-rwxrwxr-x 1 user user 260 Nov 15 00:15 bootloader.bin
-rwxrwxr-x 1 user user 6080 Nov 15 00:15 bootloader.elf
drwxrwxr-x 3 user user 4096 Nov 24 19:53 CMakeFiles
-rw-rw-r-- 1 user user 1029 Nov 15 00:14 cmake_install.cmake
-rw-rw-r-- 1 user user 6260 Nov 15 00:14 Makefile
-rw-rw-r-- 1 user user 3969 Nov 15 00:15 objdump.txt
-rw-rw-r-- 1 user user 4242 Nov 15 00:15 readelf.txt
-rw-rw-r-- 1 user user 856 Nov 15 00:15 symbol.txt
Refer to Building and Running the AZ-N1 RISC-V BLE BSP for more information.
Perform the following steps to upload the demo to the target:
Sync the Telink programmer with the target:
sudo tcdb 9518 sws
Program the bootloader with the
0
offset:sudo tcdb 9518 wf 0 -i ./bootloader.bin -b
Program the demo binary with the
1000
offset:Reset the target.
2. Checking a Local Interface
Verify that a local interface is detected with
hcitool
:Follow the instructions provided in Setting up Bluetooth application note if a local interface is not detected by
hcitool
.Check a local interface status and switch it on if it is disabled:
3. Scanning for Remote Devices and Pairing
The default device name in the ml_ble_platform/sensor_base demo is AZN1-EVB. This name can be changed in the source files or by sending a command over BLE.
3.1. Scanning for Remote Devices with hcitool
Run sudo hcitool lescan
to start scanning for LE devices:
3.2. Scanning for Remote Devices and Pairing Using bluetoothctl
Open
bluetoothctl
:Scan for available remote devices with the
scan le
command:The list of remote devices can be printed using the
devices
command:Use the
pair <BD address>
command to initiate pairing:
4. Communicating with the BLE Demo
4.1. Communicating with the BLE Demo Using gatttool in an Interactive Mode
Open
gatttool
in an interactive mode:Connect to the device:
The characteristics list can be printed using the
characteristics
command:To send commands to the target, write to the TX characteristic using the
char-write-req
or thechar-write-cmd
command. A response from the demo is received as a notification on RX characteristic value change.
To read a device name send thesys device-name=?
command:To set a new name use the
sys device-name=<new name>
command.To enable IMU sample streaming send the
acc set_config
,acc stream-on
, andacc stream-on
commands:After that notifications with IMU samples are being received:
In the notification value the first 4 bytes are a timestamp, the next 2 bytes are a sequence number and the last 12 bytes are IMU samples.
4.2. Communicating with the BLE Demo Using gatttool in a Non-Interactive Mode
In a non-interactive mode gatttool
connects to the target automatically, executes a requested command, and disconnects from the target.
Use --char-write-req -a <characteristic value handle> -n <value>
to write to characteristic. Use the --listen
flag to prevent disconnecting from the target.
To read a device name execute the following command:
To enable IMU sample streaming execute the following commands:
Note: To send a command convert it to a hex-string without any quotes or the 0x prefix. Gatttool outputs also receive notification values as hex value arrays.
4.3. Useful Commands
Here are some useful commands for communicating with BLE demo:
Command | Gatttool command | Description |
---|---|---|
sys fw-ver |
| Device firmware version request |
sys device-name=? |
| Device name request |
sys log-lvl=0 |
| Set system debug output verbosity (0 - disabled, 3 - max level) |
acc log-lvl=0 |
| Set IMU debug output verbosity |
tmp log-lvl=0 |
| Set temp sensor debug output verbosity |
sys log-lvl=? |
| Current system debug output verbosity request |
acc log-lvl=? |
| Current IMU debug output verbosity request |
tmp log-lvl=? |
| Current temp sensor debug output verbosity request |
acc set_config |
| Configure IMU |
acc start |
| Enable IMU |
acc stop |
| Disable IMU |
acc stream-on |
| Enable IMU sample streaming |
acc stream-off |
| Disable IMU sample streaming |
tmp set_config |
| Configure temp sensor |
tmp start |
| Enable temp sensor |
tmp stop |
| Disable temp sensor |
tmp stream-on |
| Enable temp sensor sample streaming |
tmp stream-off |
| Disable temp sensor sample streaming |