USB Custom Descriptors #16980
Replies: 2 comments 3 replies
-
You might want to watch the demo Damien presented on using USBDevice. You're right that the 'new way' allows you to modify the descriptors dynamically, though you'll probably find it much better to use an FTDI cable to connect to the REPL (otherwise, if your REPL is accessed over the same USB, the connection will drop when you update the descriptors). If you're not already aware, there are some good examples in micropython-lib/usb. There should be no need to build firmware to modify descriptors. |
Beta Was this translation helpful? Give feedback.
-
It looks like you're using MacOS, so I don't know how easily this is done there. But on Linux, the board with |
Beta Was this translation helpful? Give feedback.
-
I have a project with 20 or so RP2350 modules in a single system. The USB interface isn't used in the application, but for development and testing. It is becoming a pain to sort out which com port is which module.
I found a helpful discussion here by user Hippy. This substantially works, and I understand it well. At the end of that discussion it is noted that version 1.23 now includes dynamic USB drivers. Hippy points out: "Crafting initial versions of those is somewhat more complicated than copying what the MicroPython defaults are." I found some examples of dynamic USB code, but they are for changing more advanced aspects of the interface. I can't find any examples, complicated or not, of how to just change the USB descriptors (and serial number).
With that background, here is what I'd like to accomplish. By assigning a custom product descriptor, I can easily grab the desired com port from scripts on the PC. For example, "proto_meter_00, _01, _02, _03", etc. Here's an example I built last night:
Taking this approach, however, means that I would have to build a separate UF2 firmware file for each module. A smoother approach would be to make the product descriptor constant, say "proto_meter", and tweak the serial number by appending the meter number to the existing serial number (note that the meter number is read from DIP switches on each module). Ideally I'd like to be able to generate USB descriptors like below and only have a single UF2 firmware build (manually tweaked example of the above):
Questions:
(1) [NEW WAY] Are there any examples of changing USB descriptors using the dynamic USB device feature of the latest 1.23 release?
(2) [OLD WAY]
(2a) Applying the approach suggested by Mr Hippy raises a few build issues outside my previous MicroPython experiences. Other than replacing the CMakeLists.txt file in the rp2 directory, what's the usual process for dealing with custom cmake files? I tried to put CMakeLists.txt in my custom build folder, no joy. Then I extracted just the necessary bits into the .cmake file in the custom board folder, but that didn't work either.
(2b) Reading the documentation for the rp2 port closer, it states that the main way to build things is to use cmake, and the make commands are merely a convenience. But I couldn't figure out how to do a cmake-only build, and there are no examples of such that I could find. Perhaps if I knew that, I could have solved (2a) on my own.
(2c) Unlike Hippy, I put my changed USB files in my custom board folder rather than the main rp2 directory. But otherwise I still had to modify the main CMakeLists.txt file in the rp2 folder. But when I looked into changing the serial number, it seems that I have to tweak
mp_usbd_port_get_serial_number()
in fileusbd.c
. Is there an accepted way to localize all these changes to only the custom board folder? I'd like to not touch the main MicroPython code at all, and limit the changes to the custom board folder. But I don't know how to do that.Beta Was this translation helpful? Give feedback.
All reactions