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.

TMS570LS0432: Cannot write/read from flash (Newbie)

Part Number: TMS570LS0432
Other Parts Discussed in Thread: HALCOGEN

Hello all,

As a graduate engineer who is newbie in embedded world,  the embedded project i am working on requires me to write a variable to the flash and use it when power cut off and comes back again. I am trying to get the fee example in HALCoGeN to work but no luck till now. I am watching the expressions from example code like "SpecialRamBlock[0]" and "oResult" if "BlockNumber" 1 is written to them or can be read from them but i don't see anything changes in debug. I left my HALCoGeN configuration default as instructed in example and i am using the example code just the way it is.

Example code:

#include "ti_fee.h"
/* USER CODE END */

/* Include Files */
#include "sys_common.h"
/* USER CODE BEGIN (1) */


uint16 u16JobResult,Status;
Std_ReturnType oResult=E_OK;
unsigned char read_data[100]={0};

uint8 SpecialRamBlock[100];

unsigned char pattern;
uint16 u16writecounter;

unsigned int  FeeVirtualSectorNumber;
unsigned char VsState, u8EEPIndex;
unsigned char u8VirtualSector;
uint8 Test_Recovery;
uint8 Test_Cancel;

void delay(void)
{
    unsigned int dummycnt=0x0000FFU;
    do
    {
        dummycnt--;
    }
    while(dummycnt>0);
}
/* USER CODE END */

/* USER CODE BEGIN (2) */
/* USER CODE END */

void main(void)
{
/* USER CODE BEGIN (3) */
    unsigned int BlockNumber;
    unsigned int BlockOffset, Length;
    unsigned char *Read_Ptr=read_data;

    unsigned int loop;
    
    /* Initialize RAM array.*/
    for(loop=0;loop<100;loop++)SpecialRamBlock[loop] = loop;

    /* Initialize FEE. This will create Virtual sectors, initialize global variables etc.*/
    TI_Fee_Init();
    do
    {
        TI_Fee_MainFunction();
        delay();
        Status=TI_Fee_GetStatus(0 );
    }
    while(Status!= IDLE);

    /* Write the block into EEP Asynchronously. Block size is configured in ti_fee_cfg.c file. Default Block size is 
       8 bytes */
    BlockNumber=0x1;
    TI_Fee_WriteAsync(BlockNumber, &SpecialRamBlock[0]);
    do
    {
        TI_Fee_MainFunction();
        delay();
        Status=TI_Fee_GetStatus(0);
    }
    while(Status!=IDLE);

    /* Write the block into EEP Synchronously. Write will not happen since data is same. */
    TI_Fee_WriteSync(BlockNumber, &SpecialRamBlock[0]);

    /* Read the block with unknown length */
     BlockOffset = 0;
     Length = 0xFFFF;
     oResult=TI_Fee_Read(BlockNumber,BlockOffset,Read_Ptr,Length);
     do
     {
         TI_Fee_MainFunction();
         delay();
         Status=TI_Fee_GetStatus(0);
     }
    while(Status!=IDLE);

    /* Invalidate a written block  */
    TI_Fee_InvalidateBlock(BlockNumber);
    do
    {
        TI_Fee_MainFunction();
        delay();
        Status=TI_Fee_GetStatus(0);
    }
    while(Status!=IDLE);

    /* Format bank 7 */
    TI_Fee_Format(0xA5A5A5A5U);

    while(1);

Default HALCoGeN configuration..

I believe i have linked F021 flash API and included the F021 headers..

Can you help me out in this seemingly simple matter ? What do i miss out ? Thanks in advance..

  • Hello,

    oResult should be 0 if execution went fine - for example if the read job was accepted by the TI FEE module. The values that was read from the EEPROM are in read_data ( pointed by  Read_Ptr). You can use Memory browser to see whether values are written to EEPROM. Bank 7 ( bank7 is used for EEPROM emulation ) starts from address: 0xF020 0000. SpecialRamBlock should be filled with 0-99 after the following code is executed and this is not related with FEE driver or EEPROM.

    /* Initialize RAM array.*/

        for(loop=0;loop<100;loop++)SpecialRamBlock[loop] = loop;
    After that values from SpecialRamBlock (0-99) are written to EEPROM.
    If everything went fine 0-99 should be read from EEPROM and written to read_data.
    Best regards,
    Miro

    Best regards,
    Miro

  • Hello Miro,

    As you said i have read the array from read_data which was a rookie mistake not to see it i suppose and i see that starting from 0xF0200000 the sector 0 changes when SpecialRamBlock is written. 

    Then i moved on to clearing out the functionality i didn't need (since i only need writing and reading from flash) and refined the code. What i don't understand is i exit the debug and power off the launchpad but when i power it on again, comment out the writing part and re-debug again i see that the sector 0 is completely erased. 

    Here's the new code;

    #include "ti_fee.h"
    #include "sys_common.h"
    
    uint16 u16JobResult,Status;
    Std_ReturnType oResult=E_OK;
    unsigned char read_data[100]={0};
    uint8 SpecialRamBlock[100];
    unsigned char pattern;
    uint16 u16writecounter;
    unsigned int  FeeVirtualSectorNumber;
    unsigned char VsState, u8EEPIndex;
    unsigned char u8VirtualSector;
    uint8 Test_Recovery;
    uint8 Test_Cancel;
    
    void delay(void)
    {
        unsigned int dummycnt=0x0000FFU;
    
        do
        {
            dummycnt--;
        }
        while(dummycnt>0);
    }
    
    void main(void)
    {
        unsigned int BlockNumber;
        unsigned int BlockOffset, Length;
        unsigned char *Read_Ptr=read_data;
        unsigned int loop;
    
        /* Initialize RAM array.*/
        for(loop=0;loop<100;loop++)SpecialRamBlock[loop] = loop;
    
        /* Initialize FEE. This will create Virtual sectors, initialize global variables etc.*/
    
        TI_Fee_Init();
        do
        {
            TI_Fee_MainFunction();
            delay();
            Status=TI_Fee_GetStatus(0 );
        }
        while(Status!= IDLE);
    
        /* Write the block into EEP Asynchronously. Block size is configured in ti_fee_cfg.c file. Default Block size is
           8 bytes */
    
        BlockNumber=0x1;
    
        TI_Fee_WriteAsync(BlockNumber, &SpecialRamBlock[0]);
        do
        {
            TI_Fee_MainFunction();
            delay();
            Status=TI_Fee_GetStatus(0);
        }
        while(Status!=IDLE);
    
        /* Read the block with unknown length */
         BlockOffset = 0;
         Length = 0xFFFF;
    
         oResult=TI_Fee_Read(BlockNumber,BlockOffset,Read_Ptr,Length);
         do
         {
             TI_Fee_MainFunction();
             delay();
             Status=TI_Fee_GetStatus(0);
         }
        while(Status!=IDLE);
    }

    So now it's only write and then read. When i power off and power it back on again and only use the read part of the code, i am supposed to see the stored array right ? Am i wrong ? 

  • It was the CCS settings :) When debugging CCS was erasing bank 7 as well. I have unticked bank 7 and now example code works perfectly. Thanks again Miro. Couldn't have done it without you pointing out read_data. One little question though, do i need to include F021.h ? Or what is the relationship between FEE driver and F021 API ? FEE driver uses the F021 state machine ? 

    Best Regards,

    Metin