Comms port dropping after uploading

Status
Not open for further replies.

Daba

Member
I'm having a problem that after the IDE uploads my sketch to the Teensy, it drops the USB port for about 10 seconds.

It re-establishes itself, but if I'm using the serial monitor, I have to put a delay(15000) in my setup() so that I can capture the first of the Serial output - cosmetically a pain, but just about tolerable.

I also get several (exactly 8) "gettimeofday" error messages delivered on the IDE immediately after uploading.

"Sketch uses 17772 bytes (6%) of program storage space. Maximum is 262144 bytes.
Global variables use 5252 bytes (8%) of dynamic memory, leaving 60284 bytes for local variables. Maximum is 65536 bytes.
gettimeofday
gettimeofday
gettimeofday
gettimeofday
gettimeofday
gettimeofday
gettimeofday
gettimeofday
"

The 2 issues may be related, but I'm not clever enough to understand what's going on.... Anyone know how to cure these issues...

Arduino IDE 1.8.5
Teensy 3.2
Windows 7 Pro
 
The gettimeofday message is due to your using Windows 7, which does not have some of the same underlying functionality as Linux, Mac and now Windows 10... There have been a few threads on this, including:
https://forum.pjrc.com/threads/5314...yduino-1-4-2-always-this-gettimeofday-message

10 seconds seams excessive. Note: unlike some other boards like Arduino UNO, which has a separate chip (either another AVR board or an FTDI chip), that handles the USB, the processors on the Teensy handle the USB, so when they are reset, the USB drops until the board reinitialized enough to reestablish USB. Note this is not unique to Teensy. Some other Arduino boards like the older Leonardo also have/had processors that handled the USB.

To handle this, Arduino built in a mechanism that allows you to detect when the Serial port is ready. The value of the Serial object will be TRUE when it is valid...

So for example if your program starts up like:

Code:
void setup() {
    while (!Serial) ;
    Serial.begin(115200)
    Serial.println("Teeny here");
...
The startup code will wait until the Serial object has been created before it will try to print something.

Note: I personally don't start of quite this way as this code will hang forever waiting for Serial to start and I have seen too many reports from people saying something is busted, my program works after I program it, but then when I power it up again it does not work....

So I normally do it more like: while (!Serial && (millis() < 5000)) ; // wait up to 5 seconds for serial port before continuing...
 
Great reply KurtE, thanks.

I've not seen the USB dropping before this - first time with a Teensy, having used exclusively Uno's and Nano's before.

As stated, it's just about tolerable, but those delays add up to a lot when I'm trying to get things working, as I make a huge amount of mistakes and I'm uploading probably 10 to 20 times an hour !! So much to learn ....
 
Please give 1.43-beta3 a try.

https://forum.pjrc.com/threads/53549-Teensyduino-1-43-Beta-1

The "gettimeofday" message is removed in this new version. It was just leftover debugging code which I forgot to remove. Windows XP & 7 lack high res timestamp functions, so it has to fall back to the standard gettimeofday function which has limited resolution on Windows (but works very well on Mac & Linux).

I'm afraid there's little I can do about slowness of Windows 7. I can tell you Microsoft fixed *many* USB problems for Windows 10. If you have a Windows 10 machine or could consider upgrading, I believe you'll find it works better than Windows 7.
 
Status
Not open for further replies.
Back
Top