Linking with Variables in Program Memory

The compiler creates special sections in the output file for variables in program memory.

This is a description of all data in program memory sections:

The following sections are also generated if you choose to generate separate sections for char data:

These sections are used in the linker command file just like normal sections. A typical linker command file for a program that uses data in program memory looks like the following listing

Note: __pmem qualifier can be used only for global variable and is not available for local variable.
Listing: Typical Linker Command File
MEMORY

{

    .p_RAM              (RWX) : ORIGIN = 0x0082,   LENGTH = 0xFF3E

    .p_reserved_regs    (RWX) : ORIGIN = 0xFFC0,   LENGTH = 0x003F

    .p_RAM2             (RWX) : ORIGIN = 0xFFFF,   LENGTH = 0x0000

    .x_RAM              (RW)  : ORIGIN = 0x0001,   LENGTH = 0x7FFE   # SDM xRAM limit is 0x7FFF

}

SECTIONS

{

    .application_code :

    {v        # .text sections



        * (.text)

        * (rtlib.text)

        * (fp_engine.text)

        * (user.text)

        * (.data.pmem)            # program memory initalized data

        * (.const.data.pmem)      # program memory constant data

        * (.bss.pmem)             # program memory uninitialized data

    } > .p_RAM



    .data :

    {

        # .data sections



        * (.const.data.char)  # used if "Emit Separate Char Data Section" enabled

        * (.const.data)v        * (fp_state.data)

        * (rtlib.data)

        * (.data.char)        # used if "Emit Separate Char Data Section" enabled

        * (.data)



        # .bss sections



        * (rtlib.bss.lo)

        * (rtlib.bss)

        . = ALIGN(1);

        _START_BSS = .;

        * (.bss.char)         # used if "Emit Separate Char Data Section" enabled

        * (.bss)

        _END_BSS   = .;



        # setup the heap address



        . = ALIGN(4);

        _HEAP_ADDR = .;

        _HEAP_SIZE = 0x100;

        _HEAP_END = _HEAP_ADDR + _HEAP_SIZE;

        . = _HEAP_END;



        # setup the stack address



        _min_stack_size = 0x200;

        _stack_addr = _HEAP_END;

        _stack_end  = _stack_addr + _min_stack_size;

        . = _stack_end;



        # export heap and stack runtime to libraries



        F_heap_addr   = _HEAP_ADDR;

        F_heap_end    = _HEAP_END;

        F_Lstack_addr = _HEAP_END;

        F_start_bss   = _START_BSS;

        F_end_bss     = _END_BSS;

    } > .x_RAM

}