Arduino Uno avrdude Option -D added

Hi,

first time Platformio user here.

I had a problem uploading sketches to my Arduino Uno with the mkii ISP using the following configuration:

[env:uno]
platform = atmelavr
board = uno
framework = arduino
upload_protocol = stk500v2
upload_flags = -Pusb
upload_port = usb

Running:

pio run --target upload -e uno_prog -v

Calls avrdude like this:

avrdude -v -p atmega328p -C C:\somepath\avrdude.conf -c stk500v2 -Pusb -b 115200 -P "usb" -D -U flash:w:.pioenvs\uno_prog\firmware.hex:i

And gave me the following error:

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x014c
0x80 != 0x90
avrdude: verification error; content mismatch

Uploading via official Arduino IDE works, using this avrdude command:

somepath/avrdude -Csomepath/avrdude.conf -v -patmega328p -cstk500v2 -Pusb -Uflash:w:test.ino.hex:i

The only difference between the platformio and arduino ide avrdude command is the missing -D option.
Is there a reason platformio is disabling auto erase for flash memory by adding -D to the avrdude command?

Second strange thing is:
After executing the avrdude command without -D manually, uploads with PlatformIO work again.
So it seems it only works if the last upload is not done by Arduino IDE. Does this make any sense?

Thanks! Fixed in

Please re-test with development version GitHub - platformio/platform-atmelavr: Atmel AVR: development platform for PlatformIO

So i changed my ini to this:

[env:uno_prog]
platform = https://github.com/platformio/platform-atmelavr.git
board = uno
framework = arduino
upload_protocol = stk500v2
upload_flags = -Pusb
upload_port = usb

Tried compiling, but it gave me this error:

Submodule 'examples/arduino-external-libs/lib/OneWire' (https://github.com/PaulStoffregen/OneWire.git) registered for path 'examples/arduino-external-libs/lib/OneWire'
Cloning into 'C:/Users/michi/.platformio/platforms/_tmp_installing-r1k8sb-package/examples/arduino-external-libs/lib/OneWire'...
error: no such remote ref b1ef6b994fe005aec9e6b23e05010ce88a93fac3
Fetched in submodule path 'examples/arduino-external-libs/lib/OneWire', but it did not contain b1ef6b994fe005aec9e6b23e05010ce88a93fac3. Direct fetching of that commit failed.
Error: VCS: Could not process command ['git', 'clone', '--recursive', '--depth', '1', 'https://github.com/platformio/platform-atmelavr.git', 'C:\\Users\\michi\\.platformio\\platforms\\_tmp_installing-r1k8sb-package']

Not sure how this can be resolved since i never used submodules yet.

Manually checking them out with:

git clone https://github.com/platformio/platform-atmelavr.git
cd platform-atmelavr
git submodule update --init --recursive

works thought. Also git clone --recursive https://github.com/platformio/platform-atmelavr.git without --depth 1 checks out both the main repo and submodule successfully.

Edit:
This seemed to be a git issue. Updating git resolved that issue.
Still i am not able to resolve my initial issue.

Things i have done:
updated my ini platform to develop
removed .platformio/platforms/atmelavr
runnning pio platform update

pio platform updatePlatform Atmel AVR
--------
Updating atmelavr                        @ 8a06be6        [Up-to-date]
Updating toolchain-atmelavr              @ 1.40902.0      [Up-to-date]
Updating framework-arduinoavr            @ 1.10620.2      [Up-to-date]
Updating tool-avrdude                    @ 1.60300.2      [Up-to-date]

pio run -e uno_prog --target upload -v still results in avrdude -v -p atmega328p -C /home/michi/.platformio/packages/tool-avrdude/avrdude.conf -c stk500v2 usb -Pusb -D -U flash:w:.pioenvs/uno_prog/firmware.hex:i.
-D is still there.

Noticed another issue. Using this programmer config

; http://docs.platformio.org/en/latest/platforms/atmelavr.html?highlight=mkii#upload-using-programmer
[env:uno_prog]
platform = https://github.com/platformio/platform-atmelavr.git
board = uno
framework = arduino
upload_protocol = stk500v2
upload_flags = -Pusb

results in this error

Configuring upload protocol...
Available: stk500v2
Configured: upload_protocol = stk500v2
BeforeUpload(["upload"], [".pioenvs/uno_prog/firmware.hex"])
Error: Please specify `upload_port` for environment or use global `--upload-port` option.
For some development platforms it can be a USB flash drive (i.e. /media/<user>/<device name>)
*** [upload] Explicit exit, status 1

Adding a upload_port = usb results in this error:

Configuring upload protocol...
Available: stk500v2
Configured: upload_protocol = stk500v2
BeforeUpload(["upload"], [".pioenvs/uno_prog/firmware.hex"])
Use manually specified: usb
*** [upload] could not open port usb: [Errno 2] No such file or directory: 'usb'

I am able to workaround that issue by adding usb to upload_protocol leading to my final solution :wink:

[env:uno_prog]
platform = https://github.com/platformio/platform-atmelavr.git
board = uno
framework = arduino
; http://docs.platformio.org/en/latest/platforms/atmelavr.html?highlight=mkii#upload-using-programmer
upload_protocol = stk500v2 usb
upload_flags = -Pusb 

This is acually a workaround, so that the if in this builder.py-L38 line gets triggered.

Yuu MUST use PROGRAM target instead of UPLOAD.

pio run -t program
1 Like

Didn’t know that.
Thanks alot!