{"id":131,"date":"2012-10-04T10:02:27","date_gmt":"2012-10-04T09:02:27","guid":{"rendered":"http:\/\/www.kanda.com\/blog\/?p=131"},"modified":"2012-10-04T10:05:31","modified_gmt":"2012-10-04T09:05:31","slug":"programming-avr-bootloader-code","status":"publish","type":"post","link":"https:\/\/www.kanda.com\/blog\/microcontrollers\/avr-microcontrollers\/programming-avr-bootloader-code\/","title":{"rendered":"Programming AVR Bootloader Code"},"content":{"rendered":"
We have been asked about how you can program an application code file and a separate bootloader into an AVR microcontroller using a Kanda programmer. It isn’t possible to program two separate files but it is simple enough to combine them into one file.<\/p>\n
<\/p>\n
The first thing to do is to assemble the bootloader code and see what size the final code is in words. This tells us what boot block size we will need. Most AVR devices have a separate boot block section, and we can set its size, but the choice of sizes varies between different AVR microcontrollers.<\/p>\n
The next step is open the datasheet for our particular AVR and search for Boot Size Configuration table. Look for the boot block size needed to fit our bootloader code in, and note<\/p>\n
The next step is to combine our application code and bootloader in the assembler. As the boot section is at the end of the AVR device, we need to put an ORG directive at the end of our application code with the address set to the Boot Reset Address. Depending on the assembler, we may need to convert this address into bytes (x2).<\/p>\n
Next, place an Include directive after the ORG and include the bootloader code file. When we assemble it, we get one file with application code and bootloader included at correct address ready for ISP programmer.<\/p>\n
The last step is to set the boot block size to the correct setting. This is done with BOOTSZ1:0 fuses in the programmer. Set them to the value we noted down, or to that number of pages, or the required size in words, whichever you find easiest.<\/p>\n
Thats it, the bootloader will now be programmed into your AVR.<\/p>\n