Hello,
I am using NXP K2x K22FN512M12 controller and MCUXpresso IDE.
I am getting Hard Fault whenever I am trying to access Program memory.
Example:
I have saved this array in Program memory using following method
__attribute__ ((section (".myAccessArray"))) uint8_t au8DeviceObject
[MAX_PROP_SUPPORTED+1][MAX_OBJECT_TYPE-1]
Linker File:
I have allocated memory from text area
MEMORY {
m_interrupts (RX) : ORIGIN = 0x00000000, LENGTH = 0x00000198 /* Debugger COmpatible, no bootloader compatible*/
/*m_interrupts (RX) : ORIGIN = 0x00012800, LENGTH = 0x00000198*/ /* bootloader compatible*/
m_text (RX) : ORIGIN = 0x00012C10, LENGTH = 0x0006D3F0
m_data (RX) : ORIGIN = 0x1FFF0000, LENGTH = 0x00010000
m_heap_rtos (RW) : ORIGIN = 0x20000000, LENGTH = 0x00010000
m_cfmprotrom (RX) : ORIGIN = 0x00012C00, LENGTH = 0x00000010
WIFI_DATA (RX) : ORIGIN = 0x00011800, LENGTH = 0x00000800 /*0x00011800 to 0x00012000*/
OTHER_DATA (RX) : ORIGIN = 0x00012000, LENGTH = 0x00000800 /*0x00012000 to 0x00012800*/
ACCESS_ARRAY(RX) : ORIGIN = 0x00100000, LENGTH = 0x000051d8
DATA_ARRAY(RX) : ORIGIN = 0x001053E0, LENGTH = 0x000051d8
}
/* Define output sections */
SECTIONS
{
/* The startup code goes first into INTERNAL_FLASH */
.
.
.// other sections
.
.myAccessArray :
{
KEEP(*(.AccArrCfg)) /* keep my variable even if not referenced */
} > ACCESS_ARRAY
.myDataArray :
{
KEEP(*(.DataArrCfg)) /* keep my variable even if not referenced */
} > DATA_ARRAY
}
Accessing array:
uint8_t *pu8AccArray = NULL;
uint8_t *pu8Ptr = NULL;
uint32_t u32DevProp = PROP_DEVICE;
uint32_t u32ObjType = OBJECT_ANALOG;
uint32_t u32PropType = 0;
pu8AccArray = &au8DeviceObject[0][0];
pu8Ptr = (pu8AccArray + ((MAX_PROP_SUPPORTED+1) * u32DevProp) + u32ObjType);
u32PropType = *pu8Ptr; // @ this point exception occurs and controller goes into hard fault.
Please let me know if there is anything that I am doing wrong.
Thank You!!!