Hello TI Community,
I have a problem with the Flash API on TMS570LS3137 (the HDK kit). I am using the example code from the F021 Flash API (SPNU501G) for a single byte flash record and I try to verify whether it has been written correctly. For that purpose I used Fapi_doVerifyByByte().
Unfortunately, when I add the source code after the example code or before the FSM registers re-lock function, something really strange happens - my code cannot reach even the beginning - the Bank0 initialization.
Here is my code, after I have commented the problematic pieces with "////":
void main(void)
{
sciInit();
PutText(scilinREG, "\rPutText is working!\n");
sciDisplayText(scilinREG, (uint8_t *)"\rReally working\n", sizeof("\rReally working\n"));
Fapi_StatusType oReturnCheck = Fapi_Status_Success;
FwpWriteByteAccessorType * oFwpWriteByteAccessor = FWPWRITE_BYTE_ACCESSOR_ADDRESS;
FwpWriteByteAccessorType * oFwpWriteEccByteAccessor = FWPWRITE_ECC_BYTE_ACCESSOR_ADDRESS;
FwpWriteDWordAccessorType * oFwpWriteDWordAccessor = FWPWRITE_DWORD_ACCESSOR_ADDRESS;
////Fapi_FlashStatusWordType oVerifyByByte;
////uint8_t cmp_buffer[3] = { 0xA5, 0xA5, 0xA5 };
uint8 au8MainDataBuffer[16] = {0x78, 0x17, 0x19, 0x2E, 0x0A, 0xB9, 0x11, 0x70,
0x5F, 0xC1, 0x9C, 0xFD, 0x54, 0x51, 0xED, 0x86};
uint32 u32Index;
/*
For proper initialization of the device prior to any Flash
operations,
see the device-specific initialization document.
Assumes, unless otherwise noted, device has 144bit wide Flash Banks.
*/
oReturnCheck = Fapi_initializeFlashBanks(160); /* Example code is assuming operating
frequency of 180 MHz */
if((oReturnCheck == Fapi_Status_Success) && (FLASH_CONTROL_REGISTER->FmStat.FMSTAT_BITS.BUSY != Fapi_Status_FsmBusy))
{
oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank0);
/* Place specific example code here */
PutText(scilinREG, "\rFlashBank0 set active\n");
/* Wait for FSM to finish */
while(FLASH_CONTROL_REGISTER->FmStat.FMSTAT_BITS.BUSY == Fapi_Status_FsmBusy);
/* Check the FSM Status to see if there were no errors */
if (FLASH_CONTROL_REGISTER->FmStat.u32Register != 0)
{
/* Put Error handling code here */
PutText(scilinREG, "\r\nFlash init ERROR\n");
}
else
{
PutText(scilinREG, "\r\nSeems like working\n");
}
}
FLASH_CONTROL_REGISTER->Fbprot.u32Register = 1U; /* Disable Level 1 Protection */
/* Enable all sectors of current bank for erase and program. For EEPROM banks with more
than 16 sectors, this must be 0xFFFF */
FLASH_CONTROL_REGISTER->Fbse.u32Register = 0xFFFF;
FLASH_CONTROL_REGISTER->Fbprot.u32Register = 0U; /* Enable Level 1 Protection */
/*Unlock FSM registers for writing */
FLASH_CONTROL_REGISTER->FsmWrEna.u32Register = 0x5U;
/* Set command to "Clear the Status Register" */
FLASH_CONTROL_REGISTER->FsmCommand.FSM_COMMAND_BITS.FSMCMD = Fapi_ClearStatus;
/* Execute the Clear Status command */
FLASH_CONTROL_REGISTER->FsmExecute.FSM_EXECUTE_BITS.FSMEXECUTE = 0x15U;
/* Write address to FADDR register */
FLASH_CONTROL_REGISTER->Faddr.u32Register = 0x0100U;
/* Placing byte at address 0x0102 */
oFwpWriteByteAccessor[2] = 0xA5;
/* Set command to "Program" */
FLASH_CONTROL_REGISTER->FsmCommand.FSM_COMMAND_BITS.FSMCMD = Fapi_ProgramData;
/* Execute the Program command */
FLASH_CONTROL_REGISTER->FsmExecute.FSM_EXECUTE_BITS.FSMEXECUTE = 0x15U;
////oReturnCheck = Fapi_Error_Fail;
////oReturnCheck = Fapi_doVerifyByByte((uint8_t *)0x102U, 1, cmp_buffer, &oVerifyByByte);
////if(oReturnCheck == Fapi_Status_Success)
////{
//// PutText(scilinREG, "Byte written correctly");
////}
////else {PutText(scilinREG, "Byte NOT written correctly");}
/* re-lock FSM registers to prevent writing */
FLASH_CONTROL_REGISTER->FsmWrEna.u32Register = 0x2U;
while(1);
/* USER CODE END */
}
As I mentioned, I also tried to invoke the Fapi_doVerifyByByte() function after the whole example code, after the FSM lock - I did it with initialized Fapi_FlashStatusWordType, different cmp_buffer sizes but the result was just the same.
My end goal is to write a byte, verify it, read it and erase it.
Thank you in advance.
Kind regards,
Varban