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 |
---|
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 | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
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 | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
- SWITCH characteristic:
- Used to switch LED or lamp on collector device.
Peer to Peer service - SWITCH characteristic | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
Example of flow diagram between ST67W611M & ST BLE Toolbox |
---|
3.2. Advertising data
At startup, Peer To Peer server application starts advertising.
Data advertised are composed as follows:
P2P server advertising packet | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Manufacturer data are encoded following STMicroelectronics BlueST SDK v2 as described below:
STMicroelectronics manufacturer advertising data | |||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
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 |
---|
3.4. On-board button configuration
Buttons configuration for Bluetooth® LE P2P application on ST67W611M boards | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
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 |
---|
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 | ||
---|---|---|
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® |
---|
Once connected, click on the Wi-Fi commissioning button to open the commissioning dedicated 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.
The picture below shows the middleware ST67W6X_Network_Driver read-only memory (flash) used by the Bluetooth® LE P2P client application.
The picture below shows the sum of the Read Only memory (flash) of the Bluetooth® LE P2P server application.
The picture below shows the middleware ST67W6X_Network_Driver read-only memory (flash) used by the Bluetooth® LE P2P server application.
4.6.2. Read Write (RW) memory footprint
The picture below shows only the sum of the static read/write memory (static RAM) of the Bluetooth® LE P2P client application.
The picture below shows only the sum of the static read/write memory (static RAM) of the Bluetooth® LE P2P server application.
5. References