Hi,
I'm trying to use the flash API and try to program FLASH but it always returns failure. From the manual the INVDAT will be set if I'm trying to write 0 to 1 in flash. Before I write to FLASH I have erased the flash (also checked with functions everything is OK and with memory browser that is is all 0xFFFF) but it doesn't help. What am I doing wrong?
Here is some code how am I trying to do it:
uint32_t addressToErase = 0x8F000;
uint16_t data[4];
data[0] = 0x10;
data[1] = 0x11;
data[2] = 0x12;
data[3] = 0x13;
Fapi_StatusType flashStatus = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, (uint32_t *)addressToErase);
while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady);
if (flashStatus != 0)
{
// Handle error
}
else
{
if (Fapi_getFsmStatus() != 0u)
{
// Handle error
}
else
{
// Check if blank
Fapi_FlashStatusWordType flashStatusWord;
flashStatus = Fapi_doBlankCheck((uint32_t *)addressToErase, 0x1000, &flashStatusWord);
if (flashStatus != Fapi_Status_Success)
{
// Handle error
}
else
{
flashStatus = Fapi_issueProgrammingCommand(&addressToErase, &data[0], 4, NULL, 0u, Fapi_AutoEccGeneration);
// Wait until the Flash program operation is over
while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady);
if (flashStatus != Fapi_Status_Success)
{
Will always come here because INVDAT is 1
// Handle error
}
....
}
}
}