How to omit an upload flag upon uploading

I have a test project written in native AVR C++. The hardware is just a USBasp connected to a minimal ATmega328P system.
In previous PIO Core 4.3, I always use Upload using Programmer to upload program to the chip. However, new PIO Core removed the convenient task from task lists. So I just went back to CLI using pio run --target program, which worked well.

Meanwhile I also discovered the upload_protocol setting in platformio.ini, and tried if that will turn Upload to Upload using Programmer.

[env:m328p]
platform = atmelavr
board_build.mcu = atmega328p
board_build.f_cpu = 8000000L

upload_protocol = usbasp

And it did use USBasp, but not working, as avrdude say verification failure, and of course the chip won’t run. Upload output below:

Uploading .pio/build/m328p/firmware.hex

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file ".pio/build/m328p/firmware.hex"
avrdude: writing flash (320 bytes):

Writing | ################################################## | 100% 0.17s

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

Reading | ################################################## | 100% 0.11s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x007a
         0x9a != 0x9e
avrdude: verification error; content mismatch

avrdude: safemode: Fuses OK (E:FD, H:DE, L:FF)

avrdude done.  Thank you.

*** [upload] Error 1
============================================================ [FAILED] Took 0.84 seconds ============================================================
The terminal process "platformio 'run', '--target', 'upload'" terminated with exit code: 1.

So I tried Verbose Upload, and got the arguments for avrdude:
avrdude -v -p atmega328p -C /Users/45gfg9/.platformio/packages/tool-avrdude/avrdude.conf -c usbasp -D -U flash:w:.pio/build/m328p/firmware.hex:i
which fails.

Then I tried -v for --target program, arguments below:
avrdude -v -p atmega328p -C /Users/45gfg9/.platformio/packages/tool-avrdude/avrdude.conf -c usbasp -U flash:w:.pio/build/m328p/firmware.hex:i
which succeeds.

And notice: target program doesn’t have -D flag, in which target upload has.
-D disables auto erase, and I don’t see why it affects verification failure.
So the question is: is there a config entry to remove -D from upload flags?
Didn’t find specific one in documentation as upload_flags only adds arguments
If not, I may just stuck with CLI then.

It’s not missing, just in a different place! :open_mouth: It’s now in Platform section of the specific environment… even when you have only one. :frowning:

To remove flags, IIRC there was at least one thread showing a suitable extrascript. I’ll link it if I find it.

Edit: It’s not jumping out at me, but this post does something similar which could be easily adapted. Otherwise, you could override the whole upload command…

1 Like

Oh well, thanks a lot!

(PlatformIO skills improved) :laughing:

1 Like