Programmer issues with plaformIO and not with Arduino IDE

High everyone,

I have a strange problem. I am hoping yuu guys will be able to help me.

I have 3D printer with a custom board (atmega2560). This board can only be programmed through the ISP connector. Not through the USB connection (the usb connection is really unstable. Probably bad board design). I have been programming this board for a long time with USBAsp programmer on the ISP connector with the ArduinoIDE software. This works every time.

I currently trying to get platformIO for this custom board. However, I have problems uploading the firmware with the USBAsp programmer. This is the error I am getting.

Writing | ################################################## | 100% 74.27s

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

Reading | ################################################## | 100% 50.02s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
0x04 != 0x0c
avrdude: verification error; content mismatch

avrdude done. Thank you.

*** [upload] Error 1

At the moment the error is like this.

avrdude: verification error, first mismatch at byte 0x0002
0x40 != 0x41

avrdude is right. The program does not work. Even if the program blink_led does nog word.
The program does work if I use the ArduinoIDE to upload the program.

These are the platformio.ini settings that I am using.

[env:usbasp]
platform = atmelavr
board = ATmega2560
framework = arduino
upload_protocol = usbasp
; each flag in a new line
upload_flags =
-Pusb

I also tested some other things. The following things do work:

  • Uploading firmware from platformIO through USB straight to a UNO
  • Uploading firmware from platformIO through the USBAsp programmer to a UNO
  • Uploading firmware from ArduinoIDE through the USBAsp programmer to the custom board atmega2560

These are the fuses of the atmega2560 custom board.

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

Any help would be appreciated :slight_smile:

This board definition uses framework-arduino-avr-megacore - which among other things, may use a different bootloader and possibly want different fuse settings. Have you tried board = megaatmega2560? I don’t have my ISP programmer out atm, but a normal serial upload to a mega2560 with the latter board name works, whereas the former doesn’t.

MegaCore is definitely worth a look at if you want a more up to date and actively supported core (LTO code optimisation, printf support, pin macros, extra functions, etc), but you need to be ready to make the jump as there are a couple of minor differences!

Add -e to the upload_flags for an erase.

2 Likes

That works! Adding the -e. Thank you so much!
megaatmega2560 of ATmega2560 doesn’t make a difference. They both work in combination with -e.

1 Like

Great! I had it stuck in my head somewhere that --target program added the -e itself, and --target upload didn’t, but obviously not! :open_mouth:

Edit: Penny just dropped… I was right the first time! lol The upload target (-t upload) adds -D to the avrdude call, which is D as in Disable auto erase for flash. When you use the programmer specific option -t program the -D is not added, so the default behaviour of erasing flash is honoured. Realised it when looking at the source code to check something else programmer related out. platform-atmelavr/main.py at 9970ad03bfada6a8b1c18a264f99fcea0b98c9bf · platformio/platform-atmelavr · GitHub