3.9 __hugeflash Keyword

The IAR __hugeflash keyword places and accesses objects in huge program memory (addressable range 0x0-0x7FFFFF). Pointer arithmetic and access is all 24-bit. Pointers qualified with this keyword can point to any address in this range.

Suggested Replacement

There are two ways of having MPLAB XC8 code perform a similar task to this keyword.

When the -mconst-data-in-progmem const-in-program-memory feature is in effect (the default operation), this IAR keyword can simply be removed. In this case, all const-qualified objects are automatically placed in and read from program memory, and 24-bit wide pointers are used.

When the -mno-const-data-in-progmem option has been used to disabled the const-in-program-memory feature, use the MPLAB XC8 __memx qualifier, which places const objects in flash and accesses these using 24-bit addresses.

Caveats

The const qualifier must be used with the __memx qualifier when using MPLAB XC8, whereas this is only preferable when using __hugeflash with IAR.

Access of objects using __memx will be slightly slower than those using a 24-bit flash-only pointer, as __memx addresses represent a combined flash + data memory address space.

Examples

Consider migrating IAR code such as:
__hugeflash char arr[] = "abc";
 
volatile int x;
int main(void) {
    x = arr[x];
}
to MPLAB XC8 code similar to:
#include <xc.h>
 
const char arr[] = "abc";
 
volatile int x;
int main(void) {
    x = arr[x];
}
when the -mno-const-data-in-progmem const-in-program-memory feature is enabled, or to:
#include <xc.h>
 
const __memx char arr[] = "abc";
 
volatile int x;
int main(void) {
    x = arr[x];
}
when the const-in-program-memory feature has been disabled.

Further Information

See the Special Type Qualifiers and Options Specific to AVR Devices sections in the MPLAB XC8 C Compiler User's Guide for AVR MCUs for more information on this qualifier and option.