Pergunta

Whenever I need to upload the bootloader to my Arduino Mega (ATMEGA2560) I use an AVRISP MKII with the fuses/lock bits described in boards.txt file. Doing this I am able to burn arduino sketches by serial connection with my FTDI.

My question is: is it possible to burn arduino sketches (.hex files) with the AVRISP but keeping the bootloader? Whenever I try to do that (I use the same avrdude command I use to program the bootloader but changing the bootloader .hex file to the sketch .hex file) I am no longer able to program the processor with FTDI (and then I need to program the bootloader again).

I think (of course I can be wrong) this problem occurs due to the fuse and lock bits settings that cannot be the same as those used to program the bootloader.

This is the fuse settings I use (from boards.txt file under Arduino folder)

mega2560.name=Arduino Mega 2560 or Mega ADK

mega2560.upload.protocol=wiring
mega2560.upload.maximum_size=258048
mega2560.upload.speed=115200

mega2560.bootloader.low_fuses=0xFF
mega2560.bootloader.high_fuses=0xD8
mega2560.bootloader.extended_fuses=0xFD
mega2560.bootloader.path=stk500v2
mega2560.bootloader.file=stk500boot_v2_mega2560.hex
mega2560.bootloader.unlock_bits=0x3F
mega2560.bootloader.lock_bits=0x0F

mega2560.build.mcu=atmega2560
mega2560.build.f_cpu=16000000L
mega2560.build.core=arduino
mega2560.build.variant=mega

Can you help me?

Thanks in advance.

Foi útil?

Solução

Some controllers like the AT*X*MEGA series support individual flash sections that can be programmed/erased independently. However, with the ATMEGA2560 this is not possible.

One way would be to concatenate the .hex files as part of the build process. This can be achieved with some modifications to the makefile.

Something similar to this

all: $(TARGET).hex 
    srec_cat bootloader.hex -intel $(TARGET).hex -intel -o combined.hex -intel

Flashing the ´combined.hex´ would then include both, main application and boot loader. There is a related discussion on AVRFreaks.

Regarding the fuses, you just have to make sure that the boot loader (address) stays configured as the entry point.

EDIT: You can use this fuse bit calculator to verify fuse settings. Select your device and make sure "Boot Reset vector Enabled (default address=$0000); [BOOTRST=0]" is enabled with your current high fuse value. You currently use

mega2560.bootloader.high_fuses=0xD8

so that seems fine.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top