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.

TMS570LC4357: Read modify write fails for Flash write

Part Number: TMS570LC4357
Other Parts Discussed in Thread: TMS570LS3137

I am porting existing code which executes without any issues on TMS570LS3137 to TMS570LC4357. I am able to initialize flash banks, erase, 64-bit writes, 64-bit aligned reads successfully. 

However, if I write to the flash 4-bytes at a time to contiguous addresses the Fapi_issueProgrammingCommand() call fails because (FAPI_GET_FSM_STATUS != Fapi_Status_Success). FAPI_GET_FSM_STATUS = 48 (undefined?). 

eg: 2 partial (4-byte) writes at address 0x320050:

  1. Bank1 sector erase: 0x320050 = 0xff 0xff 0xff 0xff 0xff 0xff 0xfe 0xff --> success
  2. 1st read-modify-write data= {0x1 0x2 0x3 0x4} : 0x320050 = 0x1 0x2 0x3 0x4 0xff 0xff 0xfe 0xff --> success
  3. 2nd read-modify-write data= {0x5 0x6 0x7 0x8} : 0x320050 =  ? --> fails with FAPI_GET_FSM_STATUS = 48

I expected the final contents to be 0x320050 = 0x1 0x2 0x3 0x4 0x5 0x6 0xf 0x8

