Burn Bootloader failing. PlatformIO bug?

Hi
I am trying to get “Burn Bootloader” working so I no longer have to keep using Arduino IDE to do this step.

I am using Arduino as ISP to successfully program my ATMega328p, but the issue comes when I try to burn the bootloader from platformio. When I try click the button I get this error
avrdude error: cannot open port -b19200: The system cannot find the file specified.
image

My platformio.ini file is

[env]
platform = atmelavr
board = ATmega328P
framework = arduino
board_hardware.oscillator = External
board_build.f_cpu = 8000000L
board_hardware.bod = disabled
board_hardware.eesave = yes
build_unflags = -flto
board_hardware.uart = uart0

[env:Arduino_as_ISP]
upload_protocol = stk500v1
upload_speed = 19200

upload_flags =
    -P$UPLOAD_PORT
    -b$UPLOAD_SPEED

I am guessing its an issue with forming the command, but I have not worked out a way to see what command platformio is generating to see where the error is. Does anything know whats going on here or if this is a bug with platformio itself?

I am on version v3.2.0

You reference $UPLOAD_PORT but don’t set upload_port = COM... in your platformio.ini. So this flag will be empty and avrdude will see an invocation of avrdude [..] -P -b19200, thus taking -b19200 as the port.

1 Like

To my knowledge that should not matter as it picks it up automatically hence why upload works fine. But even after manually I get this error

avrdude error: cannot open port \\.\COM[4]: The system cannot find the file specified.


avrdude error: unable to open programmer stk500v1 on port COM[4]

avrdude done.  Thank you.

*** [bootloader] Error 1

image

But again, COM4 is there as after this error I clicked on upload and it worked perfectly without touching the config further.

[env:Arduino_as_ISP]
upload_protocol = stk500v1
upload_speed = 19200
upload_port = COM[4]

upload_flags =
    -P$UPLOAD_PORT
    -b$UPLOAD_SPEED

Turns out the example from here is incorrect for this use case, or is not parsing it correctly for this use case upload_port — PlatformIO latest documentation

You cannot use COM[x], you need to use COMx. After specifying it without the brackets it worked perfectly fine. Still seems odd that I need to include it, it should be able to pick up up automatically like it does when you click upload or upload and monitor.

[env:Arduino_as_ISP]
upload_protocol = stk500v1
upload_speed = 19200
upload_port = COM4 ; Needed for flashing device

upload_flags =
    -P$UPLOAD_PORT
    -b$UPLOAD_SPEED