1. Firmware Update Over The Air Profile
The Firmware Update Over The Air (FUOTA) profile is intended to demonstrate multi capabilities of the STM32WBA Bluetooth® LE solution. It acts as:
- GAP Central & GATT Server (Router Service) device to be connected and controlled by Smartphone
- GAP Peripheral & GATT Client device to control end device (P2P FUOTA Server, HR FUOTA Server)
The FUOTA service is a Generic Attribute Profile (GATT) based low-energy profile defined by STMicroelectronics with proprietary UUIDs(128 bits) including three characteristics
This wiki page is the description of the Heart Rate FUOTA and Peer to Peer FUOTA projects provided within the STM32CubeWBA MCU Package[1]
Overall application diagram |
---|
The table below describes the structure of the FUOTA service:
Bluetooth® LE FUOTA Service specification | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
FUOTA service is composed of three characteristics:
- Base Address characteristic :
- to be used by the smartphone or web bluetooth application to:
- provide Action to do.
- provide Address to store the new application, an 8K bytes page offset.
- Inform which sectors to erase.
- to be used by the smartphone or web bluetooth application to:
FUOTA service - Base Address characteristic | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
- Confirmation characteristic :
- to be used by the smartphone or web bluetooth application to inform:
- it is ready to receive the new binary application.
- to Reboot, the new file is fully received.
- Error not free, not ready to receive a new binary application.
- to be used by the smartphone or web bluetooth application to inform:
FUOTA service - Confirmation characteristic | ||||||
---|---|---|---|---|---|---|
|
- Raw Data characteristic:
- to be used by the smartphone or web bluetooth application to transfer the file.
FUOTA Service - Raw Data characteristic | ||||||
---|---|---|---|---|---|---|
|
Example of flow diagram between STM32WBAs & ST BLE Toolbox smartphone application. |
---|
1.1. Advertising data
At start up, application with FUOTA starts fast advertising (80ms/100ms) Data advertised are composed of:
Heart Rate with FUOTA Advertising packet | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Manufacturer data are encoded following STMicroelectronics BlueST v2 as described below:
Application Heart Rate with FUOTA STMicroelectronics Manufacturer Advertising data | |||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
2. Requirements
2.1. Software and system requirements
The software required are the following (minimum IDEs version):
- IAR Embedded Workbench for ARM (EWARM) toolchain 9.20.1
- RealView Microcontroller Development Kit (MDK-ARM) toolchain V5.37
- STM32CubeIDE toolchain V1.12.00 [2].
Programmer:
- STM32CubeProgrammer[3] : To flash the board with an already generated binary
2.2. Hardware requirements
NUCLEO-WBA5 [4] is necessary to install the application.
Hardware platform illustration |
---|
|
2.3. Collector applications compatible
The STM32CubeWBA FUOTA projects (Hear Rate FUOTA and P2P FUOTA) are compatible with the following remote interfaces:
- ST BLE ToolBox running on a smartphone or a tablet.
- Web bluetooth interface running into a web browser.
3. STM32WBA FUOTA example description
3.1. Project directory
The FUOTA Service embeded in the "BLE_HeartRate_ota" and the "BLE_p2pServer_ota" applications and the "Application Install Manager" are available by downloading STM32CubeWBA MCU Package[5].
Refer to How to Build a BLE Project wiki page for project directory information.
3.2. Project description
3.2.1. Structure
Software project structure with the most important parts:
Application Install Manager project structure |
---|
WARNING: Do not modify the files in Middlewares folder |
Heart Rate FUOTA project structure |
---|
WARNING: Do not modify the files in Middlewares folder |
3.2.2. Applications Role
3.2.2.1. Application Install Manager
It is responsible to install the firmware update from the Download Slot to the Active Slot when fully received.
When there is no firmware update to be installed, it shall jump on the reset vector of the Application. It cannot be updated with FUOTA.
3.2.2.2. User Application
This is a single binary implementing both the user and FUOTA application.
The FUOTA application is responsible to download the firmware update in the Download slot.
This binary (including both the User and FUOTA application) can be updated with FUOTA.
3.2.2.3. Flow
FUOTA Flow Diagram between Application Install Manager and FUOTA User Application |
---|
FUOTA Steps |
---|
Alternatively, it could be possible to run in parallel both the User Service and the OTA Service.
In that case, it is possible to download a new firmware update while the User service keeps running.
Once the firmware download is completed, the application shall reboot the device to install it.
3.2.3. Application initialization
The different steps of the application initialization are described below:
FUOTA project initialization |
---|
3.2.4. GAP and GATT initialization and interaction
and The Bluetooth LE FUOTA application initialization is done within app_ble.c
- Initialize the BLE stack - initialize the device as peripheral - configure and start advertising: ADV parameters, local name, UUID - APP_BLE_init()
- Call the services controller initialization SVCCTL_Init() - svc_ctl.c
- Manage the GAP event - SVCCTL_App_Notification()
- HCI_LE_CONNECTION_COMPLETE - provides information of the connection interval, slave latency, supervision timeout
- HCI_LE_CONNECTION_UPDATE_COMPLETE- provides the new information of the connection
- HCI_DISCONNECTION_COMPLETE - informs the application about the link disconnection and the reason
The Services management is done by the service controller, svc_ctl.c
- Initialize the number of registered handler - SVCCTL_SvcInit()
- Manage events - SVCCTL_UserEvtRx()- from the BLE Host Stack and redirect them to the gap event handler - SVCCTL_App_Notification
The application level of the FUOTA is done with ota_app.c':
- Initialization of the services:
- FUOTA Service - OTA_Init() - ota.c
- Initialization of the context of the application
- Erase the Download Slot
- Receive notification from the FUOTA Service - OTA_Notification()
The FUOTA Service ota.c manages the specification of the service:
- Service Init - OTA_Init()
- Register FUOTA Event Handle to Service Controller - SVCCTL_RegisterSvcHandler(OTA_EventHandler);
- Initialize Service UUID – add FUOTA as Primary services
- Initialize Base Address characteristic
- Initialize Confirmation characteristic
- Initialize Raw Data characteristic
- Manage the GATT event from BLE Stack - OTA_EventHandler()'
- ACI_GATT_WRITE_PERMIT_REQ_VSEVT_CODE
- Reception of a Write Command: Raw Data Characterictic Value
- Send an aci_gatt_write_response() with an OK or KO status.
- Reception of a Write Command: Raw Data Characterictic Value
- ACI_GATT_ATTRIBUTE_MODIFIED_VSEVT_CODE
- Reception of an attribute modification - Confirmation Characteristics Description Value : ENABLE or DISABLE Indication
- Notify application of the Confirmation Indication - OTA_Notification(OTA_CONF_INDICATE_ENABLED_EVT/OTA_CONF_INDICATE_DISABLED_EVT)
- Reception of an attribute modification - Base Address Characteristics Value
- Notify application of the Base Address Modification- OTA_Notification(OTA_BASE_ADR_WRITE_NO_RESP_EVT)
- Reception of an attribute modification - Raw Data Characteristics Value
- Notify application of the Raw Data Modification- OTA_Notification(OTA_RAW_DATA_WRITE_NO_RESP_EVT)
- Reception of an attribute modification - Confirmation Characteristics Description Value : ENABLE or DISABLE Indication
- ACI_GATT_WRITE_PERMIT_REQ_VSEVT_CODE
FUOTA software module interaction |
---|
4. Build and install
Follow the steps described in Bluetooth® LE Build and Install Application page, applying them for STM32WBA BLE_HeartRate_ota or BLE_p2pServer_ota projects.
The FUOTA service provides the possibility to receive new application to be installed while the current application is running.
It requires to add the FUOTA Service & Characteristics to the current application.
The FUOTA Application allows to:
- Download new BLE Application in a Free Area – Download slot
- Update/Download new User Configuration file
- Jump to the Application Install Manager
The Application Install Manager allows to:
- Replace the BLE Application to be used after reboot
- Download user data in any place in the CM33 user flash
GATT Server memory mapping example |
---|
There are 4 regions with fixed size and address, not modified along firmware update:
- One region (page 0 to page 1) that contains the Application Install Manager. This region shall be at the boot address of the CPU out of power on. The Application Install Manager is a full binary with its own vector table.
- One region that contains the NVM and User Configuration Data. The address is fixed and can be placed anywhere in the mapping. It is possible to split the NVM from the User Data into several regions at different location in the memory.
- 1 Active Slot (from page 2) and 1 Download Slot. They have same size and are placed anywhere in the memory. The Active slot contains the Application (User + OTA) binary whereas the Download slot is used only to store the application update to be applied.
The Keyword_User is used to ensure the firmware update has been fully received.
The Keyword_User is placed at the end of the binary. It shall be defined with a magic value that cannot be found anywhere else in the firmware. A variable containing the address of the Keyword_User is placed just after the vector table at a fixed address. This variable is initialized with the address of the Keyword_User. This address is defined at link time and the linker file can be used to ensure the Keyword_User is placed at the end of the binary.
The advantage of this solution is that it does not need any post-script in addition to the standard build process. In another hand, it does not protect versus data that are not properly written in the flash. This mechanism only ensures that the expected amount of byte has been written in flash.
5. Collector applications
5.1. Android ST BLE Toolbox
Android ST BLE Toolbox – How to | |||
---|---|---|---|
Android ST BLE Toolbox – How to | |||
---|---|---|---|
5.2. Web Bluetooth
From the ST Web Bluetooth Home Page, click on Web Bluetooth WBA to access the dedicated WBA web application.
The documentation for the various ST Web Bluetooth applications is available at this same address.
See https://applible.github.io/Web_Bluetooth_App_WBA