Uploading a hex file over ISP

I want to upload an arbitrary hex file - not a bootloader - to an ATMega 329P and to an ATMega 1284P using an USBasp programmer from the Arduino IDE and/or PlatformIO. Can anyone give me full instructions how to do this.

I can upload an Optiboot bootlloader to a 1284P over USBasp from the Arduino IDE, but don't know how to do this for a non-bootloader hex file. (The hex file has to be created by PlatformIO because the program fails to compile in the Arduino IDE because of library issues.)

When I try to upload at the hex file from PlatformIO with the command

pio run -t program

which I have been told is the way to do it, I get an error message that the programmer cannot be found. I have tried letting pio detect it automatically and also specifying what I think is the correct port.

The USBasp programmer does not show up in the list of ports in either theArduinoIDE or in PlatformIO although, as I have said, the Arduino IDE uploads Optiboot to the 1284P using it.

Finally, after I have flashed the bootloader, I can upload the hex file from Platform over a USB link to the 1284P using the installed bootloader.

Very confusing. Any help appreciated.

Hugh McIntyre

I can upload an Optiboot bootlloader to a 1284P over USBasp from the Arduino IDE, but don't know how to do this for a non-bootloader hex file.

The same way. The bootloader is nothing more than just a program but loaded into specific "boot" region and it is also in HEX form. With ISP you need use just avrdude tool.
You can use customized avrdude command from log (must be switched on in preferences) in IDE.

HAJM:
I want to upload an arbitrary hex file - not a bootloader - to an ATMega 329P and to an ATMega 1284P using an USBasp programmer from the Arduino IDE and/or PlatformIO. Can anyone give me full instructions how to do this.

I don't know anything about PlatformIO, but there is no way to do this via the Arduino IDE.

You can easily do it by running an avrdude command from the command line though. avrdude is included with the Arduino IDE. If you turn on File > Preferences > Show verbose output during: upload in the Arduino IDE, upload any sketch to your board, and then examine the contents of the black console window at the bottom of the Arduino IDE window, you will find the avrdude command the Arduino IDE used to upload the compiled .hex file to the Arduino board. You only need to copy that command, modify it according to your needs, and then run it from the command line.

HAJM:
The hex file has to be created by PlatformIO because the program fails to compile in the Arduino IDE because of library issues.

Then why don't you compile and upload the program from PlatformIO just as you would any other program?

HAJM:
The USBasp programmer does not show up in the list of ports in either theArduinoIDE or in PlatformIO

This is expected. The USBasp is a pure USB device. It doesn't create a virtual COM port.

HAJM:
Finally, after I have flashed the bootloader, I can upload the hex file from Platform over a USB link to the 1284P using the installed bootloader.

Then why not just do that?

pert:
I don't know anything about PlatformIO, but there is no way to do this via the Arduino IDE.

Is it not "Upload using programmer"?

No, because Upload Using Programmer requires that the sketch be compiled and HAJM says the code won't compile in the Arduino IDE:

HAJM:
The hex file has to be created by PlatformIO because the program fails to compile in the Arduino IDE because of library issues.

You could try avrdude from the command line with something like

avrdude -v -c usbasp -p atmega328p -U flash:w:/Users/me/my_intel.hex:i

USBasp doesn't show up as a port because it uses libusb.

To program from PlatformIO IDE you need to add

upload_protocol=USBasp -P usb -p atmega328

to platform.ini in your project.