This is the code
#define IAP_LOCATION 0x10400100
typedef void (*IAP)(unsigned int[5], unsigned int[4]);
unsigned int command_param[5];
unsigned int status_result[4];
IAP iap_myentry=(IAP)0x10400100;
/* Initializes the IAP command interface */
uint8_t Chip_IAP_Init(void)
{
uint32_t command[5], result[4];
command[0] = 49; /* IAP_INIT */
result[0] = IAP_CMD_SUCCESS;
delaymS(10);
iap_myentry(command, result);
return result[0];
}
/* Prepare sector for write operation */
uint8_t Chip_IAP_PreSectorForReadWrite(uint32_t strSector, uint32_t endSector, uint8_t flashBank)
{
uint32_t command[5], result[4];
command[0] = IAP_PREWRRITE_CMD;
command[1] = strSector;
command[2] = endSector;
command[3] = flashBank;
iap_myentry(command, result);
return result[0];
}
/* Copy RAM to flash */
uint8_t Chip_IAP_CopyRamToFlash(uint32_t dstAdd, uint32_t *srcAdd, uint32_t byteswrt)
{
uint32_t command[5], result[4];
command[0] = IAP_WRISECTOR_CMD;
command[1] = dstAdd;
command[2] = (uint32_t) srcAdd;
command[3] = byteswrt;
command[4] = SystemCoreClock / 1000;
iap_myentry(command, result);
return result[0];
}
/* Erase sector */
uint8_t Chip_IAP_EraseSector(uint32_t strSector, uint32_t endSector, uint8_t flashBank)
{
uint32_t command[5], result[4];
command[0] = IAP_ERSSECTOR_CMD;
command[1] = strSector;
command[2] = endSector;
command[3] = SystemCoreClock / 1000;
command[4] = flashBank;
iap_myentry(command, result);
return result[0];
}
/* Blank check sector */
uint8_t Chip_IAP_BlankCheckSector(uint32_t strSector, uint32_t endSector, uint8_t flashBank)
{
uint32_t command[5], result[4];
command[0] = IAP_BLANK_CHECK_SECTOR_CMD;
command[1] = strSector;
command[2] = endSector;
command[3] = flashBank;
iap_myentry(command, result);
return result[0];
}
/* Read part identification number */
uint32_t Chip_IAP_ReadPID()
{
uint32_t command[5], result[4];
command[0] = IAP_REPID_CMD;
iap_myentry(command, result);
return result[1];
}
/* Read boot code version number */
uint8_t Chip_IAP_ReadBootCode()
{
uint32_t command[5], result[4];
command[0] = IAP_READ_BOOT_CODE_CMD;
iap_myentry(command, result);
return result[0];
}
/* IAP compare */
uint8_t Chip_IAP_Compare(uint32_t dstAdd, uint32_t srcAdd, uint32_t bytescmp)
{
uint32_t command[5], result[4];
command[0] = IAP_COMPARE_CMD;
command[1] = dstAdd;
command[2] = srcAdd;
command[3] = bytescmp;
iap_myentry(command, result);
return result[0];
}
/* Reinvoke ISP */
uint8_t Chip_IAP_ReinvokeISP()
{
uint32_t command[5], result[4];
command[0] = IAP_REINVOKE_ISP_CMD;
iap_myentry(command, result);
return result[0];
}
/* Read the unique ID */
uint32_t Chip_IAP_ReadUID(uint32_t uid[])
{
uint32_t command[5], result[5], i;
command[0] = IAP_READ_UID_CMD;
iap_myentry(command, result);
for(i = 0; i < 4; i++) {
uid[i] = result[i + 1];
}
return result[0];
}
/* Erase page */
uint8_t Chip_IAP_ErasePage(uint32_t strPage, uint32_t endPage)
{
uint32_t command[5], result[4];
command[0] = IAP_ERASE_PAGE_CMD;
command[1] = strPage;
command[2] = endPage;
command[3] = SystemCoreClock / 1000;
iap_myentry(command, result);
return result[0];
}
/* Set active boot flash bank */
uint8_t Chip_IAP_SetBootFlashBank(uint8_t bankNum)
{
uint32_t command[5], result[4];
command[0] = IAP_SET_BOOT_FLASH;
command[1] = bankNum;
command[2] = SystemCoreClock / 1000;
iap_myentry(command, result);
return result[0];
}
When ever i call API(lets say - Chip_IAP_Init()) from main, it gives error at iap_myentry(command, result) as hard fault error.
How to get rid from this.
Hi Saurav,
Please refer to NXP official LPC4367 lpcopen sample code, you can download it from this link:
LPCOpen Software for LPC43XX|NXP
There has a project named as flashiap is the flash IAP project.
You can open folder:lpcopen_3_02_keil_iar_xpresso4337\LPC43xx_18xx\prj_xpresso4337\iar, periph_examples.eww.
The IAP address should defined like this:
/* Pointer to ROM API function address */
#define LPC_ROM_API_BASE_LOC 0x10400100
#define LPC_ROM_API ((LPC_ROM_API_T *) LPC_ROM_API_BASE)
/* Pointer to ROM IAP entry functions */
#define IAP_ENTRY_LOCATION (*((uint32_t *) 0x10400100))
Wish it helps you!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------