Hi!
I have a strange problem with SPIFI flash block erase on LPC4330. I am using lpcspifilib. Generally the spifiEraseAll function is working properly but I need to perform block erase. Below is my code:
SPIFI_ERR_T result;
SPIFI_HANDLE_T * spifiHandle = spifiInitDevice(&spifiHandleBuffer,sizeof(spifiHandleBuffer),SPIFI_CONTROLLER_ADDRESS, (uint32_t) manParams->address);
spifiDevSetOpts(spifiHandle, SPIFI_OPT_USE_QUAD, false);
spifiDevSetMemMode(spifiHandle, false);
uint32_t maxSpifiClock = spifiDevGetInfo(spifiHandle, SPIFI_INFO_MAXCLOCK);
Chip_Clock_SetDivider(CLK_IDIV_E,CLKIN_MAINPLL,(1+(Chip_Clock_GetClockInputHz(CLKIN_MAINPLL)/maxSpifiClock)));
result = spifiDevUnlockDevice(spifiHandle);
// if there are any errors - operation failed
if (result != SPIFI_ERR_NONE)
{
result = spifiDevLockDevice(spifiHandle);
result = spifiDevDeInit(spifiHandle);
return USBD_STATUS_FAILED;
}
uint32_t * header = (uint32_t *) params->recData;
result = spifiEraseByAddr(spifiHandle, (uint32_t) LPC4330_APPLICATION_BASE_ADDRESS, (uint32_t) (LPC4330_APPLICATION_BASE_ADDRESS + 72));
if (result != SPIFI_ERR_NONE)
{
result = spifiDevLockDevice(spifiHandle);
result = spifiDevDeInit(spifiHandle);
return USBD_STATUS_FAILED;
}
//result = spifiDevRead(spifiHandle, manParams->address, &checkBuffer, params->wLength);
result = spifiDevLockDevice(spifiHandle);
result = spifiDevDeInit(spifiHandle);
return USBD_STATUS_SUCCESS;
spifiInit function, registering family, pin and clock configuration are done on the start of the application. The next strange thing - this code worked... and in one moment it stopped working. Am I doing everything properly?
Hi Tomasz,
Maybe you can try using the spifilib example that comes with the LPCopen package for the NGX Xplorer LPC4330 board as starting point for your project, you can download the package from this link:
LPCOpen Software for LPC43XX|NXP
Regarding the spifiEraseByAddr function, please make sure that the passed address range is valid. You can use the spifiGetAddrFromBlock function to get the starting address of a block an use this as starting address, after that you can add the number of blocks you want to erase to the starting addres multiplied by the size of the erase blocks and use this address as ending address.
Hope it helps!
Best Regards,
Carlos Mendoza
Technical Support Engineer