5.3.4.7 How Can I Load a Value Into Flash Memory?

The compiler provides different ways of defining Flash variables.

  • A variable can be explicitly placed into Flash using an appropriate space attribute.
  • Variables are implicitly placed into Flash in the default const-in-code memory model if they have the C const type qualifier.

These differences allow you to choose how much work you want to do to access variables, and how much you want the compiler to do. The compiler has the least to do when you simply specify the attribute space(prog), and the initial value; which leaves the access (usually via tblrd instructions) up to you, the programmer. The compiler has the most to do when you combine the space(prog) attribute with an appropriate access qualifier, such as __eds__ or __prog__.

Also, there is often a single page of Flash space dedicated to const qualified objects. See -mconst-in-code in the following sections of this user’s guide for more details:

Variable Attributes

Variables in Program Space