Atmel CAVR-4 Manuale Utente
CAVR-4
Part 1. Using the compiler
15
Data storage
This chapter gives a brief introduction to the memory layout of the AVR
microcontroller and the fundamental ways data can be stored in memory: on
the stack, in static (global) memory, or in heap memory. For efficient memory
usage, AVR IAR C/C++ Compiler provides a set of memory models and
memory attributes, allowing you to fine-tune the access methods, resulting in
smaller code size. The concepts of memory models and memory types are
described in relation to pointers, structures, C++ class objects, and
non-initialized memory. Finally, detailed information about data storage on the
stack and the heap is provided.
Introduction
The AVR microcontroller is based on the Harvard architecture—thus code and data have
separate memory spaces and require different access mechanisms. Code and different
type of data are located in memory spaces as follows:
separate memory spaces and require different access mechanisms. Code and different
type of data are located in memory spaces as follows:
●
The internal flash space, which is used for code,
_ _flash
declared objects, and
initializers
●
The data space, which can consist of external ROM, used for constants, and RAM
areas used for the stack, for registers, and for variables
areas used for the stack, for registers, and for variables
●
The EEPROM space, which is used for variables.
STORING DATA
In a typical application, data can be stored in memory in three different ways:
●
On the stack. This is memory space that can be used by a function as long as it is
executing. When the function returns to its caller, the memory space is no longer
valid.
executing. When the function returns to its caller, the memory space is no longer
valid.
●
Static memory. This kind of memory is allocated once and for all; it remains valid
through the entire execution of the application. Variables that are either global or
declared static are placed in this type of memory. The word static in this context
means that the amount of memory allocated for this type of variable does not
change while the application is running.
through the entire execution of the application. Variables that are either global or
declared static are placed in this type of memory. The word static in this context
means that the amount of memory allocated for this type of variable does not
change while the application is running.