Skip to content

Extended STM32 Support#569

Open
code-fiasco wants to merge 9 commits intoadafruit:masterfrom
code-fiasco:stm32-support-v2
Open

Extended STM32 Support#569
code-fiasco wants to merge 9 commits intoadafruit:masterfrom
code-fiasco:stm32-support-v2

Conversation

@code-fiasco
Copy link
Copy Markdown
Contributor

Pull Request: Full STM32 Support and Reliable DFU Entry

TL;DR

  • Adds multi-family STM32 support: F1xx, F4xx, G4xx, and WB55
  • Automatic USB initialization and task polling for supported families
  • Serial automatically aliased to SerialTinyUSB
  • Software DFU entry overhauled for reliability:
    • F1/F4/G4: direct ROM bootloader jump
    • WB55: magic value in BKP0R + NVIC_SystemReset() with early Reset_Handler interception
  • WB55-specific support via dfu_boot_stm32wb.c
  • Nucleo-64 board definitions supported for F1/F4/G4 variants
  • Expanded hardware testing: WeAct STM32G431, G474, STM32F411/405, WB55 Nucleo boards

Notes:

  • Generic WB55 variants without a USB clock configuration are not supported
  • STM32F1 DFU still requires validation on boards with factory bootloader
  • No changes were made to other architectures

Full Detailed Description

Summary

This PR extends the Adafruit TinyUSB Arduino library to support a broader range of STM32 MCUs and adds reliable software DFU for all supported boards. It consolidates functionality previously implemented in separate updates (v0.2.0 and v0.3.0).

Added

  • STM32 Family Support
    • F1 (tested on STM32F103 BluePill)
    • F4 (WeAct STM32F411/405)
    • G4 (WeAct STM32G431/G474)
    • WB55 (WeAct STM32WB55CGU6 using P-NUCLEO-WB55 / NUCLEO WB55 USB Dongle board definitions)
  • Automatic USB initialization via initVariant()
  • Automatic TinyUSB task polling using HAL_IncTick() override and serialEventRun() hook
  • Automatic aliasing of Serial to SerialTinyUSB
  • Software DFU entry:
    • F1/F4/G4: direct ROM bootloader jump after disabling interrupts and resetting clocks
    • WB55: writes magic value to RTC backup register (BKP0R), triggers NVIC_SystemReset(), intercepted by dfu_boot_stm32wb.c at Reset_Handler
  • Nucleo-64 board definitions now supported for F1/F4/G4 variants as a side effect of WB55 support

Changed

  • DFU implementation rewritten for reliability across families
  • boards.txt entries updated: four lines per board (including use_1200bps_touch and wait_for_upload_port)
  • boards_txt_additions.txt updated to reflect new format and include Nucleo-64 entry

Testing

  • F1: STM32F103 BluePill (USB works; DFU untested on clone boards)
  • F4: WeAct STM32F411/405
  • G4: WeAct STM32G431/G474
  • WB55: P-NUCLEO-WB55, NUCLEO WB55 USB Dongle

Known Limitations

  • Generic WB55 variants without proper USB clock configuration are not supported. Full generic support would require a PLLSAI1Q 48 MHz USB clock setup in the STM32duino core.
  • STM32F1 DFU entry requires further validation on boards with factory bootloader.
  • Adding support to Nucleo-64 means that TinyUSB will show as an option for some Nucleo boards that aren't yet supported.

Notes

  • This PR builds on the existing STM32 TinyUSB support, extending it to additional families and boards.
  • WB55 DFU implementation ensures reliable bootloader entry without affecting normal boot behavior.
  • No changes were made to other architectures.
  • These changes consolidate prior experimental updates (v0.2.0 and v0.3.0 functionality) into a single, complete STM32 port.

Suggested Testing / Validation Checklist

Suggested Testing / Validation Checklist

  • USB enumeration works on all supported STM32 boards (F1xx, F4xx, G4xx, WB55)
  • CDC, MIDI, HID, MSC USB classes function correctly
  • Sketches using Serial alias to SerialTinyUSB behave as expected
  • Software DFU entry works reliably:
    • WB55: triggers bootloader via magic value + reset
    • F1/F4/G4: triggers ST ROM bootloader after direct jump
  • Nucleo-64 board definitions work with TinyUSB option in Arduino IDE
  • boards.txt auto-upload (use_1200bps_touch + wait_for_upload_port) functions correctly
  • Normal boot is unaffected when DFU is not triggered

