Modifying USBHost_t36 to support host mode for USB1

Status
Not open for further replies.

lukexyz

Active member
Both USB1 (the usual device mode port) and USB2 (the usual host mode port) on Teensy 4.1 technically support USB OTG. However, USB1 is configured to run in device mode by the bootloader, and USBHost_t36 only supports one port (USB2), and only in host mode.

I previously posted a thread asking about how to switch USB1 into host mode, so that two USB devices can be connected to Teensy 4.1 without using a USB hub:

https://forum.pjrc.com/threads/66640-USB-Host-port-hardware-questions

I tried modifying USBHost_t36 to support USB1 as well as USB2. These changes default to USB2, so they should introduce no behavioral changes compared to the latest git version of USBHost_t36.

https://github.com/lukehutch/USBHost_t36/commit/49fbdee11b5de428cd56301d763bfb24eb96c117

However, for some reason these changes don't work (I can't see USB devices on USB2 with these changes). C++ is not my strongest language. Is anyone able to help figure out what's wrong with these changes?

I had to make a few slightly dodgy changes, because of assumptions that were made in the code of USBHost_t36 that there would only ever be one USB host port.

Actually the effort to make these changes seemed to illustrate that USBHost_t36 is in need of an audit of class structure, memory ownership, and object/memory lifecycle, including how classes are related to each other, what memory allocations should belong to instances, and what memory allocations should be global/static. For example, I had to add a host_port field to USBHost, and make its methods non-static so they could access that instance variable, but then some methods (enumeration() and isr()) could not be passed as callbacks, since they became instance methods. I had to hackiily write the latest USBHost object into a 2-element array (one for USB1, one for USB2) right before the callback was submitted, in order to maintain the current semantics.

The changes linked above would be a good starting point in figuring out how to better refactor USBHost_t36 to support a more generic and flexible model of USB host mode support.

I would appreciate help figuring out how to get this done in the right way.
 
I have a much better version of these library changes to enable USB1 in host mode, in this pull request:

https://github.com/PaulStoffregen/USBHost_t36/pull/61

I really need someone's help to resolve a problem with these changes. If anyone is familiar with the USBHost_t36 library and how the USB system works on this chip, I would appreciate it if you could please take a look at the issue I describe in the PR.
 
Status
Not open for further replies.
Back
Top