A brief word about bootloaders:
Generally, a bootloader is a small program which runs at boot time and is capable of loading a complete application program into a processor's memory so that it can be exectuted. Note that the bootloader runs on the same processor into which it is loading a new program.
In the case of AVR processors, the bootloader program is usually 256-4096 assembly instuctions long and resides in a special portion of the FLASH memory called the bootblock. At boot time (when the processor has just been reset) the bootloader starts and is capable of communicating with the outside world to retrieve a new program and program it into the processor's FLASH memory. Depending on the bootloader and the available hardware, new application code can be loaded from any source including the serial port, SPI or I2C interfaces, external memory, hard disks, flash cards, etc. Once the programming is done, the bootloader program exits or the processor is reset and begins running the newly loaded code. Only AVR processors with the self-programming memory feature (those that have an SPM assembly instruction) can run a bootloader.
Installing an AVR bootloader:
Just like regular application code, a bootloader must be loaded into the processor's FLASH memory once when you first begin using it. Instructions on how to do this are beyond the scope of this document because it depends on which processor and hardware you are using. To continue you will need to know how to transfer a *.hex file to the AVR's FLASH memory, and how to set the processor's fuse bits. Common ways to load code and change fuse bit settings include using Atmel AVR Studio with an STK500 board, the PonyProg Programmer, UISP, or AVRdude. Use caution when modifying fuse bits. It's possible to render your microcontroller unresponsive.
The procedure for installing a bootloader is indepenent of how the bootloader works:
- Program the bootloader *.hex file into your processor using traditional methods (ie. AVR Studio, PonyProg, UISP, AVRdude, etc). Your AVR processor must match the one for which the bootloader is designed.
- Set the size of your processor's bootblock to match the size of the bootloader program.
- Set your processor's reset vector to point to the bootblock, not the default 0x0000 address.
NOTE: AVR Studio's notation for this is somewhat confusing. When the Boot Reset Vector Enabled box is checked, your processor will run the bootloader after reset. When this box is unchecked, the processor starts at the default 0x0000 address - ie. runs your application after reset.Notes:
- The bootblock size and reset vector can be changed by modifying your processor's fuse bits. The AVR Studio manual and/or the processor's datasheet has more information about the meaning of fuse bits and how to set them.
- AVR Studio's notation for the Boot Reset Vector is somewhat confusing. When the Boot Reset Vector Enabled box is checked, your processor will run the bootloader after reset. When this box is unchecked, the processor starts at the default 0x0000 address - ie. runs your application after reset. To enable automatic bootloader operation, this box should be checked.
- The size of the bootloader may be listed in kwords or kbytes. Convert using kwords = kbytes/2.
STKLOAD: A STK500-Emulating Bootloader
This bootloader is written to emulate Atmel's well-known STK500 AVR development board. The STK500 uses a block transfer protocol to quickly program AVR processors using a standard serial port connection and ordinary RS-232 signaling. With this bootloader installed, you will be able to program your processor from Atmel AVR Studio, just like you would if you were using an STK500 board. For most processors, a complete programming cycle takes 5-10 seconds.
With the bootloader installed, your processor will act like an STK500 board for the first 3 seconds after RESET. If within these three seconds you open an STK500 programming session in AVR Studio, your processor will be automatically detected and you will be able to load new application code. See the manual or on-line help for AVR Studio on how to do this...it's quite trivial. After loading new application code, you can exit the bootloader by pressing RESET.
If no programming instructions are received over the serial port within 3 seconds after RESET, the bootloader will timeout and the currently loaded application will run automatically. NOTE: If there is no currently loaded application (ie. the FLASH memory is blank), then the bootloader will run repeatedly until programming commands are received.
Download STKLOAD:
Download an appropriate bootloader for your processor from the list below. The bootloader is already compiled into a *.hex file and is ready to be programmed into your processor. Don't forget to set the fuse bits as appropriate.
- Protocol v1 - STKLOAD using STK500 protocol v1 (reasonably proven)
- Protocol v2 - STKLOAD using STK500 protocol v2 (alpha testing, known to be buggy)
Choose Processor, Interface, and Clock Download STKLOAD Processor Protocol/Interface Bootloader SizeCPU frequency
STK500
Protocol v1STK500
Protocol v2 RELEASE Test OnlyATmega8 STK500/UART 1Kword
7.373MHzATmega8 STK500/UART 1Kword 14.746MHzATmega8 STK500/UART 1Kword 16.000MHzATmega168
STK500/UART 1Kword 18.432MHzATmega168
STK500/UART 1Kword 20.000MHzATmega168
STK500/UART 1Kword 22.118MHzATmega16
STK500/UART 1Kword 7.373MHzATmega16 STK500/UART 1Kword 14.746MHzATmega16 STK500/UART 1Kword 16.000MHzATmega16 STK500/UART 1Kword 18.432MHzATmega32
STK500/UART 1Kword 7.373MHzATmega32 STK500/UART 1Kword 14.746MHzATmega32 STK500/UART 1Kword 16.000MHzATmega32 STK500/UART 1Kword 18.432MHzATmega644
STK500/UART 1Kword 14.746MHzATmega644
STK500/UART 1Kword 18.432MHzATmega644
STK500/UART 1Kword 22.118MHzATmega128
STK500/UART 0 1Kword 7.373MHzATmega128 STK500/UART 0 1Kword 14.746MHzATmega128 STK500/UART 0 1Kword 16.000MHzATmega128 STK500/UART 1 1Kword 7.373MHzATmega128 STK500/UART 1 1Kword 14.746MHzATmega128 STK500/UART 1 1Kword 16.000MHzATmega128 STK500/UART 1 1Kword 18.432MHzATmega1280 STK500/UART 0 1Kword 14.746MHzATmega1280 STK500/UART 0 1Kword 16.000MHzATmega1280 STK500/UART 0 1Kword 18.432MHzATmega1280 STK500/UART 1 1Kword 14.746MHzATmega1280 STK500/UART 1 1Kword 16.000MHzATmega1280 STK500/UART 1 1Kword 18.432MHzATmega163
STK500/UART 1Kword 7.373MHzATmega163
STK500/UART 1Kword 8.000MHzATmega323
STK500/UART 1Kword 7.372MHzATmega8515 STK500/UART 1Kword 7.372MHz
Download STKLOAD for AVR-Core boards:
These bootloaders contain initialization specific to the Procyon AVR-Core board, but are otherwise the same as the above bootloaders.
Processor Protocol/Interface SizeCPU frequency
STK500
Protocol v1STK500
Protocol v2ATmega128 STK500/UART 1 1Kword 7.373MHzATmega128 STK500/UART 1 1Kword 14.746MHzATmega128 STK500/UART 1 1Kword 18.432MHz