ST67W611M Bluetooth® LE – Peer 2 Peer Applications

back to main page

1. Bluetooth® LE P2P presentation

Peer to Peer server and Peer to Peer client applications aim to demonstrate Bluetooth® LE direct connection between two devices, based on STMicroelectronics proprietary service and characteristics.
These two projects are provided within the ST67W611M Firmware Package.

The client device interfacing with the Peer to Peer server can be a ST67W611M platform with Peer to Peer client application, but also a smartphone with ST BLE Toolbox Android/iOS application or a laptop with Web Bluetooth interface.

Bluetooth® LE Peer to Peer & ST67W611M solution overview
ST67W6X P2P Profile


2. Requirements

2.1. Software and system requirements

The software required are the following (minimum IDEs version):

  • STM32CubeIDE toolchain V1.18.1 [1].
  • IAR Embedded Workbench for ARM (EWARM) toolchain V9.30.1
  • RealView Microcontroller Development Kit (MDK-ARM) toolchain V5.39

Programmer:

  • STM32CubeProgrammer [2] : To flash the board with an already generated binary

HyperTerminal:

  • Use the application through the serial link
  • Open a HyperTerminal client connected to the Host ST-LINK COM port

The serial COM port must be configured as shown below:

Baudrate 921600
Data 8b
Stopbit 1b
Parity None
Flow control None
Rx LF
Tx LF
Local Echo Off

For more details, refer to the HyperTerminal setup page.

2.2. Hardware requirements

This example runs on the NUCLEO-U575ZI-Q [3] board combined with the X-NUCLEO-67W61M1 board.

The X-NUCLEO-67W61M1 board is plugged to the NUCLEO-U575ZI-Q board via the Arduino® connectors:

  • The 5V, 3V3, GND through the CN6
  • The SPI (CLK, MOSI, MISO), SPI_CS and USER_BUTTON signals through the CN5
  • The BOOT, CHIP_EN, SPI_RDY and UART TX/RX signals through the CN9

The USER_BUTTON refers to the button mounted on the X-NUCLEO-67W61M1. Indeed, the user button on the STM32 Nucleo board is not used as an external interrupt mode due to conflict with other EXTI pin requirement. The button must be defined with the user label USER_BUTTON and EXTI falling mode.

2.3. Collector compatible applications

The ST67W611M Peer To Peer server project is compatible with the following collector:

3. Peer to Peer profile

The Peer to Peer profile is a Generic Attribute Profile (GATT) based low-energy profile defined by STMicroelectronics with proprietary UUIDs (128 bits).
The Peer to Peer profile, widely used for direct connection, defines the communication between a GATT-server of a Peer to Peer server device, and a GATT-client collector device, such as a smartphone, a laptop with Web Bluetooth Interface[4], ST67W611M Peer to Peer client device.

The Peer to Peer server:
  • Contains the P2P service, which exposes two characteristics (notification and write) in order to create a bi-directional data communication
  • Is the GATT server
The collector:
  • Accesses the information exposed by the Peer to Peer server, controls it with the write characteristics, receives notifications from it
  • Is the GATT client

3.1. ST67W611M Peer to Peer server

The table below describes the structure of Peer to Peer service:

Bluetooth® LE Peer to Peer service specification
Service Characteristic Mode UUID size
P2P Service 0000FE40-cc7a-482a-984a-7f2ed5b3e58f
LED Write without Response/Read 0000FE41-8e22-4541-9d4c-21edae82ed19 2
SWITCH Notify 0000FE42-8e22-4541-9d4c-21edae82ed19 2

Peer To Peer server is exported as a service.

  • LED characteristic:
    • Used to control LED2 (Blue) on ST67W611M platform by remote device.
Peer to Peer service - LED Characteristic
Byte Index 0 1
Name LED Selection LED Level
Value 0x01: Blue LED 0x00: LED off
0x01: LED on
  • SWITCH characteristic:
    • Used to switch LED or lamp on collector device.
Peer to Peer service - SWITCH characteristic
Byte Index 0 1
Name Button Selection Status
Value 0x01: USER button 0x00 or 0x01


Example of flow diagram between ST67W611M & ST BLE Toolbox
ST67W611M P2P Flow Diagram


3.2. Advertising data

At startup, Peer To Peer server application starts advertising.
Data advertised are composed as follows:

P2P server advertising packet
Description Length AD Type Value
Device Name 8 0x09 p2pS_XX (XX: last byte of BD address)
Manufacturer Data 15 0xFF See table below
Flags 2 0x01 0x06
(GeneralDiscoverable, BrEdrNotSupported)


Manufacturer data are encoded following STMicroelectronics BlueST SDK v2 as described below:

STMicroelectronics manufacturer advertising data
Byte Index 0 1 2-3 4 5 6 7 8 9 10-15
Function Length Manufacturer ID Company BlueST SDK Version Device ID Firmware ID Option 1 Option 2 Option 3 Device Address
Value 0x0F 0xFF 0x0030 STMicro 0x02 0x9A - ST67W611 0x83 - P2P Server 0x00 0x00 0x00 0xXXXXXXXXXXXX

3.3. ST67W611M Peer to Peer client

