PlatformIO Community

Uploading to Micro\Leonardo

Hi!

I am trying to program a Arduino Micro and having a problem that appears to be at least 2-3 years old with no clear resolution. There is really old threads here discussing it but it is unclear if it was ever addressed. I have spent 2-3 hours now messing around, editing pioupload.py, etc.

Is there any update on this problem? Was it fixed?

The specific issue:
When you upload it doesnt wait long enough for the software USB to re-enumerate, then it selects the wrong port. I tried a pioupload edit that looked promising, but it didnt appear to actually work, even though the code looked promising. I would add some links but I am afraid the forum will detect it as spam since I am new!

Configuring upload protocol... AVAILABLE: avr109 CURRENT: upload_protocol = avr109 Looking for upload port... Auto-detected: COM10 Forcing reset using 1200bps open/close on port COM10 Waiting for the new upload port... result: 'COM11' Uploading .pio\build\micro\firmware.hex avrdude: ser_open(): can't open device "\\.\COM11": The system cannot find the file specified.

https://github.com/platformio/platform-atmelavr/issues/55
This didnt seem to help


This also didnt seem to work. The python code was running because I had to update the print statements to python 3 syntax, but the wait loop didnt appear to work.

I am afraid I am wasting time if there is a known solution somewhere.

In the meantime I guess I will try to figure out how to upload hex compiled by platform io in VS code using the arduino IDE… Annoying manual workflow step!

Thanks to anyone who can help!!!

Has anyone EVER used Platform IO with an Arduino Leonardo or Micro?

I for one have.

From the looks of the responsible for uploading, it really shouldn’t do that… it basically gets the list of ports currently present, triggers the bootloader reset, and then connects to serial port not previously present… so unless you have multiple boards connected, and reset the wrong one initially, or somehow manage to connect another serial type device between the reset and the rescan, it should be fine. Having said that, I’ll try again with my Micro on Windows again tomorrow if I remember.

btw, I know it’s quiet on this forum at times, and it can be frustrating when you have a problem that you don’t seem to be able to solve, but using the search feature would have answered your question pretty quickly as to if anyone has ever used an Arduino Leonardo or Arduino Micro with PlatformIO! :open_mouth:

https://github.com/platformio/platform-atmelavr/blob/13421fc974a4eb60ba2ef5d60a15d8e8fd7177a6/builder/main.py#L74-L80

Thank you for the report of having programmed a Micro\Leonardo!

I only have the one micro right now.

I am sure the WaitForNewSerialPort function is running because I can make it stop working with long sleep() commands, which do not help and result in a bunch of errors.

I am afraid I am not sure what you want me to infer from the linked code. My main.py does not have those lines in it. My main.py also seems to be a different file in a different folder. I do not have a /atmelavr/ folder. I do have the atmelavr platform installed though.

This was a fresh install of platform io. I just have blink code in it. I will try it on my mac or another computer. Digging around in the config\code for an IDE add-on that is supposed to just work seems like a poor use of time to me.

Thank you for your reply.

Same problem on both computers I have on hand.

It is weird: on the arduino IDE it takes about 5 seconds for the entire programming cycle. It is quite fast.

On Platform.io it takes 25 seconds to fail.

Bumping for visibility. A weekend in the Arduino IDE really reminds one how poor that experience is!

1 Like
[env:micro]
platform = atmelavr
board = micro
framework = arduino

This is my platformio.ini

Sorry for putting you through that… have been offline the last few days.

Right, so just tried an upload with the Micro clone I have on Windows (10) and it worked fine. I see from the verbose log it initially identified COM17 and then COM16 on the reset.

In you case, what is the device it’s detecting at port COM11? Or is it the correct serial/COM port, but avrdude isn’t able to actually do the upload for some reason? Do you have anything connected to that serial port like a terminal, or serial monitor?

Code (with an led + resistor attached between GND and 2):

#include <Arduino.h>

#define LED_PIN 2

void setup() {
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);
}

void loop() {
  digitalWrite(LED_PIN, !digitalRead(LED_PIN));
  delay(500);
}

