1
votes

I have a problem with Arduino MEGA2560 dev board. The onboard chip used to upload program (AtMega16U2) is damaged due to overvoltage so I am unable to upload the code on AtMega2560. which implies Serial0 used to upload program serially is not working properly because of the damaged IC.

So I modified the source file of bootloader (stk500boot.c) to use Serial1 instead of Serial0.(Atmega2560 has 4 serial ports).

Then I uploaded the new generated .hex file using another programmer (usbasp), but the issue is that the code goes to the application part of the flash.

So how can I load the code to Bootloader part of the flash? Should I modify the fuse settings before uploading to the flash and how can it be done?

1
Please format your text in a readable way (use newlines where appropriate).hellow
Thanks, @hellow. Hope it is clear now...user11472

1 Answers

0
votes

You have to tell the linker to relocate the .text section. Normally, it targets address 0x00. This has to be set to the start address of the bootloader flash.

For example:

-Wl,-section-start=.text=0x20000

Pitfall: Note that the addresses in the datasheet are word addresses. The You linker expects the bytes address, so remember to multiply the word address by 2.