Force windows to re-enumerate teensy USB device

AndyA

Well-known member
I know this is a bit of an odd question but does anyone know of a way that I could force windows to re-scan / re-enumerate the teensy 4 USB device as if the cable had been disconnected and re-connected?

I've tried re-initialising the USB interface (having first cleared the init done flag) but that doesn't do it.

I could always resort to a USB switch in the path to effectively disconnect and re-connect the device but it would be nice to avoid additional hardware if possible.
 
If resetting the device would do what you need, you could use tyCommander:

1706877386304.png
 
If resetting the device would do what you need, you could use tyCommander:
Unfortunately not, I need to keep the rest of the system running, but make the host PC think it's been removed and re-connected.
 
using the device manager, is de- and re-install the comport not an option?
Possibly. But ideally I'd like to trigger this from the teensy itself.

This is part of an attempt to automate some testing systems, the more I can build into the teensy rather than relying on operators or software running on the PC the better. The more I can put in the teensy where others can't mess with it the better. It may not be possible to make things completely idiot proof but you can at least require them to be a higher quality of idiot :)
 
Teensy's USB stack doesn't really support fully reinitializing all its internal variables. With that in mind, here's an imperfect way.

Code:
extern "C" void usb_init(void);

void setup() {
  while (!Serial) ; // wait
  Serial.println("Hello World #1");

  delay(5000);
  USB1_USBCMD = 0; // disconnect USB
  delay(50);       // long enough for PC+hubs to detect
 
  usb_init();
  while (!Serial) ; // doesn't wait
  Serial.println("Hello World #2"); // won't see this
  delay(3000);
  Serial.println("Hello World #3");
}

void loop() {
}
 
The method by Paul in #6 works also for MTP responder to reset MTP after writing files to disk!
Only drawback is that open Teensy Filexplorer will disappear and has to be opened again.
If that is accepted behavior no more sendEvent is needed
 
The method by Paul in #6 works also for MTP responder to reset MTP after writing files to disk!
Only drawback is that open Teensy Filexplorer will disappear and has to be opened again.
If that is accepted behavior no more sendEvent is needed
I'd probably still use sendEvent for that although this may be a good fallback option. Another element of this is making some horrible hacks to the USB drivers so that the USB device type can be changed on the fly. We don't normally want to expose the SD card via MTP but want the option to go into a debug mode where it is visible.
 
Back
Top