lpcware

IAP Flash Programming causing Hard fault

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by lonwalker on Thu Oct 16 14:06:16 MST 2014
I have been chugging right along with my project and ran into a snag writing setup parameters within LPC824's Flash memory (sector 15) for my program to read on power-up.
I am using using the LPCWare periph_flashiap project sample code snippets to my code:

/* Last sector address */
#define START_ADDR_LAST_SECTOR  0x00003C00

/* Size of each sector */
#define SECTOR_SIZE             1024

/* LAST SECTOR */
#define IAP_LAST_SECTOR         15

/* Number of bytes to be written to the last sector */
#define IAP_NUM_BYTES_TO_WRITE  64

/* Number elements in array */
#define ARRAY_ELEMENTS          (IAP_NUM_BYTES_TO_WRITE / sizeof(uint32_t))

/* Initialize the array data to be written to FLASH */
for (i = 0; i < ARRAY_ELEMENTS; i++) {
src_iap_array_data = 0x11223340 + i;
}

/* Read Part Identification Number*/
part_id = Chip_IAP_ReadPID();
DEBUGOUT("Part ID is: %x\r\n", part_id);

/* Disable interrupt mode so it doesn't fire during FLASH updates */
__disable_irq();

/* IAP Flash programming */
/* Prepare to write/erase the last sector */
ret_code = Chip_IAP_PreSectorForReadWrite(IAP_LAST_SECTOR, IAP_LAST_SECTOR);

/* Error checking */
if (ret_code != IAP_CMD_SUCCESS) {
DEBUGOUT("Command failed to execute, return code is: %x\r\n", ret_code);
}

/* Erase the last sector */
ret_code = Chip_IAP_EraseSector(IAP_LAST_SECTOR, IAP_LAST_SECTOR);

/* Error checking */
if (ret_code != IAP_CMD_SUCCESS) {
DEBUGOUT("Command failed to execute, return code is: %x\r\n", ret_code);
}

/* Prepare to write/erase the last sector */
ret_code = Chip_IAP_PreSectorForReadWrite(IAP_LAST_SECTOR, IAP_LAST_SECTOR);

/* Error checking */
if (ret_code != IAP_CMD_SUCCESS) {
DEBUGOUT("Command failed to execute, return code is: %x\r\n", ret_code);
}

/* Write to the last sector */
ret_code = Chip_IAP_CopyRamToFlash(START_ADDR_LAST_SECTOR, src_iap_array_data, IAP_NUM_BYTES_TO_WRITE);

/* Error checking */
if (ret_code != IAP_CMD_SUCCESS) {
DEBUGOUT("Command failed to execute, return code is: %x\r\n", ret_code);
}

/* Re-enable interrupt mode */
__enable_irq();

----------------------
Everything executes fine until the Chip_IAP_EraseSector(IAP_LAST_SECTOR, IAP_LAST_SECTOR) function call; where Xpresso gets a HardFault_Handler call which ceases program execution.
I am just not quite sure how to debug what is causing this due to it is down inside the code embedded on the device itself.    I looked on LPCOpen forums and see that VECTPC register indicates a hint; my value is 0xFFFFFFFE which puts program counter clear up at the top of memory space?

I also see that the IAP uses the top 32 locations of RAM, so I adjusted the Top of stack to 0x10001f80, still no joy.


Any help or direction to what is going on and where to go/debug- is greatly appreciated.

Lon

Outcomes