Upload fails specifically every second time - Teensy 4.1

I’ve done a lot for years with Teensy 3.2 and Teensy 4.0. I recently started playing with Teensy 4.1, and I get a strange behaviour on upload. As the title suggests, it fails specifically every second time. When it fails, it looks like this:

Building in release mode
Linking .pio/build/teensy41/firmware.elf
Checking size .pio/build/teensy41/firmware.elf
Building .pio/build/teensy41/firmware.hex
Configuring upload protocol...
AVAILABLE: jlink, teensy-cli, teensy-gui
CURRENT: upload_protocol = teensy-cli
Rebooting...
Uploading .pio/build/teensy41/firmware.hex
Teensy Loader, Command Line, Version 2.2
Read ".pio/build/teensy41/firmware.hex": 333820 bytes, 16.4% usage
Error opening USB device: Operation timed out
Waiting for Teensy device...
(hint: press the reset button)
Found HalfKay Bootloader
Read ".pio/build/teensy41/firmware.hex": 333820 bytes, 16.4% usage
error writing to Teensy
*** [upload] Error 1
Programming...========================== [FAILED] Took 4.35 seconds ==========================

If I switch to the teensy-gui uploader, it uploads every time, but the serial monitor doesn’t resume:
Error: [Errno 2] could not open port /dev/cu.usbmodem117574901: [Errno 2] No such file or directory: ‘/dev/cu.usbmodem117574901’

But I just press up and enter and it’s fine. It seems in either case it could be a timeout waiting for the socket to become available.

Thoughts?

And this happens with the most basic blinky example code too?

Teensy platform is updated to the latest version? CLIpio pkg update -g -p teensy

Everything is up to date. I made a blink sketch, that worked fine every time. Then I added NativeEthernet, still worked every time… then I added NativeEthernetUdp - that did it. Failed every other time, same as before. Here’s my code if you want to try and replicate it (obviously must be on a Teensy 4.1 with ethernet):

#include <Arduino.h>
#include <NativeEthernet.h>
#include <NativeEthernetUdp.h>

EthernetUDP udp;

uint8_t mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0xC2, 0xAA };
IPAddress ip(192,168,30,27);

uint32_t timerObject;
bool flipFlop;

void setup() {
pinMode(13,OUTPUT);

Ethernet.begin(mac,ip);
udp.begin(1000);

} // END SETUP

void loop() {

if (timerObject<millis()) {
timerObject = millis() + 1000;
flipFlop = !flipFlop;
digitalWrite(13,flipFlop);
}

} // END LOOP

Bump. Any thoughts folks?

Does this happen in the Arduino IDE too?

I had to update the Arduino IDE as it’s been a good five years since I’ve used it, but then it appears to just use Teensy Loader anyway. Uploads every time.

I just tried a clean Atom & PlatformIO install on a spare Mac Mini, running the latest macOS. Exactly the same problem presents.

Hi There,

I’m getting exactly the same thing here, did you find a solution?

Cheers

Andy

Negative.

And it’s not just NativeEthernetUdp. It’s also happening on projects without that library.

I’m not sure who manages the Teensy framework on platformio - perhaps we should be rattling cages over at forum.pjrc.com ?

Such an odd problem though.

So it’s been a year… new MacBook Pro, now using PlatformIO on VScode instead of Atom. Same issue persists if I use teensy-cli.

The only improvement is if I use teensy-gui the serial monitor does automatically reconnect afterward.

Any thoughts?

Did you track this issue in https://github.com/platformio/platform-teensy/issues/? That’s where the developers ar at.