This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

F28M35H52C: F021 Flash API Fapi_issueAsyncCommandWithAddress not erasing the Flash sector on M3

Part Number: F28M35H52C
Other Parts Discussed in Thread: CONTROLSUITE

I am trying to have Flash API function Erase one of the sector of M3 Flash Memory (Sector L). I have followed all the necessary steps suggested in the FLASH API application note and using the same set of F021 Libary and functions used in one of the Control suite example. 

I am particularly having challenge when software execution passes Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, (uint32 *)Bzero_SectorL_start) and passes the while condition after this. When i observe the memory browser for Sector L, I do not see it getting flashed but it still retain the same code. 

Below are some screenshots of what i have been observing while trying to erase the sector. 

Here the function i call to perform some Flash operations.

#pragma CODE_SECTION(CallFlashAPI, "ramfuncs");
bool CallFlashAPI(void)
{
uint32 u32Index = 0;
uint16 i = 0;

Fapi_StatusType oReturnCheck;
volatile Fapi_LibraryInfoType oLibInfo;
volatile Fapi_FlashStatusType oFlashStatus;
Fapi_FlashBankSectorsType oFlashBankSectors;
Fapi_FlashStatusWordType oFlashStatusWord;

// This function is required to initialize the Flash API based on System
// frequency before any other Flash API operation can be performed

#if CPU_FRQ_125MHZ
oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, 125);
#endif

#if CPU_FRQ_100MHZ
oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, 100);
#endif

#if CPU_FRQ_75MHZ
oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, 75);
#endif

#if CPU_FRQ_60MHZ
oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, 60);
#endif

if(oReturnCheck != Fapi_Status_Success)
{
//Check Flash API documentation for possible errors
Error(oReturnCheck);
}

// Fapi_getLibraryInfo function can be used to get the information
// specific to the compiled version of the API library
oLibInfo = Fapi_getLibraryInfo();

// Fapi_setActiveFlashBank function sets the Flash bank and FMC
// for further Flash operations to be performed on the bank
oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank0);
if(oReturnCheck != Fapi_Status_Success)
{
// Check Flash API documentation for possible errors
Error(oReturnCheck);
}

// Fapi_getBankSectors function returns the bank starting address,
// number of sectors, sector sizes, and bank technology type
// Above information is returned in a structure oFlashBankSectors of type
// Fapi_FlashBankSectorsType
oReturnCheck = Fapi_getBankSectors(Fapi_FlashBank0,&oFlashBankSectors);
if(oReturnCheck != Fapi_Status_Success)
{
// Check Flash API documentation for possible errors
Error(oReturnCheck);
}

// Erase Sector L
// Sector N has the example code so leave it programmed
oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector,
(uint32 *)Bzero_SectorL_start);

// Wait until FSM is done with erase sector operation
while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}

// Verify that Sector L is erased. The Erase step itself does a verify
// as it goes. This verify is a 2nd verification that can be done.
oReturnCheck = Fapi_doBlankCheck((uint32 *)Bzero_SectorL_start,
/*Bzero_32KSector_u32length*/420,
&oFlashStatusWord);
if(oReturnCheck != Fapi_Status_Success)
{
//Check Flash API documentation for possible errors
//If Erase command fails, use Fapi_getFsmStatus() function to get
// the FMSTAT register contents
//to see if any of the EV bit, ESUSP bit, CSTAT bit or VOLTSTAT
//bit is set (Refer to API documentation for more details)
Error(oReturnCheck);
}

// Erase Sector K
// Sector N has the example code so leave it programmed
oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector,
(uint32 *)Bzero_SectorK_start);

// Wait until FSM is done with erase sector operation
while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}

// Verify that SectorK is erased. The Erase step itself does a verify as
// it goes. This verify is a 2nd verification that can be done.
oReturnCheck = Fapi_doBlankCheck((uint32 *)Bzero_SectorK_start,
Bzero_16KSector_u32length,
&oFlashStatusWord);

if(oReturnCheck != Fapi_Status_Success)
{
// Check Flash API documentation for possible errors
// If Erase command fails, use Fapi_getFsmStatus() function to get
// the FMSTAT register contents
// to see if any of the EV bit, ESUSP bit, CSTAT bit or VOLTSTAT bit is
// set (Refer to API documentation for more details)
Error(oReturnCheck);
}

// Example: Program 0xFF bytes in Flash Sector K along with auto generated ECC

// In this case just fill a buffer with data to program into the flash.
for(i=0;i<=BYTES_IN_FLASH_BUFFER;i++)
{
Buffer[i] = i;
}

// Example: Program 0xFF bytes in Flash Sector K with out ECC
// Disable ECC so that error is not generated when reading Flash
// contents without ECC
HWREG(FLASH_ERROR_BASE + FLASHERR_O_ECC_ENABLE) = 0x0;

for(i=0, u32Index = Bzero_SectorK_start;
(u32Index < (Bzero_SectorK_start + BYTES_IN_FLASH_BUFFER))
&& (oReturnCheck == Fapi_Status_Success); i+= 16, u32Index+= 16)
{
oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)u32Index,
Buffer+i,
16,
0,
0,
Fapi_DataOnly);

while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);

if(oReturnCheck != Fapi_Status_Success)
{
//Check Flash API documentation for possible errors
Error(oReturnCheck);
}

//Read FMSTAT register contents to know the status of FSM after
// program command for any debug
oFlashStatus = Fapi_getFsmStatus();

// Verify the values programmed. The Program step itself does a verify
// as it goes. This verify is a 2nd verification that can be done.
oReturnCheck = Fapi_doVerifyByByte((uint8 *)u32Index,
16,
Buffer+i,
&oFlashStatusWord);

if(oReturnCheck != Fapi_Status_Success)
{
//Check Flash API documentation for possible errors
Error(oReturnCheck);
}
}

//Erase Sector K
//Sector N has the example code so leave it programmed
oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector,
(uint32 *)Bzero_SectorK_start);
//Wait until FSM is done with erase sector operation
while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
// Verify that SectorK is erased. The Erase step itself does a verify as
// it goes. This verify is a 2nd verification that can be done.
oReturnCheck = Fapi_doBlankCheck((uint32 *)Bzero_SectorK_start,
Bzero_16KSector_u32length,
&oFlashStatusWord);
if(oReturnCheck != Fapi_Status_Success)
{
// Check Flash API documentation for possible errors
// If Erase command fails, use Fapi_getFsmStatus() function to get the
// FMSTAT register contents
// to see if any of the EV bit, ESUSP bit, CSTAT bit or VOLTSTAT bit
// is set (Refer to API documentation for more details)
Error(oReturnCheck);
}

// Enable ECC
HWREG(FLASH_ERROR_BASE + FLASHERR_O_ECC_ENABLE) = 0xA;

// Leave control over pump
FlashLeavePump();

return gTRUE;

}

Also  i configured the M3 for 75Mhz frequency. 

Any hints on what i could i be doing wrong ??

Thanks