change SerialUSB.baud() etc. to return the actual CDC line coding #2892
+38
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Methods
USBSerial.baud(),USBSerial.stopbits(),USBSerial.paritytype()andUSBSerial.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 linecodingUSBSerial.stopbits()returns VCP parameter from CDC linecodingUSBSerial.paritytype()returns VCP parameter from CDC linecodingUSBSerial::numbits()returns VCP parameter from CDC linecodingNotes:
USBSerial.h, i.e. no translation requiredlinecodingUSBSerial, only stubs changedMotivation
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