Skip to content

feat: add UF2 uploader for CDC-touch bootloaders - #122

Open
cumin777 wants to merge 3 commits into
stm32duino:mainfrom
cumin777:feat/xiao-stm32c5
Open

feat: add UF2 uploader for CDC-touch bootloaders#122
cumin777 wants to merge 3 commits into
stm32duino:mainfrom
cumin777:feat/xiao-stm32c5

Conversation

@cumin777

@cumin777 cumin777 commented Aug 18, 2026

Copy link
Copy Markdown

Summary

Add uf2upload, a self-contained C++17 host uploader for STM32 boards using a USB CDC 1200-bps touch and UF2 mass-storage bootloader.

This PR implements the following features:

  • Convert a firmware .bin image to UF2 with board-supplied address, family ID and maximum-size validation
  • Detect an already-mounted UF2 volume, or perform a CDC 1200-bps touch and wait for the bootloader volume before copying the UF2 image
  • Add Windows, Linux x86_64 and Linux ARM64/AArch64 tool artifacts
  • Breaking changes

Arduino_Core_STM32 can describe a UF2 upload recipe, but STM32Tools currently has no uploader that can perform the complete CDC-touch, UF2 conversion and mass-storage-copy flow. This tool provides that missing user-facing upload path without requiring Python or shell dependencies at upload time.

On Windows, uf2upload tolerates the transient serial error caused by the expected reset after the 1200-bps touch and continues waiting for the UF2 volume.

The Linux ARM64 artifact is cross-compiled from the same source with the AArch64 GNU toolchain and is placed at linux/aarch64/uf2upload. The build scripts and Dockerfile also include this artifact in the ARM64 tool build.

Validation

Validated on a Seeed XIAO STM32C5 running the TinyUF2 bootloader:

  • Upload when the XIAOC5BOOT volume is already mounted
  • Full automatic flow from a running application: CDC 1200-bps touch, bootloader entry, UF2 conversion and copy
  • Windows serial-reset status reporting during the device reset transition

The Linux x86_64 host build was compiled and functionally exercised under Ubuntu 24.04 on WSL2. The Linux ARM64 binary was cross-compiled on x86_64 and executed under QEMU user-mode emulation for command-line, UF2 generation, simulated volume discovery and file-copy checks. Physical ARM64 USB CDC and TinyUF2 hardware upload have not been validated.

Packaging notes

The Windows and Linux x86_64 artifacts are included, together with the Linux ARM64/AArch64 artifact. macOS build integration is included, but a macOS artifact and hardware validation are not part of this PR.

Arduino_Core_STM32 follow-up PR #3061 consumes this executable from STM32Tools. After this PR merges, a corresponding STM32Tools release/package-index update is still required before end users can install the tool through Board Manager.

CI and AStyle checks are pending GitHub Actions.

@cumin777

Copy link
Copy Markdown
Author

Arduino_Core_STM32 follow-up: generic UF2 upload recipe is now split into core PR #3061, and XIAO STM32C5 board support is #3048. The core recipe invokes the uf2upload executable from this PR; after this tools PR merges, a STM32Tools release/package-index update will still be needed before end users can install it through Board Manager. End-to-end C5 CDC 1200-bps upload also depends on core USB HAL v2 PR #3059.

@fpistm

fpistm commented Aug 27, 2026

Copy link
Copy Markdown
Member

Thanks for the PR.
Anyway it seems some host target are missing ? arm ?

@cumin777

cumin777 commented Aug 28, 2026

Copy link
Copy Markdown
Author

I have added a Linux ARM64/AArch64 uf2upload artifact at linux/aarch64/uf2upload, built from the same source with the AArch64 GNU toolchain.

The ARM64 artifact was cross-compiled on Ubuntu 24.04 under WSL2 (x86_64), checked as an AArch64 ELF, and executed under QEMU user-mode emulation with an ARM64 sysroot. But physical ARM64 USB CDC and TinyUF2 hardware upload have not been validated yet.

I also completed Linux x86_64 validation on Ubuntu 24.04.3 under WSL2. The following all passed:

  • Linux x86_64 compilation with make -C src/uf2upload, without warnings or errors
  • ELF and dynamic-library checks (file and ldd)
  • --help and invalid-argument handling
  • UF2 conversion from a test binary, including 512-byte block size, UF2 magic values, application address 0x08008000, and family ID 0x00C5C5C5
  • Simulated XIAOC5BOOT volume discovery and UF2 copy
  • Missing input, empty input, size-limit, invalid-parameter, missing-port, and timeout error paths
  • Linux termios 1200-bps path using a pseudo-terminal

And the Windows build and upload flow have also been exercised in my regular Windows development environment.

Arduino Core is not required for these host-tool tests. It is only needed when reproducing the complete Arduino compile-and-upload workflow with a real xiao-STM32C5 board.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants