DFU V2 BLE Loader Example

Source code path: example/dfu_v2/ble/loader

Supported Platforms

The loader project does not hard-code a board; the target board is chosen at build time via --board, matching the companion BLE user application (verified on sf32lb52-lcd_n16r8_hcpu). Other SF32LB52X boards that provide a matching partition table work as well.

Overview

This example is the DFU loader subprogram used when DFU V2 upgrades firmware over the BLE channel. It is flashed in and runs independently from the DFU_V2_LOADER partition, receives the new firmware pushed by a phone over BLE, and writes it directly into the target partition — it is the program that actually performs the erase/flash.

Usage Instructions

You normally do not build this loader on its own. Through AddDFU_BLE() in building.py, the BLE user application’s SConstruct pulls it in automatically as a child project via AddChildProj. In other words, building the application as usual also compiles the loader. To debug it in isolation, you can also enter this project directory and build it standalone.

Hardware Requirements

Before running this example, prepare:

  • One development board supported by this example (Supported Platforms).

  • A phone with BLE and the companion upgrade app.

Compilation and Flashing

Switch to the BLE user application project directory and run the scons command to compile; building the application automatically includes this loader:

> scons --board=sf32lb52-lcd_n16r8_hcpu -j8

To build the loader standalone (e.g. for isolated debugging), enter this project directory:

> scons --board=sf32lb52-lcd_n16r8_hcpu -j8

Artifacts are generated under build_<board_name>. For detailed compilation and download steps, please refer to the Quick Start Guide.

Expected Results

  1. After entering BLE upgrade mode, the device starts advertising with a device name like SIFLI_DFU-xx-xx-xx-xx-xx-xx, where xx represents the device’s Bluetooth address, and waits for a phone to connect.

  2. Once the phone app connects, it pushes the firmware over the BLE serial transmission service; the loader receives it and writes it directly to the target partition. During the transfer it reports the progress percentage, and the progress bar is shown when the UI is enabled.

  3. To avoid getting stuck in upgrade mode, the loader has two built-in timeouts: a 5-minute global timeout (DFU_MODE_TIMEOUT_MS, the overall budget for the whole upgrade mode) and a 60-second inactivity timeout after connection (DFU_INACTIVITY_TIMEOUT_MS, reset on every progress message once BLE is connected). If either fires before the upgrade completes, the device reboots back into the user application.

  4. After all firmware is written, the loader waits 3 seconds (REBOOT_DELAY_MS, to let the success popup display) and then reboots back into the new user application.

  5. For debugging, type dfu_ble_info in the loader console to see BLE power-on status, MTU, and current progress.

Troubleshooting

Reference Documentation

Update History

Version

Date

Release Notes

0.0.1

06/2026

Initial version