It acts as a central device with the support of GATT client layer.
At startup, by pressing the SW1 USER button, the Peer To Peer client application:

  • Starts scanning to detect the Peer To Peer server application by filtering the device name in the advertising data
  • Stops scanning once the P2P server is detected
  • Connects to the P2P server to establish the connection
  • Discovers GATT service and characteristics of the P2P server
  • Enables all GATT server notification characteristics

Once connected, the Peer To Peer client application:

  • Writes a message to toggle the blue LED of the P2P server (by pressing SW1 USER button)
  • Receives notification to toggle the on-board blue LED from the remote P2P server application
Example of flow diagram between P2P server & P2P client
Peer 2 Peer Flow Diagram


3.4. On-board button configuration

Buttons configuration for Bluetooth® LE
P2P application on ST67W611M boards
Application Condition SW1 User Button Click
P2P Server Idle

Connected

/

Notification

P2P Client Idle

Connected

Start Scan

Write Char

4. ST67W61 P2P server and P2P client application

4.1. Application description

P2P server application acts as a peripheral device embedding the Peer to Peer STMicroelectronics proprietary profile and its two characteristics. At startup, the application starts to advertise.

One of the three available client solutions must be used to scan and connect to the Peer to Peer server application:

P2P server VS smartphone
Once the BLE P2P server application is installed on the ST67W611M platform, launch ST BLE Toolbox smartphone application.

Then, scan and connect the device called p2pS_XX (where XX is replaced by the last byte of the BD address) to the application.
Once the Bluetooth® LE connection is established and the notification is enabled by the smartphone (by clicking on P2P server icon):

  • LED_C value can be modified by clicking on the LED button on smartphone interface, the blue LED of the board is switched On/Off accordingly.
  • Pressing USER button on the board while connected sends a SWITCH_C notification to the smartphone and the switch level is updated on the smartphone interface.

P2P server VS P2P client
At least two platforms are required, one flashed with the BLE P2P server application and one with the BLE P2P client application.

  • On P2P the client side:
    • Pressing USER button on the P2P client platform while not connected, starts a scan procedure, and connection is done if a P2P server platform is found.
    • Pressing USER button on the P2P client platform while connected, sends a GATT event to the P2P server platform in order to switch On/Off the server blue LED.
  • On the P2P server side:
    • Pressing USER button on the P2P server side while connected sends a SWITCH_C notification to the P2P client platform and toggles the blue LED on the client side.


P2P server VS Web Bluetooth Interface
Open ST Web Bluetooth® Interface
from a laptop or a smartphone with a Bluetooth® LE connection activated.

Then, scan and connect the device called p2pS_XX (where XX is replaced by the last byte of the BD address) to the application.
Once the Bluetooth® LE connection is established and the notification is enabled by the Web Bluetooth Interface (by clicking on the P2P server icon), enable notifications by clicking on Notify OFF button.

  • LED_C value can be modified by clicking on the Light OFF/ON button on the interface, the blue LED of the board is switched On/Off accordingly.
  • Pressing USER button on the board while connected sends a SWITCH_C notification to the interface and the switch level is updated on the interface (if notifications have been enabled).

4.2. Project structure

Software project structure with the most important parts:

p2pServer and p2pClient project structures
p2pServer Client Architecture


API descriptions are available in the following page: X-CUBE-ST67W61 Architecture.

4.3. Build and Install

Refer to build and install chapter to details on how to build and download on the device.

4.4. User setup

4.4.1. ST67W6X default configuration

The default System configuration can be modified in "ST67W6X/Target/w6x_config.h":

/** NCP will go by default in low power mode when NCP is in idle mode */
#define W6X_POWER_SAVE_AUTO                     0

/** NCP clock mode : 1: Internal RC oscillator, 2: External passive crystal, 3: External active crystal */
#define W6X_CLOCK_MODE                          1

The default Bluetooth® LE configuration can be modified in the "ST67W6X/Target/w6x_config.h" file:

/** Bluetooth® LE advertising name */
#define W6X_BLE_NAME                            "p2pS"

The AT driver can be configured in "ST67W6X\Target\w61_driver_config.h":

/** Maximum number of BLE connections */
#define W61_BLE_MAX_CONN_NBR                    1

/** Maximum number of BLE services */
#define W61_BLE_MAX_SERVICE_NBR                 5

/** Maximum number of BLE characteristics per service */
#define W61_BLE_MAX_CHAR_NBR                    5

/** Maximum number of detected peripheral during the scan. Cannot be greater than 50 */
#define W61_BLE_MAX_DETECTED_PERIPHERAL         10

/** Debugging only: Enable AT log, i.e. logs the AT commands incoming/outcoming from/to the NCP */
#define W61_AT_LOG_ENABLE                       0

Additionally, some other options can be modified in the "ST67W6X/Target" directory with different configuration files as below:

  • logging_config.h: This file provides configuration for the logging component to set the log level.
  • shell_config.h: This file provides configuration for shell component.
  • w6x_config.h: This file provides configuration for the W6X APIs (used during init).
  • w61_driver_config.h: This file provides configuration for the W61 configuration module.

