Skip to content

feat(usb): add STM32C5 HAL v2 USB device support - #3059

Open
cumin777 wants to merge 1 commit into
stm32duino:mainfrom
cumin777:feat/stm32c5-halv2-usb
Open

feat(usb): add STM32C5 HAL v2 USB device support#3059
cumin777 wants to merge 1 commit into
stm32duino:mainfrom
cumin777:feat/stm32c5-halv2-usb

Conversation

@cumin777

@cumin777 cumin777 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds STM32C5 HAL v2 USB device support to the shared USBDevice library.

This PR implements the following features:

  • HAL v2 USB device low-level adapter for STM32C5
  • CDC endpoint and PMA configuration for the C5 USB DRD FS peripheral
  • CDC transmit handling compatible with HAL v2 endpoint fields
  • Optional CDC line-coding callback for board-specific actions such as 1200-bps touch
  • HAL-level USB re-enumeration using HAL_PCD_DeviceDisconnect() and the matching HAL_PCD_Start() attach path

Motivation

The Seeed XIAO STM32C5 uses the STM32C5 HAL v2 USB device peripheral. The shared USBDevice library currently has no HAL v2 low-level adapter, so the board cannot provide USB CDC through the normal Arduino core path.

This change is intentionally separated from the XIAO board definition so the common USB implementation can be reviewed independently. The initial split first used a direct PA_12 GPIO detach in usbd_if.c; after checking the STM32C5 HAL, this was replaced with the HAL PCD device-connect API. The common re-enumeration helper no longer contains a C5-specific pin reference.

Validation

USB CDC enumeration, serial communication and sustained CDC transfers were validated on Seeed XIAO STM32C5. The C5 CDC PMA endpoints are configured as non-overlapping single-buffer areas.

Code formatting

  • Ensure AStyle check is passed thanks CI

Closing issues

N/A

@cumin777
cumin777 force-pushed the feat/stm32c5-halv2-usb branch from 23c243f to 50a4eea Compare August 27, 2026 08:02
@cumin777

Copy link
Copy Markdown
Contributor Author

Follow-up: after checking the STM32C5 HAL source, I replaced the temporary direct PA_12 GPIO detach with HAL_PCD_DeviceDisconnect() after PCD initialization. HAL_PCD_Start() performs the matching attach when USB is ready. The common usbd_if.c no longer contains a C5-specific pin reference.

@cumin777

Copy link
Copy Markdown
Contributor Author

Follow-up split PRs are now open for the remaining shared pieces: #3060 contains the HAL v2 UART helper compatibility fix, and #3061 contains the generic UF2 upload recipe. The UF2 recipe invokes the uf2upload executable from Arduino_Tools #122; end-to-end C5 1200-bps upload requires both #3061 and this USB PR (#3059), while #3060 is independent of USB and Tools.

@fpistm
fpistm self-requested a review August 27, 2026 11:46
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.

1 participant