Fig. 1: Program memory organisation
Fig. 1: Program memory organisation

Normally, ATMEL’s AVR microcontrollers are programmed using programmers. There are many ways to program the AVR microcontrollers, such as in-system programming, parallel programming and using bootloader. Advantage with the bootloader method is that you don’t need any external hardware to load the hex file on the microcontroller. A bootloader program is placed inside the boot section of the Flash memory, to handle communication with the host PC and facilitate programming of both Flash and EEPROM.

Programming using bootloader

The bootloader firmware loaded on the microcontroller allows in-system programming directly via TXD and RXD pins of the microcontroller. The code responsible for in-system programming via serial port resides in the configurable boot memory section of the microcontroller. When signalled using external switch while resetting the microcontroller, it gets active and waits for communication from the PC for loading the hex file on the microcontroller’s flash memory. The PC sends the hex file to the microcontroller. The code residing in the boot section loads the hex file on the microcontroller’s flash memory.

Once the programming process is complete, newly loaded code can be executed by pressing reset. Once the code is loaded on the microcontroller, UART is free and can be used for other applications.

Note that the bootloader gets invoked only if boot switch is kept pressed while the microcontroller is reset using reset switch.

Fig. 2: Circuit to program the microcontroller using the bootloader
Fig. 2: Circuit to program the microcontroller using the bootloader

1B9_5CF_Table-2The Flash memory is divided into two sections: application and bootloader. The application section contains the main code for the application, while the bootloader section contains the code for actual self-programming.

The store program memory instruction can be executed only from the bootloader section. The memory organisation is shown in Fig. 1. The size of the bootloader section can be selected using the BOOTSZ fuse bit setting (refer the table).

2 COMMENTS

  1. Dear Arun ji,
    After Searching a lot over internet, a suitable, Explicit and Properly explained article i found.
    I have a few more question on this:
    a. IAR Embedded Workbench is mandatory for this project? Can we use AVR Studio instead?
    b. Is it possible to program bootloader & then our application program for ATmega2560 also?

  2. Dear Pronab,
    Answers to your queries is as follows:
    1. No, IAR Embedded Workbench is not mandatory. One can use nay GCC based compilers like AVR Studio (in Windows), Eclipse (in Windows and Linux platforms), etc. with slight modifications in included header files.
    2. Yes you can progran your chip with the bootloader first using any ISP programmer and then you need to use your standard serial programming interface like AVR OSP MK II as suggested in the article. But you could not use ISP Programmer to program your own code on the chip once bootloader is embedded, as this would erase the bootloader.
    Thanks for the appreciation.
    Best Wishes,
    Arun Dayal Udai

LEAVE A REPLY

Please enter your comment!
Please enter your name here