Hi
I am currently using the CPU_RESTART macro and it works quite reliably.
However, if the Teensy is connected to the PC over USB, the Virtual COMM port on the PC sometimes becomes inaccessible after the RESTART. I can still see it in Device manager but any Serial Terminal will report "Serial Port not found".
The solution is to disconnect the USB cable and reconnect it.
This brings me to the assumption that the USB host or drivers are not properly handling/recognizing what's happening and are going into an inconsistent state. This shouldn't be a total surprise since we're doing a brute force RESET on the processor followed by a very quick re-connect (on reboot), without ever gracefully perming (or allowing time for) a disconnect on the USB host.
With this in mind, is there any function in the Teensy library that we can call to send a USB disconnect command to the host, before we do the actual RESET?
I'm not familiar with the USB stack that teensy uses so any pointers would be quite helpful.
I am assuming that by sending a USB disconnect and then reboot, it will force both the host and teensy to handshake with each other, from a clean state.
Thank you in advance for any information on this.
EDIT:
Actually dug into the libraries and found some more info inside "hardware\teensy\cores\teensy3\usb_serial.h":
void begin(long) { /* TODO: call a function that tries to wait for enumeration */ };
void end() { /* TODO: flush output and shut down USB port */ };
I assume USB is being initialized at boot (tried adding a delay at the start of setup() but the teensy usb seems to be recognized even before this).
I also found the USB registers in kinetis.h but it's unclear what needs to be set. I was unable to find a datasheet explaining these.
In "hardware\teensy\
cores\usb_serial\usb_api.cpp" there is much more comprehensive class which waits for enumeration on the begin() procedure and calls usb_shutdown() on the end() procedure but I think this is for ATMEL.
So I'm back to asking for your help here. Any pointers (even if just for a manual or sample) would be greatly appreciated.
Thank you very much