manpagez: man pages & more
info gcc
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.36.1 AVR Variable Attributes

progmem

The progmem attribute is used on the AVR to place read-only data in the non-volatile program memory (flash). The progmem attribute accomplishes this by putting respective variables into a section whose name starts with .progmem.

This attribute works similar to the section attribute but adds additional checking. Notice that just like the section attribute, progmem affects the location of the data but not how this data is accessed.

In order to read data located with the progmem attribute (inline) assembler must be used.

/* Use custom macros from AVR-LibC */
#include <avr/pgmspace.h> 

/* Locate var in flash memory */
const int var[2] PROGMEM = { 1, 2 };

int read_var (int i)
{
    /* Access var[] by accessor macro from avr/pgmspace.h */
    return (int) pgm_read_word (& var[i]);
}

AVR is a Harvard architecture processor and data and read-only data normally resides in the data memory (RAM).

See also the AVR Named Address Spaces section for an alternate way to locate and access data in flash memory.


This document was generated on October 19, 2013 using texi2html 5.0.