Skip to content

USB-related improvements #887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 30, 2020
Merged

USB-related improvements #887

merged 2 commits into from
Jan 30, 2020

Conversation

matthijskooijman
Copy link
Contributor

The main goal of this PR is to make configuration of USB details (VID, PID, manufacturer and product strings) more flexible, allowing (third-party) board.txt files more control over how a board identifies on the USB side.

A related minor change is to set the device version number to 0, since this is a value that should really be configured by the sketch (and until then, should not have a meaningful value).

See the commit messages for details.

@fpistm fpistm added the enhancement New feature or request label Jan 24, 2020
@matthijskooijman
Copy link
Contributor Author

I improved things based on the comments, and rebased on top of master.

Previously, there were a few problems:
 - USB manufacturer string was only configurable when an unknown VID was
   used.
 - USB product string would always include CDC/HID and HS/FS indication,
   it was not possible to specify the full string.
 - USB PID was always hardcoded, depending on the CDC/HID mode. These
   hardcoded PIDs are really only valid within the ST PID, so it made
   now sense that the vid *could* be specified.

This commit cleans this up:
 - Boards must now either specify both the VID and PID, or neither.
 - When boards specify no VID and PID, they use the ST VID with a pid
   based on the CDC or HID mode like before.
 - All boards used to specify the ST vid explicitly in boards.txt, now
   they do not and rely on the default in the code.
 - When no USB_MANUFACTURER_STRING is defined (can be in boards.txt or
   variant.h now), a default is selected based on the VID, or "Unknown"
   is used if the VID is unknown.
 - When no USB_PRODUCT_STRING is defined (can be in boards.txt or
   variant.h now), a default is based on the BOARD_NAME, CDC/HID and
   FS/HS mode.

All included boards should work as before. Third-party board
definitions that use this core should be updated:
 - If build.vid is 0x0483, it should be removed. Otherwise, both vid and
   pid should be specified.
 - If build.usb_manufacturer is specified, it should be replaced by
   adding '-DUSB_MANUFACTURER_STRING="My Company"' to build.extra-flags.
This value should probably be configurable by the sketch, so a
meaningful value can be picked. As long is this is not possible, best to
use 0, rather than 2.0, otherwise it later becomes impossible to use 2.0
in a meaningful way (you'll never know if the device is really 2.0, or
an old version that had no meaningful version number).
@matthijskooijman
Copy link
Contributor Author

I've pushed another update, which rebases on top of master, fixes the comments above, fixes one typo and replaces an #ifdef with #elif. I've squashed the fixes into the original commit, but pushed a separate fixup commit for review here: 3devo@3387a32

I've done a bit more thorough testing this time, define no pid/vid, or just one, no mfg/product string, or just one, and confirming they show up in a device as expected. I also tested with your fpistm@0df5657 commit to confirm that the interface and configuration strings are also created properly.

I have not been able to test the included board definitions (since I have no STM32 dev boards with native USB), but I tested with our own board definition, making the needed changes there.

@fpistm fpistm merged commit ac7c4ce into stm32duino:master Jan 30, 2020
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
None yet
Development

Successfully merging this pull request may close these issues.

2 participants