Skip to main content

Microcontrollers

Section 13.1 Flash Program Memory

The ATmega328P contains 32k B (refer to Section 10.7.1 of [16.20] for a more in-depth discussion on memory capacity and the meaning of binary prefixes) of non-volatile flash memory. (Flash memory was introduced in Subsection 2.6.2.) This is where program instructions are stored. It’s important that program instructions are stored in non-volatile memory, as any instructions stored on the microcontroller should not be erased when power is removed from the circuit.
Every instruction in the AVR instruction set is either 16 bits or 32 bits wide ([16.15]). Program memory on the ATmega328P is formatted as 16k × 16. This means that each word size is 16 bits (2 bytes). The program counter needs to be large enough to address each of these memory locations. The size of the program counter is calculated in (13.1.1).
\begin{equation} \textrm{PC size} = \lceil\log_2{16\textrm{k}}\rceil = 14~\textrm{bits}\tag{13.1.1} \end{equation}
A memory map is used to demonstrate the capacity of each type of memory and shows which addresses correspond to different sections of memory. Program memory space is divided into two sections: an application section and a bootloader section. The application section is where the program instructions are stored. The bootloader is where instructions pertaining to the programming and initial startup of the microcontroller (introduced in Section 4.6) are stored. The size of the bootloader section is configured with the high fuse byte, as discussed in Subsection 4.7.2. A map of the program memory on the ATmega328P is shown in Figure 13.1.1.
A rectangle labeled "program memory." The top of the rectangle has a label on the right hand size saying 0x0000. The top 4/5 of the rectangle is labeled "application memory" and the bottom 1/5 of the rectangle is labeled "bootloader." The bottom of the rectangle has a label on the right hand size saying 0x3FFF.
Figure 13.1.1. Memory map of the flash program memory on the ATmega328P.
The first address in program memory is 0x0000, and the last address is 0x3FFF. The memory address denoting the start of the bootloader depends on the value stored in the high fuse byte.