Added support for F1 and G4 boards
Serial aliased to SerialTinyUSB
USB initialisation. task polloing, CDC flushing and DFU bootloader entry added
added txt file with lines for boards.txt
## Description

Major update to STM32 support introducing STM32WB55 support and a complete overhaul of software DFU entry across supported STM32 families.

## Added
- STM32WB55 support (tested on WeAct STM32WB55CGU6)
- Support via P-NUCLEO-WB55 and NUCLEO WB55 USB Dongle board definitions
- Nucleo-64 board definition support (F1/F4/G4 variants should work)
- `dfu_boot_stm32wb.c` for reliable WB55 DFU entry
- Additional hardware validation: WeAct STM32G474 and STM32F405

## Changed
- DFU implementation rewritten for reliability:
  - F1/F4/G4 use direct ROM bootloader jump
  - WB55 uses magic value in `BKP0R` + `NVIC_SystemReset()` with early Reset_Handler interception
- `boards.txt` now requires extra lines to enable 1200bps touch
- Updated `boards_txt_additions.txt` with new format and Nucleo_64 entry
- Added suggested change to readme to reflect status of this port

## Known Limitations
- Generic WB55 board definitions lack proper USB clock configuration and are not supported. Use P-NUCLEO-WB55 or NUCLEO WB55 USB Dongle board definitions.
- STM32F1 DFU entry requires further validation on boards with factory bootloader.

This release significantly improves stability and expands supported hardware.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Extends the STM32 Arduino port to support additional STM32 families (F1/F4/G4/WB) with automatic USB init/task servicing, and introduces a WB-specific DFU entry path via early reset interception.

Changes:

  • Auto-detect STM32 family in TinyUSB config and adjust class/buffer defaults.
  • Add automatic TinyUSB initialization (initVariant) and background servicing (HAL_IncTick flag + yield()/serialEventRun()).
  • Implement WB55 software DFU entry via backup-register “magic” + custom Reset_Handler, plus documentation updates for STM32duino boards.txt integration.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/arduino/ports/stm32/tusb_config_stm32.h Adds STM32 family autodetection and updates TinyUSB configuration for the STM32 port.
src/arduino/ports/stm32/Adafruit_TinyUSB_stm32.cpp Implements multi-family STM32 USB HW init, automatic init/task pumping, and DFU entry logic.
src/arduino/ports/stm32/dfu_boot_stm32wb.c Adds WB reset-time DFU interception and bootloader jump.
src/arduino/ports/stm32/boards_txt_additions.txt Documents STM32duino boards.txt menu additions needed to enable TinyUSB.
README.md Updates documentation for STM32 and other cores without built-in support.
Comments suppressed due to low confidence (1)

src/arduino/ports/stm32/boards_txt_additions.txt:22

  • The WB55 note says the Nucleo-64 definitions are “covered by the Nucleo_64 entry above”, but the Nucleo_64.menu.usb.TinyUSB... lines are below this comment in the file. Please fix the wording (“below”) so the instructions are unambiguous.
# Generic WB55 variants lack USB clock configuration and will not enumerate.
# Use the P-NUCLEO-WB55 or NUCLEO WB55 USB Dongle board definition instead
# (covered by the Nucleo_64 entry above). Custom WB55 boards with a 32MHz
# HSE crystal should also work with these definitions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

code-fiasco and others added 3 commits February 26, 2026 11:47
Fixed incorrect path to boards_txt_additions.txt

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Set CFG_TUSB_RHPORT0_MODE to include the speed bits

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Addresses PR review comments:

- Fix WB55 Nucleo-64 wording in boards_txt_additions.txt
- Add build.enable_usb override to prevent duplicate STM32 core USB stack
- Correct README path to boards_txt_additions.txt
- Fix CFG_TUSB_RHPORT0_MODE to include speed bits
- Update TINYUSB_NEED_POLLING_TASK comment to reflect actual scheduling mechanism
- Rework HAL_IncTick() override to avoid hard-coded +1 tick increment
- Replace naked Reset_Handler C implementation with safe assembly wrapper + C handler

No functional changes beyond the requested fixes and clarifications.
Replace `build.usb_flags` with `build.enable_usb` to match existing boards.txt conventions
@code-fiasco
Copy link
Copy Markdown
Contributor Author

Assuming esp32_v2 fail is unrelated like last time? I've submitted pr to STM32 to get boards.txt additions. Next goal is to add F0xx support and then I'm probably done for a while until someone requests something specific, can't keep buying microcontrollers! lol

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