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: Using EEPROM with flash021 API to write persistent data

Other Parts Discussed in Thread: HALCOGEN

Hello,

I am requriing some help for the following: my need is to write some configuration parameters in a non volatile memory (parameters should not be lost after a power off of the µC). It's not a big amount of data, something like 25 or maybe 30 doubles, which is about 240 bytes.

I was thinking of using the flash EEPROM to do this, as it is made for this from what I understood.

So I tried the exemple shown in HalCogen, but it does not work: the code stay stuck in the first loop, because the Status is always UNINIT.

Here is the exemple code below:

void write_to_flash(void)
{
    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;

    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);
}

I have installed the flash API correctly I guess, and link the code with "C:\ti\Hercules\F021 Flash API\02.01.01\F021_API_CortexR4_BE_L2FMC_V3D16.lib"
I have done nothing in HalCogen, except enable FEE drivers. And I am using FreeRTOS.
Any clue would be helpful.
I really read a lot of topic, but found no answer on how to make this work. The documentation is not very clear about it, and even if my need is really basic, I could not figure it out.

Thanks

Audry

  • Hello,
    Did you try the example while not using RTOS?

    Best regards,
    Miro
  • Hello,
    Yes, I also tried making a new project without freeRTOS, but it still does not work (same issue, stuck in UNINIT state)
    Also, this would not be a solution as I absolutely need FreeRTOS in my application.
  • Hello,

    F021_API_CortexR4_BE_L2FMC_V3D16.lib is for TMS570LCx device. Please use F021_API_CortexR4_BE_V3D16.lib

    Regards
    Akshay
  • Thanks ! The function seems not blocking anymore.

    However, I am not sure it work properly: I have splitted the exemple in 2 function, one to write and one to read:

    void write_to_flash(void)
    {
        uint16 u16JobResult,Status;
        Std_ReturnType oResult=E_OK;
        unsigned char read_data[100]={0};
    
        uint8 SpecialRamBlock[100] = {0x42};
    
        unsigned char pattern;
        uint16 u16writecounter;
    
        unsigned int  FeeVirtualSectorNumber;
        unsigned char VsState, u8EEPIndex;
        unsigned char u8VirtualSector;
        uint8 Test_Recovery;
        uint8 Test_Cancel;
    
        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;
        /* Write the block into EEP Synchronously. Write will not happen since data is same. */
        TI_Fee_WriteSync(BlockNumber, &SpecialRamBlock[0]);
    }
    
    void read_from_flash(uint8_t* value_read)
    {
        unsigned int BlockNumber = 0x01;
        unsigned int BlockOffset, Length;
        uint16 u16JobResult,Status;
        Std_ReturnType oResult=E_OK;
        /* Read the block with unknown length */
         BlockOffset = 0;
         Length = 0xFFFF;
         oResult=TI_Fee_Read(BlockNumber,BlockOffset,value_read,Length);
         do
         {
             TI_Fee_MainFunction();
             delay();
             Status=TI_Fee_GetStatus(0);
         }
        while(Status!=IDLE);
    }

    This does not block, and seems to work partially. I mean:

    - If in the main, I do a write, then a read, the read data is OK

    - If I just do the read (assuming write has been done earlier, I want to check that data are saved permanently in the memory), I only read 0, it's like the data has been deleted ?

  • If anyone is interrested, the erasing of the flash was due to the debugger options. I configured it to not erase FlashBank7, and now it works fine.

    However, I am having another problem with the Flash: on my application, I am using FreeRTOS.

    In my main I have the following code, which works fine

        // flash writing
        double Pol[6] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0};
        EEPROM_writeValue((uint8_t*)Pol, 1);
    
        //flash reading
        uint8_t buffer_o[100];
        EEPROM_readValue(buffer_o, 6*sizeof(double), 1);

    but the exact same code, used in a FreeRTOS Task does not work, it makes the task to crash.

    my EEPROM_write and EEPROM_read functions are the following

    void EEPROM_readValue(uint8_t* buffer_o, unsigned int length, uint8_t block_number) {
        TI_Fee_Read(block_number, 0, buffer_o, length);
        delay();
        TI_Fee_MainFunction();
    }
    
    void EEPROM_writeValue(uint8_t* buffer_i, uint8_t block_number) {
        TI_Fee_WriteSync(block_number, buffer_i);
        delay();
        TI_Fee_MainFunction();
    }

    It really looks like I can't perform operation ine the flash from a FreeRTOS task ?

  • Hi,

    This is because FEE needs to be executed in Supervisor mode. Please check whether the tasks are running in user mode or supervisor mode.
    Also see this thread : e2e.ti.com/.../2332152

    Regards,
    Akshay