I am getting Hard Fault whenever I am trying to access Program memory

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I am getting Hard Fault whenever I am trying to access Program memory

1,452 Views
abaniketbhumkar
Contributor I
  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!!!
Labels (1)
0 Kudos
3 Replies

1,229 Views
mjbcswitzerland
Specialist V

Hi

What is the value of pu8Ptr when it hard faults?
Are you sure that it is pointing to the flash since it can't be calculated from the code that you have shown (some define values are not shown).

Regards

Mark

0 Kudos

1,229 Views
abaniketbhumkar
Contributor I

Hi Mark,

Thank you for your reply.

Yes, the value of  pu8Ptr pointer is pointing to the flash. Whenever I debug, pu8Ptr pointer points the

assigned memory address in flash. 

 

Regards,

Aniket

0 Kudos

1,229 Views
BlackNight
NXP Employee
NXP Employee

Hi Aniket,

what is the value of pu8Ptr?

And I see that you have stuff allocated at 0x10'0000, but your device has FLASH only up to 0x8'0000?

I hope this helps,

Erich