11.4.1 Declare a New Memory Space

The XC32 toolsuite requires information about each external memory. In order for 32-bit MCU device linker to be able to properly assign memory, information about the size of memory available and, optionally the origin of the memory, needs to be provided.

The external memory space was introduced in section Differences Between MPLAB® XC32 and C Standard. This attribute serves two purposes: declaring extended memory spaces and assigning C variable declarations to external memory (this will be covered in the next subsection).

Declaring an extended memory requires providing the size of the memory. You may optionally specify an origin for this memory; if none is specified 0x0000 will be assumed.

extern int external_memory

__attribute__((space(external(size(1024)))));

Above an external memory of size 1024 bytes is defined. This memory can be uniquely identified by its given name of external_memory.