UM2666
User manual
Getting started with the X-CUBE-BLE2 Bluetooth Low Energy software expansion for STM32Cube
Introduction
The X-CUBE-BLE2 expansion software package for STM32Cube runs on the STM32 and includes drivers for BlueNRG-2and BlueNRG-2N Bluetooth® low energy devices.
The expansion is built on STM32Cube software technology to ease portability across different STM32 microcontrollers.
The software comes with sample implementations of the drivers running on the X-NUCLEO-BNRG2A1 when connected to a NUCLEO-L476RG board.
RELATED LINKS
Visit the STM32Cube ecosystem web page on www.st.com for further information
UM2666 - Rev 2 - July 2020 |
www.st.com |
For further information contact your local STMicroelectronics sales office. |
|
|
|
UM2666
1Acronyms and abbreviations
|
Table 1. List of acronyms |
|
|
Acronym |
Description |
ACI |
Application controller interface |
|
|
ATT |
Attribute protocol |
|
|
BLE |
Bluetooth low energy |
|
|
BSP |
Board support package |
|
|
BT |
Bluetooth |
|
|
GAP |
Generic access profile |
|
|
GATT |
Generic attribute profile |
|
|
GUI |
Graphical user interface |
|
|
HAL |
Hardware abstraction layer |
|
|
HCI |
Host controller interface |
|
|
IDE |
Integrated development environment |
|
|
L2CAP |
Logical link control and adaptation protocol |
|
|
LED |
Light emitting diode |
|
|
LL |
Link layer |
|
|
LPM |
Low power manager |
|
|
MCU |
Micro controller unit |
|
|
PCI |
Profile command interface |
|
|
PHY |
Physical layer |
|
|
SIG |
Special interest group |
|
|
SM |
Security manager |
|
|
SPI |
Serial peripheral interface |
|
|
UUID |
Universally unique identifier |
|
|
UM2666 - Rev 2 |
page 2/22 |
|
|
UM2666
2X-CUBE-BLE2 software expansion for STM32Cube
The X-CUBE-BLE2 software package expands STM32Cube functionality and provides the Bluetooth Low Energy connectivity.
The key features are:
•Complete middleware to build Bluetooth® low energy applications using BlueNRG-2 and BlueNRG-2N devices
•Easy portability across different MCU families, thanks to STM32Cube
•Numerous examples to aid comprehension of Bluetooth connectivity applications
•Package compatible with STM32CubeMX, can be downloaded from and installed directly into STM32CubeMX
•Free, user-friendly license terms
Bluetooth Low Energy is a wireless personal area network technology designed and marketed by Bluetooth SIG. It can be used to develop new innovative applications (fitness, security, healthcare, etc.) using devices which run on coin cell batteries, and can remain indefinetely operative without draining the battery.
According to the Bluetooth standard specification (version 4.0 and above), Bluetooth Classic and Bluetooth Low Energy can be supported on the same device (dual-mode, also called Bluetooth smart ready).
Instead, a single-mode (Bluetooth smart) device supports the BLE protocol only.
A typical BLE system consists of :
•an LE controller, containing a physical layer (PHY) including the radio, a link layer (LL) and a standard host controller interface (HCI)
•a host, containing an HCI and other higher protocol layers (e.g. L2CAP, SM, ATT/GATT and GAP)
UM2666 - Rev 2 |
page 3/22 |
|
|
UM2666
Overview
Figure 1. BLE protocol stack
The host can send HCI commands to control the LE controller. The HCI interface and the HCI commands are standardized by the Bluetooth core specification (refer to the Bluetooth standard for further information).
The PHY layer ensures communication with the stack and data (bits) transmission over-the-air. BLE operates in the 2.4 GHz Industrial Scientific Medical (ISM) band and defines 40 radio frequency (RF) channels with 2 MHz channel spacing.
In BLE, when a device only needs to broadcast data, it transmits the data in advertising packets through the advertising channels. Any device that transmits advertising packets is called advertiser. Devices that aim only at receiving data through the advertising channels are called scanners. Bidirectional data communication between two devices requires them to connect to each other.
BLE defines two device roles at the link layer (LL) for a created connection: the master and the slave. These are the devices that act as initiator and advertiser during the connection creation, respectively.
The host controller interface (HCI) layer provides a standardized interface to enable communication between the host and controller. In BlueNRG-2 and BlueNRG-2N, this layer is implemented through the SPI hardware interface.
In BLE, the main goal of L2CAP is to multiplex the data of three higher layer protocols, ATT, SMP and link layer control signaling, on top of a link layer connection.
The SM layer is responsible for pairing and key distribution, and enables secure connection and data exchange with another device.
At the highest level of the core BLE stack, the GAP specifies device roles, modes and procedures for the discovery of devices and services, the management of connection establishment and security. In addition, GAP handles the initiation of security features. The BLE GAP defines four roles with specific requirements on the underlying controller: Broadcaster, Observer, Peripheral and Central.
The ATT protocol allows a device to expose certain pieces of data, known as attributes, to another device. The ATT defines the communication between two devices playing the roles of server and client, respectively, on top of a dedicated L2CAP channel. The server maintains a set of attributes. An attribute is a data structure that stores the information managed by the GATT, the protocol that operates on top of the ATT. The client or server role is determined by the GATT, and is independent of the slave or master role.
UM2666 - Rev 2 |
page 4/22 |
|
|
UM2666
Overview
The GATT defines a framework that uses the ATT for the discovery of services, and the exchange of characteristics from one device to another. GATT specifies the structure of profiles. In BLE, all pieces of data that are being used by a profile or service are called characteristics. A characteristic is a set of data which includes a value and properties.
The BLE protocol stack is used by the applications through its GAP and GATT profiles. The GAP profile is used to initialize the stack and setup the connection with other devices. The GATT profile is a way of specifying the transmission - sending and receiving - of short pieces of data known as attributes over a Bluetooth smart link.
All current Low Energy application profiles are based on GATT. The GATT profile allows the creation of profiles and services within these application profiles.
Figure 2. Structure of a GATT-based profile
In this example, the profile is created with the following services:
•GAP service, which has to be always set up
•health thermometer service
•device information service
Each service consists of a set of characteristics defining the service and the type of data it provides as part of the service. In the above example, the health thermometer service contains the following characteristics:
•temperature measurement
•temperature type
•intermediate temperature
•measurement interval
Each characteristic details the data type and value, and is defined by attributes (at least, two for characteristic): the main attribute (0x2803) and a value attribute that actually contains the data. The main attribute defines the value attribute handle and UUID.
UM2666 - Rev 2 |
page 5/22 |
|
|
UM2666
Figure 3. State machine during BLE operations
During normal operation, a BLE device can be in the following states:
•Standby: does not transmit or receive packets.
•Advertising: broadcasts advertisements in advertising channels. The device transmits advertising channel packets and possibly listens and answers to, triggered by the advertising channel packets.
•Scanning: looks for advertisers. The device is listening for advertising channel packets from advertising devices.
•Initiating: the device initiates connection to the advertiser and is listens to advertising channel packets from specific device(s) and responds to these packets to initiate a connection with another device.
•Connection: connection has been established and the device is transmitting or receiving:
–the initiator device plays the master role, that is, it communicates with the device in the slave role and defines timings of transmission;
–the advertiser device plays the slave role, that is, it communicates with a single device in the master role.
2.2Architecture
This software is a fully compliant expansion for STM32Cube enabling development of applications using the Bluetooth Low Energy connectivity.
UM2666 - Rev 2 |
page 6/22 |
|
|
UM2666
The software is based on the hardware abstraction layer for the STM32 microcontroller, STM32CubeHAL. The package extends STM32Cube by providing complete middleware for the Bluetooth Low Energy expansion board and several sample applications.
The software layers used by the application software to access the BlueNRG-M2SP module expansion board are:
•The STM32Cube HAL driver layer provides a simple, generic and multi-instance set of APIs (application programming interfaces) to interact with the upper layers (application, libraries and stacks). It includes generic and extension APIs and is based on a generic architecture which allows the layers built on it (such as the middleware layer) to implement their functionalities without dependence on the specific hardware configuration of a given Microcontroller Unit (MCU). This structure improves library code reusability and guarantees high portability across other devices.
•The Board Support Package (BSP) layer provides supporting software for the peripherals on the STM32 Nucleo board, except for the MCU. It has a set of APIs to provide a programming interface for certain boardspecific peripherals (e.g. the LED, the user button etc.) and allow identification of the specific board version.
Figure 4. X-CUBE-BLE2 software architecture
Application |
Applications |
|
|
Middleware |
BLE |
|
Hardware |
STM32Cube Hardware Abstraction Layer (HAL) |
|
Abstraction |
||
|
||
|
|
STM32 Nucleo expansion boards
X-NUCLEO-BNRG2A1 (Connect)
Hardware
STM32 Nucleo development board
2.3Folders
Figure 5. X-CUBE-BLE2 package folder structure
UM2666 - Rev 2 |
page 7/22 |
|
|