T4.1 USB challenge (USB drive and programming on one external port...)

AndyMeyer

Active member
I am building a next revision of my Engine Monitor that I previously posted - really getting the design dialed in.

I would love to be able to use a single USB port on the front to both update code on the monitor as well as be able to plug in a USB thumb drive and download data. Port 1 can't be a storage device and you can't reprogram over port 2... Can this be run through a mux where port 1 is normally active and when I go to the data-write page, it switches which Teensy USB port is attached to the port on the front of the unit?

A device I'm looking at is the OnSemi FSUSB104. Put this right next to the iMXRT1062 where the USB ports are located.

A couple of concerns that I'm looking for help with are:
Driving this with an IO pin and that pin changing status during programming?
Signal integrity - any concerns with this with the iMXRT1062? I'd be placing right beside the chip - about as close as I can get it.
What else I might not be seeing?

Regards,

Andy
 
What you want is called USB on the go. Cellphones do this. You can plug USB drives into them or plug them into a computer and they work both ways. The 1062 chip on a Teensy 4.1 does support OTG on both USB ports. So, if the correct software were there, they both could be used in either direction. But, it is my understanding that currently they don't work like this. But, they could. You just have to put together the proper drivers to make it happen.
 
There's not really any "software" support needed for OTG. There's some IO pins to support detecting what sort of device is connected (and if it's a charger), but they're not routed anywhere. So the easiest way to handle it is let the default USB device code run and see if a host has enumerated the Teensy, then if it doesn't happen within a certain amount of time initialize the USB host code (which pokes a register to switch the port to host mode and takes over the IRQ handler).
Switching back and forth between the modes is more difficult, you'd need some sort of external trigger to initiate it.
 
It sounds like this might work then - sweet! And I don't have spin a new board! (I've laid out a PCBA based on the Teensy with all of my I/O - just to see if it could be done. Waiting on a BAT54C from digikey before I power it up and find out if I was successful.

Functionally: I simply go to a page on the UI screen and select "Download to Thumb Drive", swap the port to a host, then mount the drive, check and transfer the files, then unmount, swap the port back to device and display on the screen that the transfer is complete.

Sweet! Now to figure out how to code it up. :) Thank you!
 
Switching the USB pins between the two ports is probably the easiest way to do things. Depending on the selected mode you switch the external port between the two Teensy ports.
USB2 signals are fairly forgiving, I've used a TMUX1574DYY to swap two USB ports over in the past without any issues.

For your application one thing to look out for would be ensuring the power is handled cleanly, in one situation the USB port would be a potential power source, in the other you need to supply power. the OTG spec has a way to do this but you would probably want a simpler if in mode A enable power, if in mode B disable power.

As has been pointed out the hardware does support USB OTG nativly but the driver side would require you to do a fair amount of work. I have in the past mad it so that the second power is a USB device not a host and even managed to have it reconfigure the functionality on that port on the fly. But that was all keeping things as a device so it was simply a case of hacking the current driver. Switching mode would be a whole other level of interesting.
 
Back
Top