There's more to adding a new USB device than editing usb desc.h

mborgerson

Well-known member
In a now-closed thread, @PaulStoffregen said:

But that is a lot of work and requires a pretty deep dive into the details of crafting USB devices. In Teensy 4.0 you still need some expertise, but it's meant to be much easier with editing 1 file, just usb_desc.h. Even if you don't need the more capable hardware, buying a new board might still be worthwhile because with 12 years newer hardware comes newer software that was built upon the learning experiences from those early products.

In the process of developing my USBTMC (USB Test and Measurement Class) driver, I have found it necessary to also modify usb_desc.c to insert the descriptor data from usb_desc.h into the executed code that sets up the usb devices. This involved adding code to build the device descriptor byte array at two places in the 2897 lines of usb_desc.c. If you should embark on a similar project, I strongly recommend a code editor that supports code folding. Usb_desc.c is essentially a long series of mutually exclusive " #if, #elseif" statements that use your new definitions in usb_desc.h to build the descriptor array. You can only confine your changes to usb_desc.h if you are putting together a new combination of existing usb types already available in usb_desc.c.

A secondary problem is that if you want your new device to appear in the drop-down list under USB type in the Arduio IDE, you will need to modify Boards.txt. There are some issues with this process:

1. The IDE will not recognize your changes to boards.txt unless you delete some temporary files--and the suggestion at the start of boards.txt was no longer relevant when I last checked two weeks ago.
2. When adding a new USB device type, you need to respect the limits on the number of endpoints. While a host driver can handle lots of endpoints, the device code is limited to endpoints 2 through 7. (The usb hardware only allows 8 endpoints. All devices use EP 0 for control and EP 1 is reserved for PJRC usage.)
3. I ran into a lot of issues when I tried to add lines for my new Serial + USBTMC [Experimental] driver to boards.txt. It seems that adding new lines to boards.txt spoils something in the parsing of the file. My workaround is to keep the same number of lines by re-purposing the otherwise-unused Triple Serial menu item. I changed only the device-name string in boards.txt. My device name now appears in the drop-down list while build type and upload ports still refer to USB_TRIPLE_SERIAL. I think the USB Serial part of my device still works because the triple-serial means the driver builds with the required CDC support. (There's still a bit of mystery about what is happening inside the build process. OK---there's LOT of mystery involved!)

I suspect that the problems noted above may have figured into the long development time for the USB Serial+MTP driver.

NOTE: I do a lot of my data wrangling in MATLAB on my PC. USB MTP transfer of data files to the PC is at the top of my list of great new capabilities for the Teensy 3.x and 4.x. My kudos to all who have contributed to the MTP project.
 
Are you planning to publish your USB TMC code? Or is it a private project?

If it's public, would you like to see it eventually merged in future Teensyduino releases?
 
This project is definitely going to be published---it's free of the NDAs that hinder the distribution of the FLIR Boson source code.

It's a Work-In-Progress that will probably occupy a good part of my non-travel time over the next several months. I've just today gotten the Host T4.1 to get two-way packet comms established with the device teensy. The first release will probably bare-bones proof of concept without the USBTMC packet overhead. Although the USBTMC spec is only 34 pages, I will postpone that implementation until I'm confident that I can get the host T4.1 to collect high-bandwidth data from at least two devices connected through a powered hub. My next goal is to have two T4.x devices under the control of a T4.1 Host with about 4MB/second collected from each device and written to SD. I also need to get a better handle on a minimum set of control transfers.

When at least USBTMC_LIte is stable and I can recruit some beta testers to discover the bugs, I think it might be a useful addition to Teenysduino for users with extreme data collection needs. It will allow more CPU and peripheral bandwidth at the device level by using multiple T4.0s to collect with 95% of their CPU and Peripheral bandwidth to concentrate on the data collection, buffering and pre-processing while the host excercises control and handles SD card storage.
 
Back
Top