PlatformIO Community

Hex file includes fuse config for bare ATmega16 project

After building a native Atmega16 project (platform=atmelavr, board=Atmega16) the upload with avrdude fails:
avrdude: ERROR: address 0x820002 out of range at line 146 of .pio/build/ATmega16/firmware.hex

The reason is the presence of the fuse settings in the hex file

:02000004008278
:02000000CF89A6

The cause seems the hex file generation by avr-objcopy which does not include the -R .fuse flag. This way the flags are copied from the elf file to the hex file.

I created a work around by overwriting the hex file in an extra_script as a post step (see below). But this feels more as a hack then a solution.

Has anybody else another/better solution to this issue?

import sys

Import("env")

sys.stdout.write('Rewriting firmware.hex without fuses\n')
env.AddPostAction(
    "$BUILD_DIR/${PROGNAME}.hex",
    env.VerboseAction(" ".join([
        "$OBJCOPY", "-O", "ihex", "-R", ".eeprom", "-R", ".fuse",
        "$BUILD_DIR/${PROGNAME}.elf", "$BUILD_DIR/${PROGNAME}.hex"
    ]), "Building $BUILD_DIR/${PROGNAME}.hex")
)

Thanks, please report this bug to Issues · platformio/platform-atmelavr · GitHub