Bluetooth: LLPM

The Bluetooth® Low Latency Packet Mode (LLPM) sample uses the GATT Latency Service and the GATT Latency Client to showcase the LLPM proprietary Bluetooth extension from Nordic Semiconductor. You can use it to determine the transmission latency of LLPM-enabled connections, or to compare with different connection parameters and check their influence on the results.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Build target

nRF52 DK

PCA10040

nrf52dk_nrf52832

nrf52dk_nrf52832

nRF52840 Dongle

PCA10059

nrf52840dongle_nrf52840

nrf52840dongle_nrf52840

nRF52840 DK

PCA10056

nrf52840dk_nrf52840

nrf52840dk_nrf52840

The sample also supports other development kits running SoftDevice Controller variants that support LLPM (see SoftDevice Controller proprietary feature support. You can use any two of the development kits mentioned above and mix different development kits.

Additionally, the sample requires a connection to a computer with a serial terminal for each of the development kits.

Overview

The LLPM is designed for applications in which the interface response time is critical for the user. For example, for virtual reality headsets or gaming mouse and keyboard.

See the following subsections for a description of the key LLPM elements.

LLPM connection interval (1 ms)

The connection interval defines how often the devices must listen on the radio. The LLPM introduces the possibility to reduce the connection interval below what is supported in Bluetooth LE. The lowest supported connection interval is 1 ms for one link.

Physical layer (PHY)

Starting with Bluetooth® 5, the over-the-air data rate in Bluetooth Low Energy supports 2 Ms/s (mega symbol per second), which allows for faster transmission. The LLPM connection interval is only supported on LE 2M PHY. Otherwise, the SoftDevice Controller will deny the request command.

QoS connection event reports

When reports are enabled, one report will be generated on every connection event. The report gives information about the quality of service of the connection event. The values in the report are used to describe the quality of links. For parameter descriptions, see sdc_hci_vs_subevent_qos_conn_event_report_t (in sdc_hci_vs.h).

Transmission latency

The definition of the latency used in this example counts the time interval from the sender’s application to the GATT service of the receiver. It demonstrates the performance of an LLPM-enabled connection that the receiver will receive the data approximately every 1 ms.

GATT Latency Service

To measure the transmission latency from application layers, a GATT Latency service BT_UUID_LATENCY is included to compute the time spent. When the sender writes its timestamp to the BT_UUID_LATENC_CHAR characteristic of the receiver, the Latency service of the receiver will automatically reply back. Whenever the sender receives a response, it will use its current time and the corresponding timestamp written before to estimate the round-trip time (RTT) of a writing characteristic procedure (see Bluetooth Core Specification: Vol 3, Part F, 3.4.5 Writing attributes).

GATT Attributes

Type

UUID

Property

Primary service

BT_UUID_LATENCY

Read only

Characteristic

BT_UUID_LATENCY_CHAR

BT_GATT_CHRC_WRITE, BT_GATT_PERM_WRITE

This sample transmits data between two development kits to measure the transmission latency in between. One of the devices is connected as a central and another is connected as a peripheral. The performance is evaluated with the transmission latency dividing the estimated round-trip time in half (RTT / 2).

By default, the following values are used to demonstrates the interaction of the connection parameters:

Default parameter values

Parameter

Value

Connection interval

80 units (100 ms)

LLPM connection interval

Lowest interval (1 ms)

Physical layer (PHY)

LE 2M PHY

Building and running

This sample can be found under samples/bluetooth/llpm in the nRF Connect SDK folder structure.

To build the sample with Visual Studio Code, follow the steps listed on the How to build an application page in the nRF Connect for VS Code extension documentation. See Building and programming an application for other building and programming scenarios and Testing and debugging an application for general information about testing and debugging in the nRF Connect SDK.

Testing

After programming the sample to both development kits, test it by performing the following steps:

  1. Connect to both kits with a terminal emulator (for example, PuTTY). See How to connect with PuTTY for the required settings.

  2. Reset both kits.

  3. In one of the terminal emulators, type “c” to start the application on the connected board in the central (tester) role.

  4. In the other terminal emulator, type “p” to start the application in the peripheral (peer) role.

  5. Observe that the kits establish a connection.

    • The central outputs the following information:

      Press any key to set LLPM short connection connection interval (1 ms)
      
    • The peripheral outputs the following information:

      Press any key to start measuring transmission latency
      
  6. Press a key in the terminal that is connected to the peripheral.

  7. Observe the terminal connected to the peripheral. The latency measurements are printed in the terminal. The latency is expected to be shorter than the default connection interval:

    Transmission Latency: 80917 (us), CRC mismatches: 0
    
  8. Press a key in the terminal that is connected to the central.

  9. Observe the connection gets updated to LLPM connection interval (1 ms) on both sides:

    Connection interval updated: LLPM (1 ms)
    
  10. Observe the terminal connected to the peripheral. The measured latency on the peripheral becomes approximate 1 ms:

    Transmission Latency: 1098 (us), CRC mismatches: 0
    
  11. Press a key in the terminal that is connected to the central.

  12. Observe the terminal connected to the central. The measured latency on the central remains approximate 1 ms:

    Transmission Latency: 1235 (us), CRC mismatches: 0
    

msc {
hscale = "1.3";
Central,Peripheral;
Central<<=>>Peripheral      [label="Connected"];
Central<<=>>Peripheral      [label="Discovered GATT Latency Service"];
Peripheral note Peripheral  [label="Press any key to start measuring transmission latency"];
Peripheral note Peripheral  [label="Read current timestamp: s1"];
Peripheral=>Central         [label="Write Request (timestamp: s1)"];
Central>>Peripheral         [label="Write Response"];
Peripheral note Peripheral  [label="Read current timestamp: s2"];
Peripheral note Peripheral  [label="Latency = (s2 - s1) / 2"];
Central note Central        [label="Press any key to set LLPM short connection connection interval (1 ms)"];
Central<<=>>Peripheral      [label="Switched to LLPM connection interval"];
Central note Central        [label="Press any key to start measuring transmission latency"];
Central note Central        [label="Read current timestamp: m1"];
Central=>Peripheral         [label="Write Request (timestamp: m1)"];
Peripheral>>Central         [label="Write Response"];
Central note Central        [label="Read current timestamp: m2"];
Central note Central        [label="Latency = (m2 - m1) / 2"];
}

Sample output

The result should look similar to the following output.

  • For the central:

    ***** Booting Zephyr OS build v1.14.99-ncs3-snapshot2-2647-gd6e67554cfeb *****
    Bluetooth initialized
    LLPM mode enabled
    Choose device role - type c (central) or p (peripheral): c
    Central. Starting scanning
    Scanning successfully started
    Connection event reports enabled
    Filter not match. Address: 08:c6:a4:e0:72:e9 (random) connectable: 0
    Filter not match. Address: 13:04:eb:f1:0b:46 (random) connectable: 0
    Filter not match. Address: 2b:74:72:c3:8f:a8 (random) connectable: 0
    Filter not match. Address: 02:ec:f9:bb:ec:27 (random) connectable: 0
    Filter not match. Address: 01:54:cf:d4:31:cd (random) connectable: 0
    Filter not match. Address: 3e:21:91:91:52:82 (random) connectable: 0
    Filter not match. Address: 08:c6:a4:e0:72:e9 (random) connectable: 0
    Filter not match. Address: 37:63:6a:ed:38:e2 (random) connectable: 0
    Filter not match. Address: 56:c6:75:17:80:d8 (random) connectable: 1
    Filters matched. Address: f9:3c:9c:d1:f6:07 (random) connectable: 1
    Connected as central
    Conn. interval is 80 units (1.25 ms/unit)
    Service discovery completed
    Press any key to set LLPM short connection interval (1 ms)
    Press any key to start measuring transmission latency
    Connection interval updated: LLPM (1 ms)
    Transmission Latency: 1235 (us), CRC mismatches: 0
    Transmission Latency: 1007 (us), CRC mismatches: 0
    Transmission Latency: 1434 (us), CRC mismatches: 0
    Transmission Latency: 1312 (us), CRC mismatches: 0
    Transmission Latency: 1220 (us), CRC mismatches: 0
    Transmission Latency: 991 (us), CRC mismatches: 0
    Transmission Latency: 1419 (us), CRC mismatches: 0
    Transmission Latency: 1281 (us), CRC mismatches: 0
    Transmission Latency: 1052 (us), CRC mismatches: 0
    Transmission Latency: 991 (us), CRC mismatches: 0
    Transmission Latency: 1403 (us), CRC mismatches: 0
    Transmission Latency: 1296 (us), CRC mismatches: 0
    Transmission Latency: 1052 (us), CRC mismatches: 0
    Transmission Latency: 976 (us), CRC mismatches: 0
    Transmission Latency: 1358 (us), CRC mismatches: 0
    Transmission Latency: 1281 (us), CRC mismatches: 0
    Transmission Latency: 1052 (us), CRC mismatches: 0
    Transmission Latency: 976 (us), CRC mismatches: 0
    Transmission Latency: 1358 (us), CRC mismatches: 0
    Transmission Latency: 1281 (us), CRC mismatches: 0
    Transmission Latency: 1052 (us), CRC mismatches: 0
    Transmission Latency: 976 (us), CRC mismatches: 0
    Transmission Latency: 1358 (us), CRC mismatches: 0
    Transmission Latency: 1281 (us), CRC mismatches: 0
    
  • For the peripheral:

    ***** Booting Zephyr OS build v1.14.99-ncs3-snapshot2-2647-gd6e67554cfeb *****
    Bluetooth initialized
    LLPM mode enabled
    Choose device role - type c (central) or p (peripheral): p
    Slave role. Starting advertising
    Advertising successfully started
    Connection event reports enabled
    Filter not match. Address: 1d:18:b1:84:fd:05 (random) connectable: 0
    Filter not match. Address: 00:92:3f:a6:3f:48 (random) connectable: 0
    Filter not match. Address: 02:ec:f9:bb:ec:27 (random) connectable: 0
    Filter not match. Address: 3e:21:91:91:52:82 (random) connectable: 0
    Filter not match. Address: 08:c6:a4:e0:72:e9 (random) connectable: 0
    Filter not match. Address: 13:04:eb:f1:0b:46 (random) connectable: 0
    Filter not match. Address: cb:01:1a:2d:6e:ae (random) connectable: 1
    Filter not match. Address: 5c:f2:70:c2:3f:9f (random) connectable: 1
    Connected as peripheral
    Conn. interval is 80 units (1.25 ms/unit)
    Service discovery completed
    Press any key to start measuring transmission latency
    Transmission Latency: 80917 (us), CRC mismatches: 0
    Transmission Latency: 80841 (us), CRC mismatches: 0
    Transmission Latency: 80749 (us), CRC mismatches: 0
    Transmission Latency: 80673 (us), CRC mismatches: 0
    Transmission Latency: 80596 (us), CRC mismatches: 0
    Transmission Latency: 80505 (us), CRC mismatches: 0
    Transmission Latency: 80429 (us), CRC mismatches: 0
    Transmission Latency: 80337 (us), CRC mismatches: 0
    Transmission Latency: 80261 (us), CRC mismatches: 0
    Transmission Latency: 80184 (us), CRC mismatches: 0
    Transmission Latency: 80093 (us), CRC mismatches: 0
    Transmission Latency: 80017 (us), CRC mismatches: 0
    Transmission Latency: 79940 (us), CRC mismatches: 0
    Transmission Latency: 79849 (us), CRC mismatches: 0
    Connection interval updated: LLPM (1 ms)
    Transmission Latency: 81604 (us), CRC mismatches: 0
    Transmission Latency: 30181 (us), CRC mismatches: 0
    Transmission Latency: 1098 (us), CRC mismatches: 0
    Transmission Latency: 1129 (us), CRC mismatches: 0
    Transmission Latency: 1037 (us), CRC mismatches: 0
    Transmission Latency: 930 (us), CRC mismatches: 0
    Transmission Latency: 1312 (us), CRC mismatches: 0
    Transmission Latency: 1083 (us), CRC mismatches: 0
    Transmission Latency: 1007 (us), CRC mismatches: 0
    

Dependencies

This sample uses the following nRF Connect SDK libraries:

This sample uses the following sdk-nrfxlib libraries:

In addition, it uses the following Zephyr libraries:

  • include/console.h

  • Kernel Services:

    • include/kernel.h

  • include/sys/printk.h

  • include/zephyr/types.h

  • Bluetooth APIs:

    • include/bluetooth/bluetooth.h

    • include/bluetooth/conn.h

    • include/bluetooth/gatt.h

    • include/bluetooth/hci.h

    • include/bluetooth/uuid.h

    • include/bluetooth/scan.h

    • include/bluetooth/gatt_dm.h

References

For more information about the connection parameters that are used in this sample, see the following chapters of the Bluetooth Core Specification:

  • Vol 3, Part F, 3.4.5 Writing attributes

  • Vol 3, Part G, 4.9.3 Write Characteristic Value

  • Vol 6, Part B, 5.1.1 Connection Update Procedure

  • Vol 6, Part B, 5.1.10 PHY Update Procedure