-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add supervisor.set_usb_identification(manufacturer, product, vid, pid) function #6247
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
Conversation
b23ec04
to
d9ce4a2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking on this work! A number of people have asked for it.
I made some detailed comments. I would also note that we may want to get this to fit on the SAMD21 builds, which are very tight on code space for right now. If that's not possible, we need to make this optional to save the code space.
4409e62
to
9f3baa5
Compare
@dhalbert do you have any idea what that could be about? Are those last two bytes just enough to hit a stack size limit maybe? For reference, I'm testing this on the solderparty RP2040 stamp. I don't have anything set up to debug the crash currently - USB doesn't come up so I just know that it "didn't work". |
I don't know, but I was going to look later. I think there may be a write past the end of something. Your shorter ones may be working by accident. Also, does odd vs even size make a difference (e.g. 128 vs 127?) |
Ah, that seems to be it actually! At 128 it works. Increasing |
Are these buffers where the UTF-16 values go? Then I'd think they need to be a multiple of two bytes. |
No, these buffers are used to hold the "unexpanded" ASCII values. They are |
I've fixed a wrong
But it still will only work with even lengths. I'm not sure how to diagnose this further, but I actually just realized that the length of 128 makes perfect sense: the final USB descriptor can hold 127 UTF-16 chars, but in this phase we actually need space for a null byte (since we are not storing the size out-of-band). I guess that
|
It actually turns out that the maximum length of USB descriptor strings is 126 characters. Since the USB descriptor size field is only one byte, the maximum length of the whole descriptor is actually 255 and not 256 bytes as I had wrongly assumed so far. |
Hey @dhalbert, this is ready functionality-wise at this point; it does look like I pushed some builds over the edge though (~50 bytes too much for most failures). There are some that seem a bit odd though, for example As you mentioned above, this probably means that this feature should go behind a feature flag? |
I have some ideas for post-7.3.0 for shrinking some builds a bit by consolidating similar error messages, but yes, we probably need to conditionalize it. |
@s-ol I have not forgotten this, but am deferring it until after I finish working on 7.3.0 final. |
3782f3a
to
adf15fa
Compare
In the long run, this functionality is probably better put in the |
fc5d32e
to
9aca092
Compare
Yeah, I think we discussed it in a line-comment thread above originally. It definitely would fit in a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, will merge after the latest tweaks I made!
Tested this on Linux with a Metro M4, using lsusb
. One interesting thing is that the manufacturer string is overriden by a known VID name. I had to try several before I got the mfr name I supplied to go through (e.g. try 0x0001 for the VID, and you'll get "Fry's Electronics")
Thank you @s-ol, and sorry for the delay!
This adds
supervisor.set_usb_identification(manufacturer: Optional[str] = None, product: Optional[str] = None, vid: int = -1, pid: int = -1)
This function can be called to override the build-type settings for USB_VID, USB_PID, USB_MANUFACTURER_NAME, USB_PRODUCT_NAME for the next boot process from
boot.py
.Closes #4404