How to support programming "bare" AVR chips on the atmelavr platform?

I’m directly programming an atmega328p (RC osc, 8 mhz, clkdiv8, so 1 mhz) using and Arduino Nano as an ISP programmer. Specifically, I’m putting a blank (from Mouser) 328 into a breakout board, and attaching the ISP pins, with zero supporting circuitry.

I’m using the 328p8m board.

This almost works – the flash needs to be erased before programming, but it looks like the ‘atmelavr’ platform builder script is hard-coded to use the -D (don’t erase flash) avrdude flag, for most upload protocols.

Is this something that can be overridden in a board JSON file, or is a custom builder script needed? Or something else?

This is working – no longer has the -D flag.

However, looks like the “program” target does not support auto-detection of the serial port, nor does it support the “wildcard” option for the upload_port variable:

In builder/ line 256 it adds BeforeUpload to the list of commands, but if you look at BeforeUpload, it will immediately return for the program target.

Not sure if this behavior is intentional, but the docs don’t mention that these things won’t work when using the program target.

Would a PR that simply moves these lines:

    env.Append(UPLOADERFLAGS=["-P", '"$UPLOAD_PORT"'])```

Above the check for the `program` target be accepted?

upload_flags = -P $UPLOAD_PORT

Yes, that works fine, if you want to manually set the port. It would be nice if the auto-detect of the port worked for the program target.

I’m referring to this part of the documentation:

If upload_port isn’t specified, then PlatformIO will try to detect it automatically.

If it’s not supported for the program target, that’s fine – need to update the documentation. If it is supported, then it should work.

board = 328p8m
board_f_cpu = 1000000

platform = atmelavr
framework = arduino

# arduino as ISP
#upload_port = /dev/ttyUSB0
upload_speed = 57600
upload_protocol = arduinoisp
upload_protocol = stk500v1
upload_flags = -b$UPLOAD_SPEED

Results in this:

avrdude: ser_open(): can't open device "com1": No such file or directory

Actual port is /dev/ttyUSB0 – auto-detect of this port does work for the upload target, but upload fails because of the -D flag.

Take a look at

Just overwrite UPLOADHEXCMD with '$UPLOADER $UPLOADERFLAGS -U flash:w:$SOURCES:i' and use upload target instead of program.