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
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 brandSIFLI, and the versionVer: 1.0.9(taken fromAPP_VERSIONinmain.c).Prepare a “new version” firmware to verify the upgrade: change
APP_VERSIONinsrc/main.cto a new value (e.g.1.1.0) and rebuild to getproject/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--triggerso 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 --triggerHere
0x12218000is theHCPU_FLASH_CODEpartition address (partition-table base0x12000000plus offset0x00218000).Trigger flow: the tool sends the 4-byte magic
AA 55 DF 00to the device; theusbd_cdc_acm_bulk_outcallback inmain.crecognizes the magic, replies withAA 55 DF 01, and setsg_dfu_trigger_requested. The main loop sees the flag and callsdfu_enter_dfu_mode(), which writes the update flag and reboots.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.
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 |