I use the following API to write:

  while( FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmBusy );
  while( FAPI_GET_FSM_STATUS != Fapi_Status_Success );
  if(FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmReady) {
    status = Fapi_issueProgrammingCommand(
      reinterpret_cast<uint32_t*>(0x320050),
      local_buffer,
      8,
      nullptr,
      0,
      Fapi_AutoEccGeneration);
  while( FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmBusy);
  while(FAPI_GET_FSM_STATUS != Fapi_Status_Success);

Can you please provide some pointer regarding what I may be doing wrong? 

  • Hello Richa,

    You can not write data to the same address (0x320050). The flash content can be switch from 1 to 0 only.   

  • I have following questions:

    1. What does this status value mean : FAPI_GET_FSM_STATUS = 48?
    2. What is the data expected in the bank after erase? Can it be anything other than all 0xFF?
    3. This same test works fine for TMS570LS3137, but does not for TMS570LC4357 -- why is that if both flash have the same property of 1->0? 

  • Hello Richa,

    1. Please refer to the field definition of FMSTAT register in TRM:

    2. When performing flash erase, the erase for flash ecc is erased as well. After flash is erased, the content of the flash and flash ECC is 0xFFFFFFFF. For TMS570LC4357, the ECC is enabled by default. The value in memory browser is the adjusted value with wrong ECC (The ECC of 0xFFFFFFFF_FFFFFFFF is not 0xFF). The easy way is to program the ECC for the whole flash using linker command file:

    https://processors.wiki.ti.com/index.php/LAUNCHXL2-570LC43-RM57L:_LinkerECCRecommendation

    3. The flash on TMS570LS3137 and TMS570LC4357 are different. Different F021 Flash API library should be used for TMS570LC4357.

  • Hi QJ Wang,

    Thanks for the prompt reply! Yes I am using F021_API_CortexR4_BE_L2FMC_V3D16.lib for TMS570LC4357.

    I have few more questions:

    Say - the entire flash (along with corresponding ECC) is correctly programmed by the linker when I load the program. Then in my code, I erase a sector of flash using FAPI  Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, reinterpret_cast<uint32_t*>(sector_offset)); So the contents of the flash and corresponding ECC are 0xFFFFFFFF.

    1. Can a read to this sector cause an ECC error?
    2. Do I need to program appropriate ECC for the 0xFFFFFFFF data at the erased address before I can read contents at that address?

    Regards

    Richa

  • Hello Rita,

    1. You are correct. When you read the flash location whose ECC has not been programmed, you will get ECC erro.

    2. For TMS570LC43x, to avoid the ECC error, you need to program the ECC before reading the flash. For TMS570LS3137, flash ECC can be disabled before reading the blank flash.

  • Hi QJ Wang

    If I write 0xFFFFFFFF_00000000 to a flash address - the corresponding ECC (assume calculated ECC = 0x00000101) gets auto generated and filled when I use Fapi_AutoEccGeneration option in the Fapi_issueProgrammingCommand() API.

    If I want to modify the data at the same location to 0xFFFF0000_00000000 (assume corresponding ECC = 0x00000111)  -- is it possible to do that without erasing the entire sector?

    On TMS570LS3137 (with ECC disabled) I am able to successfully modify flash data from  0xFFFFFFFF_00000000 to 0xFFFF0000_00000000. But on TMS570LC4357 (with ECC enabled) I cannot -- it generates the FSMSTAT =0x30 error.

  • Hi Richa,

    It works for LC4357. This is the code I used for testing:

    void main(void)

    {

    uint32_t status;
    uint32_t size;
    uint32_t Success1[] = {0xbd0400ea, 0x00000000,
    0x00000000, 0x00000000,
    0x00000000, 0x00000000,
    0x00000000, 0x00000000,
    0x38b50546, 0x0c46062d,
    0x05d0082d, 0x03d00e2d,
    0x18bf0520, 0x08d11020,
    0x00f034fa, 0x03480460};

    uint32_t Success[] = {0xea0004bd, 0x00000000,
    0x00000000, 0x00000000,
    0x00000000, 0x00000000,
    0x00000000, 0x00000000,
    0x4605b538, 0x2d06460c,
    0x2d08d005, 0x2d0ed003,
    0x2005bf18, 0x2010d108,
    0xfa34f000, 0x60044803};

    uint32_t Success2[] = {0xFFFFFFFF, 0xFFFFFFFF,
    0xFFFFFFFF, 0x00000000};

    uint32_t Success3[] = {0xFFFFFFFF, 0xFFFFFFFF,
    0x00000000, 0x00000000};

    uint32_t Success4[] = {0xFFFFFFFF, 0x00000000};

    uint32_t Success5[] = {0xFFFF0000, 0x00000000};

    status = Fapi_BlockErase(1, 0x0200000, 64);

    //make sure "Fapi_AutoEccGeneration" is used in Flash API call, bl_flash.c
    status = Fapi_BlockProgram(1, 0x200000, (unsigned long)&Success, 64);

    status = Fapi_BlockProgram(1, 0x200120, (unsigned long)&Success, 64);

    status = Fapi_BlockProgram(1, 0x200200, (unsigned long)&Success2, 16);

    status = Fapi_BlockProgram(1, 0x200200, (unsigned long)&Success3, 16);

    status = Fapi_BlockProgram(1, 0x200220, (unsigned long)&Success4, 8);

    status = Fapi_BlockProgram(1, 0x200220, (unsigned long)&Success5, 8);

    while(1){};

    }

  • 1. After status = Fapi_BlockProgram(1, 0x200220, (unsigned long)&Success4, 8);

    2. After status = Fapi_BlockProgram(1, 0x200220, (unsigned long)&Success5, 8);

  • Hi QJ Wang

    Thanks for doing a quick test. However, I tried some more such examples where write fails.

    0xFFFFFFFF_00000000 to 0xFFFF0000_00000000 passes because at the particular address the ECC for both those values is the same. However, if I try  0xFFFF00FF_0000FFFF to 0xFFFF0000_00000000 then write fails.

    The ECC encoding table (Table-1) in this document (http://www.ti.com/lit/an/spna126/spna126.pdf) is missing third row in ADDR_MSW_LSW column and rows 3 and 8 in the CPU Pariy column.  

    Can you please share the full ECC econding table for TMS570LC4357?

  • The ECC encoding table is on Page 342 of TMS570LC4357 TRM.

  • Hello,

    The ECC value of try  0xFFFF00FF_0000FFFF at 0x200220 is 0x40, and ECC value of 0xFFFF0000_00000000 at 0x200220 is 0x4A. 

     When modifying flash data from  0xFFFFFFFF_00000000 to 0xFFFF0000_00000000, the data should be changed, but the ECC value can not be changed from 0x40 to 0x4A. The value read back from flash is corrected to 0xFFFFFFFF_00000000.