shared/tinyusb, extmod: Add runtime USB class selection.#19103
Open
andrewleech wants to merge 9 commits into
Open
shared/tinyusb, extmod: Add runtime USB class selection.#19103andrewleech wants to merge 9 commits into
andrewleech wants to merge 9 commits into
Conversation
|
Code size report: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #19103 +/- ##
=======================================
Coverage 98.47% 98.47%
=======================================
Files 176 176
Lines 22845 22845
=======================================
Hits 22497 22497
Misses 348 348 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
82a6938 to
f25a7bb
Compare
Signed-off-by: Andrew Leech <[email protected]>
When false, the DHCP server omits the Router option from DHCP responses. This prevents point-to-point links (like USB NCM) from advertising a default gateway that hijacks the host's internet route. Defaults to true for backward compatibility with CYW43 AP mode. Signed-off-by: Andrew Leech <[email protected]>
lwIP's own opt.h defaults LWIP_IPV6 to 0, so the explicit hardcoded define here was redundant and prevented overriding the value from elsewhere. Signed-off-by: Andrew Leech <[email protected]>
Signed-off-by: Andrew Leech <[email protected]>
Adds TinyUSB configuration and descriptor support for USB Network Control Model (NCM) interface. This provides the low-level USB infrastructure needed for USB networking. Signed-off-by: Andrew Leech <[email protected]>
Implements a complete USB Network Control Model (NCM) driver that provides ethernet-over-USB functionality integrated with lwIP stack. Features: - Link-local IP address generation from MAC using CRC32 - DHCP server integration with connect callbacks - Full lwIP network interface with IPv6 support - USB NCM protocol handling via TinyUSB - Python network.USB_NET class interface Signed-off-by: Andrew Leech <[email protected]>
Automatically enable MICROPY_HW_NETWORK_USBNET when MICROPY_PY_LWIP is enabled, following the same pattern as WEBSOCKET and WEBREPL. This makes USB networking available by default on boards that support both USB device mode and LWIP networking, while still allowing boards to explicitly disable it by setting MICROPY_HW_NETWORK_USBNET=0. Also fixes USB NCM build issues when LWIP is enabled for ethernet by making MICROPY_HW_NETWORK_USBNET conditional on both LWIP and TinyUSB. Signed-off-by: Andrew Leech <[email protected]>
Add builtin_driver flag constants (BUILTIN_FLAG_CDC, BUILTIN_FLAG_MSC, BUILTIN_FLAG_NCM) that can be OR'd together to select USB classes at runtime from boot.py. A dynamic configuration descriptor is built containing only the selected classes with compact interface/endpoint numbering. Signed-off-by: Andrew Leech <[email protected]>
Signed-off-by: Andrew Leech <[email protected]>
f25a7bb to
08590ca
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Adds
BUILTIN_FLAG_CDC,BUILTIN_FLAG_MSC, andBUILTIN_FLAG_NCMconstants tomachine.USBDeviceso boot.py can select which built-in USB classes are active at runtime. Previously the only options wereBUILTIN_NONE(disable all builtins) orBUILTIN_DEFAULT(CDC only), with no way to enable NCM or MSC alongside CDC without writing a full runtime USB driver in Python.Assigning a flag mask to
builtin_driverbuilds a dynamic configuration descriptor containing only the selected classes, with interface/endpoint/string numbers compacted to remove gaps. The USB PID is varied per combination so the host re-enumerates correctly when classes change.BUILTIN_DEFAULTis now CDC-only rather than all compiled-in classes. This keeps the default USB footprint minimal and lets boot.py opt into heavier classes like NCM.Example boot.py:
Testing
Tested on NUCLEO_WB55 (stm32) with CDC+NCM and CDC-only configurations. Verified USB re-enumeration on class change, descriptor correctness with
lsusb -v, and NCM data path with ping.Generative AI
I used generative AI tools when creating this PR, but a human has checked the
code and is responsible for the code and the description above.