platformio / platform-atmelavr

Atmel AVR: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/atmelavr
Apache License 2.0
138 stars 105 forks source link

Default `upload_flags` should be empty for `upload_protocol` == `avrisp` #30

Closed satanowski closed 7 years ago

satanowski commented 7 years ago

By default upload_protocol contains -D option when using avrisp as upload_protocol.

Example:

Such configuration...

$ cat platformio.ini
[env:nano]
platform=atmelavr
board=attiny13
framework=arduino
upload_port=/dev/ttyUSB01
upload_protocol=avrisp

...will give more or less such avrdude command:

avrdude -v -p attiny13 -C avrdude.conf -c avrisp -b 19200 -P "/dev/ttyUSB01" -D -U flash:w:.pioenvs/nano/firmware.hex:i

The problem is that -D option disables auto erase of flash and when using Arduino as programmer omitting this particular phase very often (often = always on all my programmers and AVR chips) causes mismatch errors:

avrdude -v -p attiny13 -C avrdude.conf -c avrisp -b 19200 -P "/dev/ttyUSB01" -D -U flash:w:.pioenvs/nano/firmware.hex:i

(...)
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.08s
(...)
Writing | ################################################## | 100% 0.53s
(...)
Reading | ################################################## | 100% 0.34s
(...)
avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0002
0x06 != 0x16
avrdude: verification error; content mismatch

avrdude: safemode: hfuse reads as FF
avrdude: safemode: Fuses OK (E:FF, H:FF, L:6A)

avrdude done.  Thank you.

Without -D option everything works as a charm.

Of course one can set empty value to upload_flags to mitigate this problem. But since -D is not enabled by default in avrdude, maybe it should not be in platformio?

ivankravets commented 7 years ago

Do you use upload or program target?

satanowski commented 7 years ago

upload

ivankravets commented 7 years ago

http://docs.platformio.org/en/latest/platforms/atmelavr.html#upload-using-programmer

satanowski commented 7 years ago

My bad :)