How can I allocate a variable in program memory?
You can use MPLAB® XC32 compiler specific qualifiers as described in section 8.11 of the "MPLAB XC32 C/C++ Compiler User's Guide".
For example, in main.c, uint32_t attribute((space(prog), address(0x9D07FFF8))) hw_version = 0X12345678; void main(void) { uint32_t tmp = 0; tmp = hw_version;. After this statement is executed, the variable tmp value is 0x12345678. Note that the address 0x9D07FFF8 is a physical address and its equivalent virtual address is 0x1D07FFF8.