Implementing OTA Firmware Update in User Application


This code example has a related User's Guide, here: Uploading Firmware Images Using OTA DFU


The article referred in the Background section discusses two methods of performing OTA:

  1. Using Apploader

  2. Using user application

This code example demonstrates the second method. See the article Uploading Firmware Images Using OTA DFU for conceptual details.

The code sample provided in AN1086: Using the Gecko Bootloader with the Silicon Labs Bluetooth® Applications is simplified to fit on one page. The full example provided here includes some additional debug prints and features, such as printing the estimated data transfer rate.

The main functional difference is related to erasing the download area. In the simplified code, the download area is erased when the remote OTA client starts the OTA process (writing value 0 to ota_control). In this example, the download area is erased at startup. The code also reads the content of the download area and does an erase only if needed (i.e., if the download area is not already blank) to avoid dropping connection because of the supervision timeout. Erasing the whole download area (256k or more) will take several seconds (it is a blocking function call) and this can lead to supervision timeout unless the connection parameters are specifically adjusted to prevent it.

Before installing this example, make sure you have created a suitable Gecko bootloader project and flash your target device with the <bootloader_name>-combined.s37 file.

Setting up

  1. Create SoC-empty project for your radio board.

  2. Import the attached GATT database (gatt.xml) into the project.

    1. In BLE GATT Configurator, select the top hierarchy (Custom BLE GATT) in the database that is included in the SoC-empty by default. Click the import icon on the right hand side. Open the gatt.xml attached.

    2. Press the Generate button to re-generate the gatt_db.c/h files. After importing, you should see "Silicon Labs OTA" service in the GATT with two characteristics: Silicon Labs OTA Control and Silicon Labs OTA Data.

  3. Enable debug prints: open the file app.h in project root folder, and change the value of DEBUG_LEVEL from 0 to 1.

  4. Add necessary files and includes for bootloader API:

    1. Locate the following directory on your Studio installion: C:\SiliconLabs\SimplicityStudio\v4\developer\sdks\gecko_sdk_suite\v2.x\platform\bootloader\api.

    2. Copy these two files into your project:

      • btl_interface.c

      • btl_interface_storage.c

  5. Add the necessary include paths to your project build settings:

  6. Copy the attached app.c file to the project (overwrites the default app.c from soc-empty template)

  7. Build the project and flash it to your target.


Now you can generate OTA files by running the create_bl_files script and try OTA using the full.gbl file. You can use the EFR Connect app as the OTA update client.

You can check the debug prints to make sure that the application can detect the bootloader version and download area information correctly as the first test before trying any updates. Below is a sample of the debug prints when running on a EFR32xG13 device: (with 512k flash).

stack version: 2.10.0
local BT device address: 00:0b:57:49:2a:ea
boot event - starting advertising
Gecko bootloader version: 1.6
Slot 0 starts @ 0x00044000, size 241664 bytes