All available defines are available in template directory "Middlewares/ST/ST67W6X_Network_Driver/Conf"

4.4.2. Application configuration

The logging output mode can be modified in "App_BLE_p2p*/App/app_config.h":

/** Select output log mode [0: printf / 1: UART / 2: ITM] */
#define LOG_OUTPUT_MODE             1

The host low-power mode can be modified in "App_BLE_p2p*/App/app_config.h":

/** Low power configuration [0: disable / 1: sleep / 2: stop / 3: standby] */
#define LOW_POWER_MODE              1

The host debugger pins can be modified in "App_BLE_p2p*/App/app_config.h":

/**
* Enable/Disable MCU Debugger pins (dbg serial wires)
* @note by HW serial wires are ON by default, need to put them OFF to save power
*/
#define DEBUGGER_ENABLED            1

4.5. P2P client solutions

4.5.1. ST BLE Toolbox application

Once the BLE P2P server application is installed on the ST67W611 + STM32-U5 platform, launch the ST BLE Toolbox smartphone application. The application starts scanning and allows to see advertisement data or to connect to the device. Once the device is connected, an interface allows to switch On/Off the blue LED of the platform, and a notification reflects the Switch_C characteristic status.

BLE P2P application on ST BLE ToolBox
Connectivity WBA P2P Toolbox scan.jpg
Connectivity WBA P2P Toolbox adv.jpg
Connectivity WBA P2P Toolbox connected.jpg


4.5.2. Web Bluetooth Interface

In order to interface with the Peer to Peer server embedded application, a web interface has been developed by STMicroelectronics and is available at the following link ST Web Bluetooth® Interface accessible from computer, table or smartphone.

Enable the Bluetooth® connection of the device and click on the connect button:

Connection from Web Bluetooth®
Connection from Web Bluetooth®

Once connected, click on the Wi-Fi commissioning button to open the commissioning dedicated interface:

P2P server interface
P2P Server interface


Access P2P server interface by clicking (1).

Once the P2P server interface is opened, click on (2) to switch On/Off the blue LED of the board, the status of the LED is also displayed in (3). (4) allows enabling/disabling SWITCH characteristic notifications. If the notifications are enabled, (5) reflects the SWITCH characteristic status. This status changes by clicking on USER button of the platform.

4.5.3. P2P client embedded application

At startup, start a scan by pressing USER button of the Peer To Peer client plateform. Once a Peer to Peer server is detected, the client initiates the connection with it.

Once connected, the Peer To Peer client application:

  • By pressing SW1 USER button, write a message to toggle the blue LED of the P2P server
  • Receive notification to toggle the on-board blue LED from remote P2P server application

If no Peer to Peer server is connected, relaunch a scan by pressing the USER button.

4.6. Memory footprint

Module Description
[Driver] HAL/CMSIS/BSP STM32 CMSIS Cortex, HAL and LL, Board Specific Package drivers
[Project] Core Native STM32 core components
[Project] App Main part of the application
[Project] Target Configuration files for ST67W6X_Network_Driver component
[MW] ST67W6X_Network_Driver Core and API System and Bluetooth® LE components
Util/Logging: Utility to process shell and trace messages onto the UART interface (can be changed by ITM)
[MW] FreeRTOS FreeRTOS kernel source
[Utility] lpm Tiny Low-Power Management
[Toolchain] Startup Int_vect, init routines, init table, CSTACK and HEAP
[Toolchain] EWARM Libraries Native compiler libraries

These values depend on the chosen toolset, and they can change in next releases.

4.6.1. ROM/Flash memory footprint

The picture below shows the sum of the Read Only memory (flash) of the Bluetooth® LE P2P client application.

ST67W6X_BLE_p2pClient Read Only memory footprint.

The picture below shows the middleware ST67W6X_Network_Driver read-only memory (flash) used by the Bluetooth® LE P2P client application.

ST67W6X_Network_Driver Read Only memory footprint used by ST67W6X_BLE_p2pClient application.

The picture below shows the sum of the Read Only memory (flash) of the Bluetooth® LE P2P server application.

ST67W6X_BLE_p2pServer Read Only memory footprint.

The picture below shows the middleware ST67W6X_Network_Driver read-only memory (flash) used by the Bluetooth® LE P2P server application.

ST67W6X_Network_Driver Read Only memory footprint used by ST67W6X_BLE_p2pServer application.

4.6.2. Read Write (RW) memory footprint

Info white.png Information
The FreeRTOS Heap is not part of the below chart.
The dynamic memory allocation adds 200'000 bytes (value set for the TOTAL_HEAP_SIZE FreeRTOS parameter).

The ST67W6X_BLE_p2pClient project uses only 30kb and the ST67W6X_BLE_p2pServer uses only 24kb of the heap. Refer to Dynamic memory overview wiki page.

The picture below shows only the sum of the static read/write memory (static RAM) of the Bluetooth® LE P2P client application.

ST67W6X_BLE_p2pClient Read Write memory footprint

The picture below shows only the sum of the static read/write memory (static RAM) of the Bluetooth® LE P2P server application.

ST67W6X_BLE_p2pServer Read Write memory footprint

5. References