DFU V2 CDC Loader Example

Source code path: example/dfu_v2/cdc/loader

Supported Platforms

  • sf32lb52-lcd_n16r8_hcpu — SF32LB52X, 16MB NOR flash (n16r8).

Overview

This example is the DFU loader subprogram for the USB-CDC channel of DFU V2. It is flashed independently into the DFU_V2_LOADER partition; after the bootloader detects an update flag it jumps in here to receive the new firmware over USB-CDC, write it directly to the target partition, and optionally show the upgrade progress on screen.

Usage Instructions

This loader usually does not need a separate build: the CDC user application’s SConstruct pulls it in as a child project via AddDFU_CDC(SIFLI_SDK) (see tools/build/building.py), so building the user application also produces the loader firmware. It can also be built standalone.

Hardware Requirements

Before running this example, prepare:

Compilation and Flashing

To build the CDC user application (the loader is included automatically), switch to the user application project directory and run the scons command to compile:

> scons --board=sf32lb52-lcd_n16r8_hcpu -j8

To build this loader standalone, switch to this example project directory and run the scons command to compile:

> scons --board=sf32lb52-lcd_n16r8_hcpu -j8

Artifacts are placed under the matching build_<board> directory. For detailed compilation and download steps, please refer to the Quick Start Guide.

Expected Results

  1. After flashing, the board runs the user application (the screen shows Ver: 1.0.9).

  2. The PC sends the 4-byte trigger magic 0xAA 0x55 0xDF 0x00 to the user application over USB-CDC; the app replies with the ACK 0xAA 0x55 0xDF 0x01, then calls dfu_enter_dfu_mode() to write the update flag and reboot.

  3. After the reboot the bootloader detects the update flag and jumps into this loader (DFU_V2_LOADER partition). In main() the loader first calls dfu_init() to bring up the middleware, then dfu_check_install() to handle any pending install, and waits for the USB-CDC connection.

  4. The PC tool connects and streams the new firmware to the loader in chunks. The loader receives it via dfu_process() and writes it directly to the target partition; the on_dfu_event() callback feeds progress to the LVGL UI so the screen shows the percentage, and a success popup appears when all images are complete.

  5. The loader finishes the install and reboots; the bootloader jumps back into the new user application. The changed version label on the screen confirms a successful upgrade.

For debugging, the cdc_dfu_info console command reports USB readiness and the current transfer progress.

Troubleshooting

Reference Documentation

Update History

Version

Date

Release Notes

0.0.1

06/2026

Initial version