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?

  • 2
    \$\begingroup\$ Last time I wrote an AVR bootloader was before Atmel Studio but just having a quick I think you should be able to do it under project properties | Toolchain | AVR/GNU Linker | Memory Settings. Normally if I want them combined I do the bootloader, use it to load and then read back the result. \$\endgroup\$ – PeterJ May 29 '14 at 11:29
  • \$\begingroup\$ Yes. I can see the option there, but its really confusing \$\endgroup\$ – gzix May 29 '14 at 11:38
  • \$\begingroup\$ I am really confused with .text and .boot. Also that boot section only take last 512 words,so from where 1234 is coming. Please tell me where to look at for your old project. \$\endgroup\$ – gzix May 29 '14 at 12:01
  • \$\begingroup\$ Ok so i need to replace it with boot section address of Atmega32A. Right am I? \$\endgroup\$ – gzix May 29 '14 at 12:11
  • \$\begingroup\$ I am getting an error "File contents does not map to any valid device memory for programming Flash" when i include .text. when replace it with .boot it works, but writing from the same 0x00 address. \$\endgroup\$ – gzix May 29 '14 at 13:11

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.