Other Parts Discussed in Thread: CONTROLSUITE, C2000WARE
bool FlashWrite(void)
{
Uint32 u32Index = 0;
Uint16 i = 0;
Fapi_StatusType oReturnCheck;
volatile Fapi_FlashStatusType oFlashStatus;
DINT;
//
// Gain pump semaphore
//
SeizeFlashPump();
Fapi_FlashStatusWordType oFlashStatusWord;
EALLOW;
//
// This function is required to initialize the Flash API based on System
// frequency before any other Flash API operation can be performed
//
oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, 200);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
return false;
}
//
// 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
//
return false;
}
//
// Verify that SectorL 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_SectorG_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)
//
return false;
}
// Start of Some snippet that fills the data to be written
// Doesn't call a function
// End of snippet that fills the data to be written
for(i = 0, u32Index = Bzero_SectorG_start;
(u32Index < (Bzero_SectorG_start + WORDS_IN_FLASH_BUFFER)) && (oReturnCheck == Fapi_Status_Success);
i+= 8, u32Index+= 8)
{
oReturnCheck = Fapi_issueProgrammingCommand((Uint32 *)u32Index,
Flash_Array + i,
8,
0,
0,
Fapi_AutoEccGeneration);
while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
return false;
}
//
// 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_doVerify((Uint32 *)u32Index,
4, pFlashArray+(i/2),
&oFlashStatusWord);
if(oReturnCheck != Fapi_Status_Success)
{
//
// Check Flash API documentation for possible errors
//
return false;
}
}
//
// Enable ECC
//
Flash0EccRegs.ECC_ENABLE.bit.ENABLE = 0xA;
EDIS;
EINT;
//
// Leave control over flash pump
//
ReleaseFlashPump();
return true;
}
I am having an issue with flash APIs here.
Above is a function which (as of now) writes some data in one of the sectors, and is written using the reference codes from controlSUITE.
When I debug, I can see that the value returned by 'Fapi_setActiveFlashBank(Fapi_FlashBank0);' is always 'Fapi_Error_InvalidHclkValue'. I have ensured that InitFlash() is getting called during the one-time initialization before the application loop.
What could be the problem?
Regards,
Prasad