This is an old revision of the document!
Table of Contents
Bluetooth Low Energy for STM32 - peripheral
This laboratory shows the details of the example provided as part of the STM32duinoBLE library by Arduino.
Installing the library and importing the example
As the first step, we need to install the library to the current project (how to download and import the first STM32WB55 project is described here. We can choose the simplest blink project as the base for our BLE peripheral).
After finding the library in the repository we can add it to our project. By clicking the “Add to Project” button you can select the already existing “arduino blink” project to add the library entry to the platformio.ini file automatically. It will create the dependency of your project build with the specific version of the STP32duinoBLE library. To use the code provided as the example, select the code of the “LED” example and paste it as the content of the “Blink.cpp” program chosen from the project tree.
Description of the most important elements of the code
To use the BLE device you need to create the object of the BLELocalDevice class. This object can work both using the SPI-connected Bluetooth module and the built-in unit in SoC. In the case of STM32WB55, the internal unit is used, so the HCISharedMemTransportClass is chosen as the connection to the BLE module.
HCISharedMemTransportClass HCISharedMemTransport; BLELocalDevice BLEObj(&HCISharedMemTransport); BLELocalDevice& BLE = BLEObj;
After creating the BLE object, we can configure services, characteristics and advertising process. Let's define the service first. To use the service defined by you, you specify the 128-bit version of the UUID. You can use also predefined 16-bit services as listed in Bluetooth SIG documents.
BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service
This service can be added to the advertising information of the device.
