| Back to main page |
|---|
1. Bluetooth® Low Energy P2P presentation
Bluetooth® Low Energy Peer to Peer server and Peer to Peer client applications aim to demonstrate a direct Bluetooth® Low Energy connection between two devices, based on STMicroelectronics proprietary service and characteristics.
These two projects are provided within the ST67W611M1 Firmware Package.
The client device interfacing with the Bluetooth® Low Energy Peer to Peer server can be an ST67W611M1 platform running the Bluetooth® Low Energy Peer to Peer client application, but also a smartphone with the ST BLE Toolbox Android/iOS application or a laptop with the Web Bluetooth® interface.
| Bluetooth® Low Energy Peer to Peer & ST67W611M1 solution overview |
|---|
2. Requirements
2.1. Software and system requirements
The software requirements are as follows (minimum IDE versions):
- STM32CubeIDE toolchain V2.1.0 [1].
- IAR Embedded Workbench for Arm (EWARM) toolchain V9.30.1
- RealView Microcontroller Development Kit (MDK-ARM) toolchain V5.39
Programmer:
- STM32CubeProgrammer [2] to program the board with a pre-generated binary file
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 further 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 into 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 in external interrupt mode due to a conflict with another EXTI pin requirement. The button must be defined with the user label USER_BUTTON and EXTI falling mode.
2.3. Collector compatible applications
The ST67W611M1 Bluetooth® Low Energy Peer To Peer server project is compatible with the following collectors:
3. Bluetooth® Low Energy Peer to Peer profile
The Bluetooth® Low Energy Peer to Peer profile is a Generic Attribute Profile (GATT) based low-energy profile defined by STMicroelectronics with proprietary UUIDs (128 bits).
The Bluetooth® Low Energy Peer to Peer profile, widely used for direct connections, defines communication between the GATT server of a Bluetooth® Low Energy Peer to Peer server device and a GATT client collector device, such as a smartphone, a laptop with the Web Bluetooth® Interface[4], or an ST67W611M1 Bluetooth® Low Energy Peer to Peer client device.
The Bluetooth® Low Energy Peer to Peer server:
- Contains the Bluetooth® Low Energy 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 Bluetooth® Low Energy Peer to Peer server, controls it with the write characteristics, receives notifications from it
- Is the GATT client
3.1. ST67W611M1 Bluetooth® Low Energy Peer to Peer Server
The table below describes the structure of the Bluetooth® Low Energy Peer to Peer service:
| Bluetooth® Low Energy Peer to Peer service specification | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Bluetooth® Low Energy Peer To Peer Server is exposed as a service.
- LED characteristic:
- Used to control LED2 (Blue) on the ST67W611M1 platform from a remote device.
| Bluetooth® Low Energy Peer to Peer service
LED Characteristic | |||||||||
|---|---|---|---|---|---|---|---|---|---|
|
- SWITCH characteristic:
- Used to switch the LED or lamp on the collector device.
| Bluetooth® Low Energy Peer to Peer service
SWITCH characteristic | |||||||||
|---|---|---|---|---|---|---|---|---|---|
|
| Example of flow diagram between ST67W611M1 & ST BLE Toolbox |
|---|
3.2. Advertising data
At startup, the Bluetooth® Low Energy Peer To Peer server application starts advertising.
The advertised data is composed as follows:
| Bluetooth® Low Energy P2P server advertising packet | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Manufacturer data are encoded following STMicroelectronics BlueST SDK v2 as described below:
| STMicroelectronics manufacturer advertising data | |||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
3.3. ST67W611M1 Bluetooth® Low Energy Peer to Peer Client
It acts as a central device with support from the GATT client layer.
At startup, when the SW1 USER button is pressed, the Peer To Peer client application:
- Starts scanning to detect a Bluetooth® Low Energy Peer To Peer server application by filtering the device name in the advertising data
- Stops scanning once a Bluetooth® Low Energy P2P server is detected
- Connects to the remote Bluetooth® Low Energy P2P server to establish the connection
- Discovers the GATT service and characteristics of the Bluetooth® Low Energy P2P server
- Enables all GATT server notification characteristics
Once connected, the Peer To Peer client application:
- Writes a message to toggle the green LED of the Bluetooth® Low Energy P2P server (by pressing the SW1 USER button)
- Receives a notification to toggle the on-board green LED from the remote Bluetooth® Low Energy P2P server application
| Example of flow diagram between Bluetooth® Low Energy P2P server & Bluetooth® Low Energy P2P client |
|---|
3.4. On-board button configuration
| Buttons configuration for Bluetooth® Low Energy P2P application on ST67W611M1 boards | |||||||||
|---|---|---|---|---|---|---|---|---|---|
|
4. ST67W611M1 Bluetooth® Low Energy P2P server and Bluetooth® Low Energy P2P client application
4.1. Project directory
The "ST67W6X_BLE_p2pServer" and "ST67W6X_BLE_p2pClient" applications are available by downloading the X-CUBE-ST67W61 Expansion Package.
Refer to the Project directory wiki page for project directory information.
4.2. Project description
The Bluetooth® Low Energy P2P server application acts as a peripheral device embedding the STMicroelectronics proprietary Bluetooth® Low Energy Peer to Peer profile and its two characteristics. At startup, the application starts advertising.
One of the three available client solutions must be used to scan and connect to the Bluetooth® Low Energy P2P server application:
Bluetooth® Low Energy P2P server VS smartphone
Once the Bluetooth® Low Energy P2P server application is installed on the ST67W611M1 platform, launch ST BLE Toolbox smartphone application.
Then, scan for and connect the device called p2pS_XX (where XX is replaced by the last byte of the BD address) from the application.
Once the Bluetooth® Low Energy connection is established and the notification is enabled by the smartphone (by clicking on P2P server icon):
- The LED_C value can be modified by clicking the LED button on the smartphone interface; the green LED on the board is switched on/off accordingly.
- Pressing the 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.
- Pressing the USER button on the board while not connected clears the bonded device list of the platform.
Bluetooth® Low Energy P2P server VS Bluetooth® Low Energy P2P client
At least two platforms are required, one flashed with the Bluetooth® Low Energy P2P server application and one with the Bluetooth® Low Energy P2P client application.
- On the Bluetooth® Low Energy P2P client side:
- Pressing the USER button on the Bluetooth® Low Energy P2P client platform while not connected starts a scan procedure, and a connection is established if a Bluetooth® Low Energy P2P server platform is found.
- Pressing the USER button on the Bluetooth® Low Energy P2P client platform while connected sends a GATT event to the Bluetooth® Low Energy P2P server platform to switch the server green LED on/off.
- On the Bluetooth® Low Energy P2P server side:
- Pressing the USER button on the Bluetooth® Low Energy P2P server side while connected sends a SWITCH_C notification to the Bluetooth® Low Energy P2P client platform and toggles the green LED on the client side.
- Pressing the USER button on the board while not connected clears the bonded device list of the platform.
Bluetooth® Low Energy P2P server VS Web Bluetooth® Interface
Open ST Web Bluetooth® Interface
from a laptop or a smartphone with a Bluetooth® Low Energy connection activated.
Then, scan for and connect the device called p2pS_XX (where XX is replaced by the last byte of the BD address) from the application.
Once the Bluetooth® Low Energy connection is established and notifications are enabled by the Web Bluetooth® Interface (by clicking on the Bluetooth® Low Energy P2P server icon),
enable notifications by clicking the Notify OFF button.
- The LED_C value can be modified by clicking the Light OFF/ON button on the interface; the green LED on the board is switched on/off accordingly.
- Pressing the 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).
- Pressing the USER button on the board while not connected clears the bonded device list of the platform.
4.3. Project structure
Software project structure with the most important parts:
| p2pServer and p2pClient project structures |
|---|
API descriptions are available on the following page: X-CUBE-ST67W61 Architecture.
4.4. Build and Install
Refer to build and load chapter for details on how to build and download the software onto the device.
4.5. User setup
4.5.1. ST67W6X default configuration
The default System configuration can be modified in "ST67W6X/Target/w6x_config.h":
/** NCP power save mode : 0: NCP stays always active / 1: NCP goes in low power mode when idle */ #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
Note: An external clock oscillator must be used to support Bluetooth® Low Energy in low-power mode. If W6X_POWER_SAVE_AUTO is set to 1 but the clock mode is not correct, the W6X_Ble_Init() API disables low-power mode.
The default Bluetooth® Low Energy configuration can be modified in the "ST67W6X/Target/w6x_config.h" file:
/** Bluetooth® Low Energy advertising name */ #define W6X_BLE_NAME "p2pS"
The AT driver can be configured in "ST67W6X/Target/w61_driver_config.h":
/** Maximum number of detected peripheral during the scan. Cannot be greater than 50 */ #define W61_BLE_MAX_DETECTED_PERIPHERAL 10 /** Enable/Disable BLE module logging */ #define BLE_LOG_ENABLE 1 /** Maximum SPI buffer size */ #define W61_MAX_SPI_XFER 1520 /** Debugging only: Enable AT log, i.e. logs the AT commands incoming/outcoming from/to the NCP */ #define W61_AT_LOG_ENABLE 0 /** Enable/Disable System module logging */ #define SYS_LOG_ENABLE 1
Additionally, some other options can be modified in the "ST67W6X/Target" directory using different configuration files, as outlined 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 the 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 provided in the template directory "Middlewares/ST/ST67W6X_Network_Driver/Conf"
4.5.2. Application configuration
The logging output mode can be modified in "Appli/App/app_config.h":
/** Select output log mode [0: printf / 1: UART / 2: ITM] */ #define LOG_OUTPUT_MODE LOG_OUTPUT_UART
The host low-power mode can be modified in "Appli/App/app_config.h":
/** Low power configuration [0: disable / 1: sleep / 2: stop / 3: standby] */ #define LOW_POWER_MODE LOW_POWER_SLEEP_ENABLE
The host debugger pins can be modified in "Appli/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.6. Bluetooth® Low Energy P2P client solutions
4.6.1. ST BLE ToolBox application
Once the Bluetooth® Low Energy P2P server application is installed on the ST67W611M1 + STM32U5 platform, launch the ST BLE ToolBox smartphone application. The application starts scanning and allows you to view advertisement data or connect to the device. Once the device is connected, an interface allows you to switch the platform green LED on/off, and a notification reflects the Switch_C characteristic status.
| Bluetooth® Low Energy P2P application on ST BLE ToolBox | ||
|---|---|---|
4.6.2. Web Bluetooth® Interface
In order to interface with the embedded Bluetooth® Low Energy Peer to Peer server application, a web interface has been developed by STMicroelectronics and is available at the following link ST Web Bluetooth® Interface, accessible from a computer, tablet, or smartphone.
Enable the Bluetooth® connection of the device, click on "Connect" button and select p2pS_[...] device:
| Connection from Web Bluetooth® |
|---|
Once connected, click on the P2P Server button to open the Peer to Peer dedicated interface:
| Bluetooth® Low Energy P2P server interface |
|---|
Access P2P Server interface by clicking (1).
Once the P2P Server interface is opened, click on (2) to switch the green LED of the board on/off; the LED status is also displayed in (3). (4) allows enabling/disabling SWITCH characteristic notifications. If notifications are enabled, (5) reflects the SWITCH characteristic status. This status changes when the USER button on the platform is pressed.
4.6.3. Bluetooth® Low Energy P2P client embedded application
At startup, start a scan by pressing the USER button on the Bluetooth® Low Energy Peer To Peer client platform.
If a Bluetooth® Low Energy Peer to Peer server device is detected, the client initiates the connection, then starts the service and characteristic discovery process, and identifies the Bluetooth® Low Energy Peer to Peer service and its characteristics by their UUIDs.
Once connected, the Bluetooth® Low Energy Peer To Peer client application:
- By pressing the SW1 USER button, writes a message to toggle the green LED of the Bluetooth® Low Energy P2P server
- Receives a notification to toggle the on-board green LED from the remote Bluetooth® Low Energy P2P server application
If no Bluetooth® Low Energy Peer to Peer server is connected, relaunch a scan by pressing the USER button.
4.7. 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® Low Energy 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 future releases.
4.7.1. ROM/Flash memory footprint
The picture below shows the sum of the read-only memory (flash) of the Bluetooth® Low Energy P2P applications.
The picture below shows the middleware ST67W6X_Network_Driver read-only memory (flash) used by the Bluetooth® Low Energy P2P applications.
4.7.2. Read Write (RW) memory footprint
The picture below shows only the sum of the static read/write memory (static RAM) of the Bluetooth® Low Energy P2P applications.
5. References