Bootloader for the ATMEL AT MEGA series of processors (WinAVR port)

Page Revision Information

Page revision
21 Apr 2004
Initial version.


The Atmel AVR 8-bit processors are a great choice for any small embedded systems projects. Earlier versions of these processor support high-voltage parallel and serial ICP programming of their internal FLASH (code) and EEPROM (data) memory subsystems.

The latest series of AVR processors (the AT MEGA series) include two useful capabilities:

  1. The processor can begin execution, after reset, either location 0x0000, or at a special bootstrap area at the top of FLASH memory
  2. The processor can erase, program and read the FLASH under program control
These two abilities allow the implementation of a simple bootloader (executed at reset) that is able to update the program in FLASH. This removes the need for a dedicated programmer after the bootloader is installed in the processor.

This project is a bootloader that allows the FLASH and EEPROM to be programmed using a computer connected via the serial port.

The original bootloader program source is supplied by Atmel as Application note AVR109. The application note and source code are available from the Atmel web site.

The bootloader is implemented in a mixture of assembler and "C" language modules that are written for the IAR assembler and "C" compiler. The project is a port of the original source code to the freely available WinAVR port of the GCC compiler and supporting tools.

This project was originally intended to be used with the EQ-6/Atlas MCU replacement project, but should be a useful starting point for anyone who want to add bootloader functionality to a MEGA AVR project.

This program is compatible with the AVR Prog software from Atmel. This is distributed as part of the (free) AVR Studio 4


This project is a derivative of software originally written by Atmel. Permission is given to use the modifications to the original Atmel program under the same conditions as the original Atmel program.

Unfortunately, the source files contain no statement of how the original source can be used from a copyright point of view.

If you want to use this code in a commercial program I suggest you contact Atmel for permission via email.

I suspect that Atmel's response will be that you're free to use it, as anything that sells devices is a good thing for a semiconductor company (trust me - I work for one!).

Modifying the Bootloader

The source code may need to be modified for use in other applications. The application note has details on the overall program structure, but the following table might help:

How to change it
Modify defines.h as described in processor.xls
8 MHz clock
Change DEF_CLK_RATE in serial.h, or modify the Makefile to pass the CLK_RATE preprocessor macro definition (CPU frequency in Hz)
Waits 5 seconds for AVR Prog to connect
  • WAIT_MS specifies the wait time in msec
  • Can use different method. See main.c source comments
AT MEGA Serial port 1 is used for connection
Change serial port register names in serial.c

Source code

The following source code table contains the software releases:

Release 1
Initial release

Setting up the CPU

The processor needs to be setup before the bootloader can be used. Each member of the family has a different set of fuse and lockbit settings, but the appropriate ones for the AT MEGA 162 are:

Fuse settings:
Lock bits:

Other settings are system dependent.