Electronic – Writing the bootloader program into ATmega32A

atmegaavrbootloaderc

I am in a need of programming a bootloader code written in C into the boot section of AVR ATmega32A using a serial programmer. I can't write the code directly into the boot section from Atmel studio. So, I am looking for a way here. Also, is there any good way of combining application code and Boot code and write them in respective sections using C program?

Best Answer

The ATmega32A Datasheet on page 245 shows the following table of where the bootloader area starts depending on how the BOOTSZ fuses are set:

ATmega32A boot size configuration

So assuming you have BOOTSZ0 and BOOTSZ1 are both cleared for the largest bootloader section it will start at 0x3800. From the memory sections documentation you can see the code goes into the .text linker segment and the address may be changed by going under Project properties | Toolchain | AVR/GNU Linker | Memory Settings and adding .text=0x3800 under the FLASH segment section:

Atmel Studio FLASH segment for bootloader

Normally if I want the bootloader combined with the application firmware for production programming I use the bootloader to load the main firmware and then read back the result from FLASH. It should be technically possible to combine them using custom linker segments but you'd have to be very careful about where things like standard library functions were placed so the former method is probably easier and safer.