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.

TMS570LS1224: Code to test flash by erasing and writing data

Part Number: TMS570LS1224


Hi,

I would like to write a code to test the flash erase and write.
Suppose I want to write a byte of data (0x1) to the address (0x00010100).
FlashDestination would be: 0x00010100
buf would be: uint8 buf[1] = {0x1}
data_size would be: 1
imageSize would be: 1
Do you think the following code would be ok for unit test:

// Initialize the Flash Wrapper registers.
oReturnCheck = 0;
oReturnCheck = Fapi_BlockErase(Bank0, FlashDestination, imageSize);
// Return an error if an access violation occurred.
if(oReturnCheck)
{
state = AbortHeader;
}
oReturnCheck = 0;

oReturnCheck = Fapi_BlockProgram(Bank0, FlashDestination, buf, data_size);
if(oReturnCheck)
{
// Indicate that the flash programming failed.
state = AbortHeader;
}


Thanks and regards,
Abrar

  • Hello Abrar,
    You question is addressed and will be answered by one of our experts.

    Best regards,
    Miro
  • Hello Abrar,

    The address should be aligned on a 64-bit boundary: 0x......00, 0x......08. You can write 1 byte data, but the ecc is calculated using your 1-byte data with appended zero (56 bits).

    The flash state-machine can actually program 16 bytes of data and 2 bytes of ECC in a single operation. It will make programming faster. I did this way in bootloader example code.
  • Hi,

    Thanks for your reply.

    I tried to store a 16 byte buffer:

    uint8 buf[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};

    to an Address: 0x00120000

    Upon checking the contents in the memory window it shows as follows:

    Has it stored data wrongly in the flash?

    Thanks and regards,

    Abrar

  • Hello Abrar,

    You need to execute your code in SRAM.

    This is my code and test result. 

  • Hi,

    Thanks for your reply.

    I am using IAR v8.22.2.

    So I had to add the following lines to my linker file:

    initialize by copy { object F021_API_CortexR4_BE.lib };

    initialize by copy { object bl_flash.o };

    In the F021 Flash API Header file - CGT.IAR.h,  I replaced #if !defined(__LITTLE_ENDIAN__) with #if (__LITTLE_ENDIAN__ == 0) .

    And in the code, I had to disable interrupts before flash operation.

      uint8 buf[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
      uint8 rbuf[16] = {0};
      
      _disable_interrupt_();
    
      oReturnCheck = Fapi_BlockErase(0x0, 0x00120000, 0x1000);
      // Return an error if an access violation occurred.
      if(oReturnCheck)
      {
        state = AbortHeader;
      }
    
      oReturnCheck = Fapi_BlockProgram(0x0,0x00120000,(uint32)buf,16);
      if(oReturnCheck)
      {
        // Indicate that the flash programming failed.
        state = AbortHeader;
      }
    
      Fapi_BlockRead(0x0,(uint32)rbuf,0x00120000,16);
    
      _enable_interrupt_();

    Regards,

    Abrar