PlatformIO Community

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