1
AVR109: Self-programming
Features
• AVR109 Code Fits in All AVR
®
Microcontrollers with Boot Block
• Read and Write Both Flash and EEPROM Memories
• Uses the AVRProg Protocol
• Read and Write Lock Bits
Introduction
This application note describes how an AVR with the Store Program Memory (SPM)
instruction can be configured for Self-programming. The AVR communicates via the
UART with a PC running the AVRprog programming software. This enables Flash and
EEPROM programming without the need for an external programmer.
A Boot Loader program is placed inside the Boot Section of the Flash memory. This
program handles communication with the host PC, and facilitates programming of
both Flash and EEPROM. Once programmed, different levels of protection can be
individually applied to both the boot and application portion of the Flash memory. The
AVR thus offers a unique flexibility, allowing the user extensive degrees of memory
protection.
SPM Explained
To get a better understanding of the AVRs’ self-programming capabilities, the basics
of this feature are explained below.
Memory Organization
The Flash memory is divided into two sections, one Application section and one Boot
Loader section. The Application section contains the main code for the application,
while the Boot Loader section contains the code for the actual Self-programming. The
SPM instruction can only be executed from the Boot Loader section. (Note: The Boot
Loader section can also be used for ordinary application code.)
The Flash memory is divided into pages containing 32, 64, or 128 words each. The
usage of pages is explained later. The entire memory span, both Application and Boot
Loader sections, is divided into pages. For instance, a device with 8 kbytes of Flash
and page size of 32 words (64 bytes) will therefore have a total of 128 pages. The
memory organization is shown in Figure 1.
8-bit
RISC
Microcontroller
Application
Note
Rev. 1644C–AVR–08/02