Other Parts Discussed in Thread: CONTROLSUITE
Hi Team,
Posting for a colleague.
What I’m trying to do:
I am trying to write a small block of data to an unused FLASH memory sector. Evenually, I will use the TI EEPROM emulation functions, but for starters I have been trying to write a small number of bytes to the FLASH using the API and then read it back in a simple function with directly addresses the memory in flash. FYI- I am writing 8 bytes to flash, in an attempt to keep the data boundary correct.
What is the problem:
When I do a flash read (after a flash write), the processor encounters an unconfigured interrupt. I’ve assumed that it was the “correctable error fault” but it does not seem to be this fault. When I try to trap the interrupt and figure out where it came from, I don’t see any flags that point to where the interrupt came from.
My assumptions:
I’ve been assuming that I’m getting an ECC error, but I can’t prove it. My flash writing code is adapted from an example that I got from controlSuite, so I assume that it is writing correctly. But then again, I am not too savvy with flash writing, so I really don’t even know what questions to ask when it comes to what is going wrong. I noticed there is a mention of FLASH errors in the silicon errata for this device (document SPRZ423D), but the errata specifically states that this only occurs if the error is caused by a program fetch operation, not a data read. I am reading data, so I assume this is not applicable. Also FYI, I am using TMS rev C silicon.
Using customer hardware with CCS Version: 6.1.1.00022. Adapted a software example. Code below:
Have: F021_API_F2837xD_FPU32.lib file in my project, and I have F021_F2837xD_C28.h #included in Fapi_UserDefinedFunctions.c.
void eeprom_write(void)
{
uint32 u32Index = 0;
uint16 i = 0;
Fapi_StatusType oReturnCheck;
volatile Fapi_FlashStatusType oFlashStatus;
Fapi_FlashStatusWordType oFlashStatusWord;
// Disable ECC. ECC does not have to be disabled to do FSM operations like
// program and erase.
// However, on Sonata Rev. 0 silicon, due to an OTP ECC errata,
// disable ECC to avoid ECC errors while using Flash API functions that
// read TI-OTP
INT_DISABLE;
/*
EALLOW;
Flash0EccRegs.ECC_ENABLE.bit.ENABLE = 0x0;
EDIS;
*/
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, 120);
if(oReturnCheck != Fapi_Status_Success)
{
// Check Flash API documentation for possible errors
Example_Error(oReturnCheck);
}
// 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
Example_Error(oReturnCheck);
}
// Erase Sector B
oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector,
(uint32 *)Bzero_SectorB_start);
// Wait until FSM is done with erase sector operation
while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
// Verify that SectorB 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_SectorB_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)
Example_Error(oReturnCheck);
}
// A data buffer of max 8 words can be supplied to the program function.
// Each word is programmed until the whole buffer is programmed or a
// problem is found. However to program a buffer that has more than 8
// words, program function can be called in a loop to program 8 words for
// each loop iteration until the whole buffer is programmed
/*
// Example: Program 0xFF bytes in Flash Sector B with out ECC
// Disable ECC so that error is not generated when reading Flash contents
// without ECC
Flash0EccRegs.ECC_ENABLE.bit.ENABLE = 0x0;
*/
for(i=0; i<=WORDS_IN_FLASH_BUFFER; i++)
{
Buffer[i] = i;
}
for(i=0, u32Index = Bzero_SectorB_start;
(u32Index < (Bzero_SectorB_start + WORDS_IN_FLASH_BUFFER))
&& (oReturnCheck == Fapi_Status_Success); i+= 8, u32Index+= 8)
{
oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)u32Index,
read_flash_buffer+i,
8,
0,
0,
Fapi_AutoEccGeneration);
while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);
if(oReturnCheck != Fapi_Status_Success)
{
// Check Flash API documentation for possible errors
Example_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_doVerify((uint32 *)u32Index,
4,
Buffer32+(i/2),
&oFlashStatusWord);
if(oReturnCheck != Fapi_Status_Success)
{
// Check Flash API documentation for possible errors
Example_Error(oReturnCheck);
}
}
EDIS;
INT_ENABLE;
}
void Example_Error(Fapi_StatusType status)
{
// Error code will be in the status parameter
// __asm(" ESTOP0");
}
void flash_read(void)
{
Uint16 i;
extern Uint16 eeprom_data_load_start;
for (i=0; i < WORDS_IN_FLASH_BUFFER; i++)
{
*(read_flash_buffer + i) = *(&eeprom_data_load_start + i);
}
flash_pack_struct_from_buffer(); // take values from flash and pack into the eeprom_data_buffer struct
} // end of function flash_read()
This snippet is from the .cmd file which calls out the location of the eeprom_data in the FLASH.
eeprom_data : LOAD = FLASHB,
LOAD_START(_eeprom_data_load_start),
LOAD_END(_eeprom_data_load_end),
PAGE = 0, ALIGN(4)
Thank you for the assistance,
Nate