Upload log:

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/micro.html
PLATFORM: Atmel AVR 2.0.0 > Arduino Micro
HARDWARE: ATMEGA32U4 16MHz, 2.50KB RAM, 28KB Flash
PACKAGES: framework-arduino-avr 5.0.0, toolchain-atmelavr 1.50400.190710 (5.4.0), tool-avrdude 1.60300.190424 (6.3.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies...    
No dependencies
Building in release mode
Compiling .pio\build\micro\src\main.cpp.o
Linking .pio\build\micro\firmware.elf
Checking size .pio\build\micro\firmware.elf
Building .pio\build\micro\firmware.hex
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   5.8% (used 149 bytes from 2560 bytes)
Flash: [=         ]  14.8% (used 4234 bytes from 28672 bytes)
Configuring upload protocol...
AVAILABLE: avr109
CURRENT: upload_protocol = avr109
Looking for upload port...
Auto-detected: COM13
Forcing reset using 1200bps open/close on port COM13
Waiting for the new upload port...
Uploading .pio\build\micro\firmware.hex

Connecting to programmer: .
Found programmer: Id = "CATERIN"; type = S
    Software Version = 1.0; No Hardware Version given.
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=128 bytes.

Programmer supports the following devices:
    Device code: 0x44

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% -0.00s

avrdude: Device signature = 0x1e9587 (probably m32u4)
avrdude: reading input file ".pio\build\micro\firmware.hex"
avrdude: writing flash (4234 bytes):

Writing | ################################################## | 100% 0.33s

avrdude: 4234 bytes of flash written
avrdude: verifying flash memory against .pio\build\micro\firmware.hex:
avrdude: load data flash data from input file .pio\build\micro\firmware.hex:
avrdude: input file .pio\build\micro\firmware.hex contains 4234 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.04s

avrdude: verifying ...
avrdude: 4234 bytes of flash verified

avrdude: safemode: Fuses OK (E:CB, H:D8, L:FF)

avrdude done.  Thank you.

========================================================== [SUCCESS] Took 12.35 seconds ==========================================================

Environment              Status    Duration
-----------------------  --------  ------------
nanoatmega328            IGNORED
uno                      IGNORED
nrf52_dk                 IGNORED
wemos d1 esp32           IGNORED
megaatmega2560           IGNORED
megaatmega1280           IGNORED
c_mate_r3_No_Bootloader  IGNORED
nodemcuv2                IGNORED
micro                    SUCCESS   00:00:12.350
esp12e-USB0              IGNORED
esp12e-USB1              IGNORED
genericSTM32F103CB       IGNORED
esp32dev-release         IGNORED
esp32dev-dev             IGNORED
loraduino                IGNORED
bg96                     IGNORED
esp01_1m                 IGNORED
=========================================================== 1 succeeded in 00:00:12.350 =========================================================== 

Snippet from verbose upload:

Auto-detected: COM17
Forcing reset using 1200bps open/close on port COM17
Waiting for the new upload port...
avrdude -v -p atmega32u4 -C C:\Users\Peter\.platformio\packages\tool-avrdude\avrdude.conf -c avr109 -b 57600 -D -P "COM16" -U flash:w:.pio\build\micro\firmware.hex:i

Hey. Thanks! I will try this today.

Where do I add the verbose flag? Is it in the main Code settings or in platform.io settings somewhere?

Thanks!

After google searching a bit I am still uncertain how to set the verbose flag for avr_dude output. I find info on the PIO CLI in general, but nothing specific about setting the compiler output to verbose.

Anyway I am continuing to fail at getting this to work. Here is what it does now ( same as in first post).

I have the Arduino Micro detected on (in this case) COM19. My code compiles. It is simply blink.ino.

Based on the same process in Arduino IDE, it doesnt seem to be accepting the COM port once it returns to availability. In the Arduino IDE it takes 5-8 seconds total for the entire program cycle.

When I select upload it does the following. Note the program lights on the Micro blink and it appears to be being programmed, but it does not get programmed.

> Executing task in folder micro-hi: C:\Users\Robert\.platformio\penv\Scripts\platformio.exe run --target upload <


Processing micro (platform: atmelavr; board: micro; framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/micro.html
PLATFORM: Atmel AVR 2.0.0 > Arduino Micro
HARDWARE: ATMEGA32U4 16MHz, 2.50KB RAM, 28KB Flash
PACKAGES: toolchain-atmelavr 1.50400.190710 (5.4.0), framework-arduino-avr 5.0.0, tool-avrdude 1.60300.190424 (6.3.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies...    
No dependencies
Building in release mode    
Checking size .pio\build\micro\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
DATA:    [=         ]   5.8% (used 149 bytes from 2560 bytes)
PROGRAM: [=         ]  14.4% (used 4132 bytes from 28672 bytes)
Configuring upload protocol...
AVAILABLE: avr109
CURRENT: upload_protocol = avr109
Looking for upload port...
Auto-detected: COM19
Forcing reset using 1200bps open/close on port COM19
Waiting for the new upload port...
result: 'COM18'
Uploading .pio\build\micro\firmware.hex
avrdude: ser_open(): can't open device "\\.\COM18": The system cannot find the file specified.



avrdude done.  Thank you.

*** [upload] Error 1
===================================================== [FAILED] Took 21.91 seconds =====================================================
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

Plot thickens. I tried it on my iMac and it works. I am going to try a complete uninstall of VS Code. I guess if I cannot get it running on the PC I will try to run it in a Linux VM on the PC. Still, I am interested in trying a bit more on the PC.

Frustrating because I want to do this project on ‘my main pc’. Here is the output from the working mac:

 Executing task: platformio run --target upload <

Processing micro (platform: atmelavr; board: micro; framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/micro.html
PLATFORM: Atmel AVR 2.0.0 > Arduino Micro
HARDWARE: ATMEGA32U4 16MHz, 2.50KB RAM, 28KB Flash
PACKAGES: framework-arduino-avr 5.0.0, toolchain-atmelavr 1.50400.190710 (5.4.0), tool-avrdude 1.60300.190628 (6.3.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Checking size .pio/build/micro/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
DATA:    [=         ]   5.8% (used 149 bytes from 2560 bytes)
PROGRAM: [=         ]  12.6% (used 3620 bytes from 28672 bytes)
Configuring upload protocol...
AVAILABLE: avr109
CURRENT: upload_protocol = avr109
Looking for upload port...
Auto-detected: /dev/cu.usbmodemFD141
Forcing reset using 1200bps open/close on port /dev/cu.usbmodemFD141
Waiting for the new upload port...
Uploading .pio/build/micro/firmware.hex

Connecting to programmer: .
Found programmer: Id = "CATERIN"; type = S
    Software Version = 1.0; No Hardware Version given.
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=128 bytes.

Programmer supports the following devices:
    Device code: 0x44

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9587 (probably m32u4)
avrdude: reading input file ".pio/build/micro/firmware.hex"
avrdude: writing flash (3620 bytes):

Writing | ################################################## | 100% 0.28s

avrdude: 3620 bytes of flash written
avrdude: verifying flash memory against .pio/build/micro/firmware.hex:
avrdude: load data flash data from input file .pio/build/micro/firmware.hex:
avrdude: input file .pio/build/micro/firmware.hex contains 3620 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.03s

avrdude: verifying ...
avrdude: 3620 bytes of flash verified

avrdude: safemode: Fuses OK (E:FB, H:D8, L:FF)

avrdude done.  Thank you.

============================================================================ [SUCCESS] Took 4.29 seconds ============================================================================

Terminal will be reused by tasks, press any key to close it.

GOOD NEWS!

Total uninstall of both Code and Code Insiders, as well as manually removing the left over .VScode and .platformio stuff in AppData and user local folders, then re-installing seems to have done the trick.

Oddly after re-install, my first attempt to replace PlatformIO could not find Python, which was mysteriously no longer on my PATH. So I installed the new Python 3.8, added it to the path and then re-installed PlatformIO and now I can program my Arduino Micro from the preferred work PC.

Thanks a lot for your assistance, even though in the end I just needed a clean install. If anyone reading this knows what caused the issue, I would like to know still!

1 Like

That is really weird, but at least you have it working now. Maybe someone else find what the cause is if they encounter it.

For the verbose upload (or verbose build) you either add the -v flag if running the platformio command from the terminal, or use the verbose options in the panel.

image

1 Like

Hey, Thanks!
I did actually figure out the -v flag, now that I have dug deeper into platformio.

1 Like

I’m dealing with the same issue. I prefer not to completly whipe and reïnstall my vscode. Here is the verbose upload console output:

CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/leonardo.html
PLATFORM: Atmel AVR 2.2.0 > Arduino Leonardo
HARDWARE: ATMEGA32U4 16MHz, 2.50KB RAM, 28KB Flash
DEBUG: Current (simavr) On-board (simavr)
PACKAGES:

  • framework-arduino-avr 5.0.0
  • tool-avrdude 1.60300.200527 (6.3.0)
  • toolchain-atmelavr 1.50400.190710 (5.4.0)
    LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 5 compatible libraries
    Scanning dependencies…
    Dependency Graph
    |-- 1.0 (C:\Users\basti.platformio\packages\framework-arduino-avr\libraries\Wire)
    Building in release mode
    MethodWrapper([“checkprogsize”], [".pio\build\leonardo\firmware.elf"])
    Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
    RAM: [= ] 12.8% (used 327 bytes from 2560 bytes)
    Flash: [== ] 18.8% (used 5382 bytes from 28672 bytes)
    .pio\build\leonardo\firmware.elf :slight_smile:

section size addr

.data 56 8388864

.text 5326 0

.bss 271 8388920

.comment 48 0

.note.gnu.avr.deviceinfo 64 0

.debug_info 2548 0

.debug_abbrev 2410 0

.debug_line 26 0

.debug_str 881 0

Total 11630
([“upload”], [".pio\build\leonardo\firmware.hex"])
AVAILABLE: avr109
CURRENT: upload_protocol = avr109
BeforeUpload([“upload”], [".pio\build\leonardo\firmware.hex"])
Auto-detected: COM11
Forcing reset using 1200bps open/close on port COM11
Waiting for the new upload port…
avrdude -v -p atmega32u4 -C C:\Users\basti.platformio\packages\tool-avrdude\avrdude.conf -c avr109 -b 57600 -D -P “COM12” -U flash:w:.pio\build\leonardo\firmware.hex:i

avrdude: Version 6.3, compiled on Sep 12 2016 at 17:24:16
Copyright © 2000-2005 Brian Dean
Copyright © 2007-2014 Joerg Wunsch

System wide configuration file is “C:\Users\basti.platformio\packages\tool-avrdude\avrdude.conf”

Using Port : COM12
Using Programmer : avr109
Overriding Baud Rate : 57600
avrdude: ser_open(): can’t open device “\.\COM12”: Het systeem kan het opgegeven bestand niet vinden.

avrdude done. Thank you.

*** [upload] Error 1

I wonder if there is a timing issue here… possibly there is too much of a delay between the COM12 programming port becoming available and avrdude trying to use it? Do you have the Arduino IDE installed - does it have the same issue?

I am having the same issue, Arduino IDE works perfectly fine, here is the verbose upload output:

Forcing reset using 1200bps open/close on port COM3
PORTS {COM3, COM6, COM9, } / {COM6, COM9, } => {}
PORTS {COM6, COM9, } / {COM4, COM6, COM9, } => {COM4, }
Found upload port: COM4
C:\Users\Ivo\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\Ivo\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega32u4 -cavr109 -PCOM4 -b57600 -D -Uflash:w:C:\Users\Ivo\AppData\Local\Temp\arduino_build_529372/sketch_sep03a.ino.hex:i 

avrdude: Version 6.3-20190619
     Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
     Copyright (c) 2007-2014 Joerg Wunsch

     System wide configuration file is "C:\Users\Ivo\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"

     Using Port                    : COM4
     Using Programmer              : avr109
     Overriding Baud Rate          : 57600
     AVR Part                      : ATmega32U4
     Chip Erase delay              : 9000 us
     PAGEL                         : PD7
     BS2                           : PA0
     RESET disposition             : dedicated
     RETRY pulse                   : SCK
     serial program mode           : yes
     parallel program mode         : yes
     Timeout                       : 200
     StabDelay                     : 100
     CmdexeDelay                   : 25
     SyncLoops                     : 32
     ByteDelay                     : 0
     PollIndex                     : 3
     PollValue                     : 0x53
     Memory Detail                 :

                              Block Poll               Page                       Polled
       Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
       ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
       eeprom        65    20     4    0 no       1024    4      0  9000  9000 0x00 0x00
       flash         65     6   128    0 yes     32768  128    256  4500  4500 0x00 0x00
       lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
       hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
       efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
       lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
       calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
       signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

     Programmer Type : butterfly
     Description     : Atmel AppNote AVR109 Boot Loader

Connecting to programmer: .
Found programmer: Id = "CATERIN"; type = S
Software Version = 1.0; No Hardware Version given.
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=128 bytes.

Programmer supports the following devices:
Device code: 0x44

avrdude: devcode selected: 0x44
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% -0.00s

avrdude: Device signature = 0x1e9587 (probably m32u4)
avrdude: reading input file "C:\Users\Ivo\AppData\Local\Temp\arduino_build_529372/sketch_sep03a.ino.hex"
avrdude: writing flash (3602 bytes):

Writing | ################################################## | 100% 0.28s

avrdude: 3602 bytes of flash written
avrdude: verifying flash memory against C:\Users\Ivo\AppData\Local\Temp\arduino_build_529372/sketch_sep03a.ino.hex:
avrdude: load data flash data from input file C:\Users\Ivo\AppData\Local\Temp\arduino_build_529372/sketch_sep03a.ino.hex:
avrdude: input file C:\Users\Ivo\AppData\Local\Temp\arduino_build_529372/sketch_sep03a.ino.hex contains 3602 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.03s

avrdude: verifying ...
avrdude: 3602 bytes of flash verified

avrdude done.  Thank you.

The PlatformIO output is the same as robear, I also tried completely uninstalling VS Code and PlatformIO, but to no success.

I should also add that for some reason my projects seem to upload much slower compared to some of my colleagues, it takes less than 3 seconds for other PCs in comparasion to 25 for mine.