11.4.2 Declare a New Memory Space

The compiler toolsuite requires information about each additional memory being attached via the PMP. In order for the XC-DSC device linker to be able to properly assign memory, information about the size of memory available and the number of chip-selects needs to be provided.

In Differences Between MPLAB® XC-DSC and C Standard the new pmp memory space was introduced. 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 assign the memory to a particular chip-select pin; if none is assigned it will be assumed that chip-selects are not being used. These memory declarations look like normal external C declarations:

extern int external_PMP_memory

__attribute__((space(pmp(size(1024),cs(0)))));

Above we defined an external memory of size 1024 bytes and there are no chip-selects. The compiler only supports one PMP memory unless chip-selects are being used:

extern int PMP_bank1 __attribute__((space(pmp(size(1024),cs(1)))));

extern int PMP_bank2 __attribute__((space(pmp(size(2048),cs(2)))));

Above PMP_bank1 will be activated using chip-select pin 1 (address pin 14 will be asserted when accessing variables in this bank). PMP_bank2 will be activated using chip-select pin 2 (address pin 15 will be asserted).

Note that when using chip-selects, the largest amount of memory is 16 Kbytes per bank. It is recommended that the declaration appear in a common header file so that the declaration is available to all translation units.