mborgerson
Well-known member
In a now-closed thread, @PaulStoffregen said:
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.
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.