Skip to content

Conversation

@gicking
Copy link

@gicking gicking commented Jan 11, 2026

Summary

Methods USBSerial.baud(), USBSerial.stopbits(), USBSerial.paritytype() and USBSerial.numbits() already exist, but currently return dummy values. Reason is that these have no relevance on the actual USB communication. This PR returns the actual (virtual) VCP baudrate from CDC linecoding.

Added Features

  • USBSerial::baud() returns VCP parameter from CDC linecoding
  • USBSerial.stopbits() returns VCP parameter from CDC linecoding
  • USBSerial.paritytype() returns VCP parameter from CDC linecoding
  • USBSerial::numbits() returns VCP parameter from CDC linecoding

Notes:

  • definitions for stop bits and parity are identical in CDC and USBSerial.h, i.e. no translation required
  • PR uses getter functions to keep the change level low and avoid exposing (private) linecoding
  • no new methods were implemented for USBSerial, only stubs changed

Motivation

In a project I have to use a legacy Windows software, which has different operating modes using different COM port baudrates. In order to detect that operating mode, I need to detect the actual VCP baudrate on Windows side - even though it has no relevance for actual SerialUSB speed.

Before selecting STM32 I checked, and the core does indeed provide USBSerial::baud() method. However, when I later tested it, I found it always returns 115200. On closer inspection I saw that USBSerial.c only contains stubs returning dummy values.

Validation

Running this code on a Nucleo-STM32L432KC prints the (virtual) SerialUSB baudrate configured on PC side via Serial2 / STLink. Also, SerialUSB output is not impaired.

main.cpp

Code formatting

all changes passed AStyle check

@fpistm fpistm self-requested a review January 11, 2026 15:36
@fpistm fpistm added the enhancement New feature or request label Jan 11, 2026
@fpistm fpistm added this to the 2.13.0 milestone Jan 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

2 participants