Advertisement
The required BOOTLOAD.asm is located in the BOOTLOAD folder. Based on the microcontroller you are using it may become necessary to change the TX and RX pins and ports in BOOTLOAD.asm to match with your microcontroller • You need to assemble the BOOTLOAD.asm using the assembler that comes with AVR STUDIO. This will create a final file called BOOTLOAD.hex • AVRs have “fuses”! The only fuses that are relative to boot loaders are the BOOTSZ1,BOOTSZ0 and BOOTRST fuses. The BOOTSZ1 and BOOTSZ0 fuses specify how much of the memory should be “set aside” for the boot loader(Fast Tiny & Mega Uart Bootloader needs 256 words of space) • The BOOTRST fuse tells the microcontroller to boot up at the beginning of your boot loader code. It is crucial to have this fuse programmed • You need your hardware programmer to program the bootloader into the microcontroller • You should also decide which communication protocol you want to use with your microcontroller (USB,RS232,etc). This allows you to easily select the right hardware for interfacing between the UART of the microcontroller and your computer

Working With Bootloaders & Build Your Own Bootloader – 2

Now you understand that what is a bootloader is and what are the benefits of a bootloader. Inspired by many online tutorials, now I am giving you an introduction to install a bootloader into your own electronics project with an ATmega microcontroller at its heart!

You can download the zip file “Bootloader Hex” with a precompiled bootloader (for Atmega8) available here. Now unzip the bootloader, and upload the hex code using AVR Studio. On the otherhand, if you are in a plan to modify the bootloader code, go through the following steps:

  • Open AVR Studio, start a new project called bootloader in the Project Wizard Make sure you select Atmel AVR Assembler as we are programming in Assembly. Actually,you do not need to program in Assembly to write a bootloader, but the bootloader included here is written in that language, and hence you must compile for it.

avr studio

  • Click Finish to load the New Project
  • Download the zip file “Bootloader Source”, and unzip it into your bootloader directory. Now you should also put the compiled program .hex of your own project into the bootloader file as well
  • Look for the asm file in the unzipped folder. Open that file, copy the contents into your bootloader.asm that is already open in AVR Studio
  • Now refer the datasheet of your microcontroller (pin assignment), and verify that the Tx and Rx pins are correct in bootloader.asm. Make any changes if necessary.
  • Finally, build, and upload your custom bootloader .hex file into your microcontroller using your own hardware programmer, as usual.

avr studio build

Remember that you need to program a fuse to tell it to use the bootloader. For this, set BOOTRST to 0 by check the relevant box. Yes, Your Bootloader is uploaded and ready for action! Now disconnect your programmer cable. It is necessary to power cycle your microcontroller (turn it off then on again) after uploading your bootloader for the new settings to take effect.

BOOTRST

Points To Remember

generic avr bootloader

  • The required BOOTLOAD.asm is located in the BOOTLOAD folder. Based on the microcontroller you are using it may become necessary to change the TX and RX pins and ports in BOOTLOAD.asm to match with your microcontroller
  • You need to assemble the BOOTLOAD.asm using the assembler that comes with AVR STUDIO. This will create a final file called BOOTLOAD.hex
  • AVRs have “fuses”! The only fuses that are relative to boot loaders are the BOOTSZ1,BOOTSZ0 and BOOTRST fuses. The BOOTSZ1 and BOOTSZ0 fuses specify how much of the memory should be “set aside” for the boot loader(Fast Tiny & Mega Uart Bootloader needs 256 words of space)
  • The BOOTRST fuse tells the microcontroller to boot up at the beginning of your boot loader code. It is crucial to have this fuse programmed
  • You need your hardware programmer to program the bootloader into the microcontroller
  • You should also decide which communication protocol you want to use with your microcontroller (USB, RS232, etc). This allows you to easily select the right hardware for interfacing between the UART of the microcontroller and your computer

avr usb isp programmer

→ Part 21: Bootload an ATmega Microcontroller & Build Your Own Arduino!
← Part 19: Working With Bootloaders & Build Your Own Bootloader – 1

5 Comments

Join the conversation!

Error! Please fill all fields.
Looking for the latest from TI?