DFU V2 CDC User Application Example

Source code path: example/dfu_v2/cdc/app

Supported Platforms

  • sf32lb52-lcd_n16r8_hcpu — SF32LB52X chip, NOR Flash (16Mb NOR + 8MB PSRAM).

Overview

This example demonstrates the user application side of DFU V2 firmware update over the USB-CDC (virtual serial) channel. The device enumerates as a CDC ACM serial port and shows its version on screen during normal operation; when the PC tool sends an upgrade trigger over that port, the device acknowledges and reboots into the DFU loader to perform the flashing. The companion PC-side tool is dfu_v2_cdc_tool.py, which first sends the trigger to put the device into DFU mode, then uploads firmware over USB-CDC.

Usage Instructions

After flashing the build artifacts to the device, the device runs normally and enumerates as a USB-CDC serial port showing its version. Prepare a new-version firmware, run dfu_v2_cdc_tool.py on the PC with --trigger to start the upgrade, and the device reboots into the loader to complete the flashing before returning to the new user application.

Hardware Requirements

Before running this example, prepare:

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

  • A USB data cable to connect the development board to the PC.

Compilation and Flashing

Switch to the example project directory and run the scons command to compile:

> scons --board=sf32lb52-lcd_n16r8_hcpu -j8

Building the application automatically pulls in the sibling loader as a child project via AddDFU_CDC in building.py, so the loader does not need to be built separately. For detailed compilation and download steps, please refer to the Quick Start Guide.

Expected Results

  1. Flash the build artifacts to the device and reset. The device enumerates as a USB-CDC serial port and the screen shows the title CDC DFU EXAMPLE, the brand SIFLI, and the version Ver: 1.0.9 (taken from APP_VERSION in main.c).

  2. Prepare a “new version” firmware to verify the upgrade: change APP_VERSION in src/main.c to a new value (e.g. 1.1.0) and rebuild to get project/build_sf32lb52-lcd_n16r8_hcpu/main.bin. Then on the PC, run the update tool with the serial port, this new firmware and the target partition address, adding --trigger so the tool sends the trigger first:

    python dfu_v2_cdc_tool.py --port COM3 --firmware project/build_sf32lb52-lcd_n16r8_hcpu/main.bin --addr 0x12218000 --trigger
    

    Here 0x12218000 is the HCPU_FLASH_CODE partition address (partition-table base 0x12000000 plus offset 0x00218000).

  3. Trigger flow: the tool sends the 4-byte magic AA 55 DF 00 to the device; the usbd_cdc_acm_bulk_out callback in main.c recognizes the magic, replies with AA 55 DF 01, and sets g_dfu_trigger_requested. The main loop sees the flag and calls dfu_enter_dfu_mode(), which writes the update flag and reboots.

  4. After the reboot the bootloader detects the update flag and jumps into the DFU loader. The tool reconnects automatically, uploads the firmware over the DFU V2 protocol, writes it directly to the target partition, and then resets the device.

  5. The device reboots back into the new user application. The Ver: label on screen changes to the value from the new firmware, confirming the upgrade succeeded.

Troubleshooting

Reference Documentation

Update History

Version

Date

Release Notes

0.0.1

06/2026

Initial version