Uploading to Micro\Leonardo

Checking in for 2021 to say this is still an issue. It sends reset, dutifully waits for the new port, and then promptly dies with:

Waiting for the new upload port…
Uploading .pio\build\leonardo\firmware.hex
avrdude: ser_open(): can’t open device “\.\COM5”: The system cannot find the file specified.

I have similar issues with the Arduino IDE, but only sometimes. So I suspect there is a race and that sleeping for a second or two after the new port is detected will fix it. How do I test that?

Edit: Found pioupload.py, tried my sleep hack after it discovers the new port. Inititally I thought did not work but after much fussing, trying different bootloaders, etc. I started experimenting with avrdude from the commandline, triggering the bootloader/serial switch with the reset button, and realized that it the delay actually needs to be very long. Nearly 3s of sleep, when you add up the other smaller ones that are already in there.

So, yeah, this is a race condition, and it is probably somewhat (if not highly) system-dependent. Basically pioupload.py watches for the new serial port to appear, and then more or less immediately launches avrdude. This doesn’t work on my system - Windows is not finished “doing stuff” with the serial port, and so avrdude cannot open it.

There is probably a more robust solution than my current kludge of “sleep(2.8)” just after the line where the new port is found. So, in that loop, it seems util.get_serial_ports() is necessary but not sufficient to narrow down precisely when things need to proceed to avrdude. And of course you can’t wait too long because then the bootloader sketch times out. So it’s a pretty fussy thing.

Hello, Im experiencing this issue too. Im running windows 10, it appears the upload process waits just long enough for the bootloader to timeout. Quite frustrating,

COM 12: Arduino Leonardo

Configuring upload protocol...
CURRENT: upload_protocol = avr109
Looking for upload port...
Auto-detected: COM12
Forcing reset using 1200bps open/close on port COM12

COM 12 disappears from device manager, COM 13: Leonardo Bootloader appears

Waiting for the new upload port...

COM 13 disappears, COM 12 Arduino Leonardo appears

Uploading .pio\build\leonardo\firmware.hex
avrdude: ser_open(): can't open device "\\.\COM13": The system cannot find the file specified.

it seems to be waiting for COM 13 to disconnect before attempting to upload

1 Like

Solved - not perfectly but works.
I had the same issue, I found that it PlatformIO spends too much time detecting new upload port thus Arduino Leonardo is leaving boot mode. The workaround I found was to leave only one Serial port in device manager. I had 2 bluetooth ports open and they are very unresponsive in terms of detection of the port state. When I disabled Bluetooth - left only one serial port was left then upload works perfectly.
Better solution would be to modify 32U4 bootloader to set more time being spent in bootloader mode.

Hi all, I have a similar problem, even though I’m using a Raspberry Pico. Uploading from PIO worked fine for many days, but suddenly it stopped working. The Pico creates a COM port when connected (COM7), which appears in Device Manager on Windows 10, but PIO cannot use it, neither to upload firmware nor via a serial terminal.

The moment PIO attempts to upload the firmware, the COM port disappears, and the following is displayed:

Configuring upload protocol...
AVAILABLE: cmsis-dap, jlink, picotool, raspberrypi-swd      
CURRENT: upload_protocol = picotool
Looking for upload port...
Auto-detected: COM7
Forcing reset using 1200bps open/close on port COM7
Uploading .pio\build\pico\firmware.elf
rp2040load 1.0.1 - compiled with go1.15.8
*** [upload] Error 1
=============== [FAILED] Took 12.56 seconds ===============
The terminal process "C:\Users\micro\.platformio\penv\Scripts\platformio.exe 'run', '--target', 'upload'" terminated with exit code: 1.

I disabled Bluetooth as suggested above, leaving COM7 as the only COM port in Device Manager, but it did not help. Any idea?

When you manually copy the .pio\build\pico\firmware.uf2 file on the Pico (via BOOTSEL pressed on plug-in), does it work thereafter?