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: Reading Flash After Reset

Part Number: TMS570LS1224
Other Parts Discussed in Thread: HALCOGEN

I have a TMS570LS1224 (PGE) and I have a problem reading value after reset. The idea was to store a 4 digit integer value (between 0 and 9999 in my case around 1200) into the flash. FEE function writes the value every time on other location in the bank 7. When I want to read the value it works fine but after reset it forgets where to read and gives me a wrong value (but every time the same number). Then after first write is done it reads again the right value.
so I need a little help how to make the mcu read on the right location after reset?
Or other alternative: can I somehow write (with F021 Flash API functions) always to the same location and read from the same location. For example I want to use the Bank 7 address 0xF0200000 (to 0xF0200003 - 4 digit number) and after reset it should read from that location.

Thanks for your help

functions:

Regards, Mihael

  • Hello,

    The functions you wrote for FEE read/write look ok to me. Did you use CPU reset or system reset from CCS or use the nRST on the board? I tried both CPU reset and system reset from CCS, then checked the memory, and everything looks fine. 

    From the picture attached, you will see the virtual sector header (4 32-bit words), 4 reserved 32-bit words, and 6 32-bit words block header. Can you please check the block status in your memory browser? If the status is 0xFFFF_0000_0000_0000, the block is invalid.

    Regards,

    QJ

  • I see some funny behavior. the first two pictures represent the old memory, the second two pictures I took after the format (TI_Fee_Format(0xA5A5A5A5U);). If I format it I would expect from the write function to write on the first empty location which is 0xF0200000. if you look at the last picture it continues writing on the 0xF020555? address in spite of the fact that it was formatted.

    so I think it is better that I write a function to write every time to the same location and read from it. I found some very interesting functions from 021 and 035 Flash API literature but I am not able to use it because I am not experienced enough - I need a little help from you.

    for example: 

    Fapi_issueProgrammingCommand()

    Fapi_doMarginRead()

    after TI_Fee_Format(0xA5A5A5A5U);

  • I found what was wrong. I forgot to define BlockNumber in read function. If I write "BlockNumber=0x1;" before oResult=TI_Fee_Read(...) than it works. It also works if I define it in declaration area.

    so I wrote an example code for saving and reading integer (fee driver must be enabled in Halcogen, 021 flash api files are also necessary (read help-fee example in hcg)):

    /* USER CODE BEGIN (2) */
       uint16 u16JobResult,Status;
       Std_ReturnType oResult=E_OK;
       unsigned char read_data[4]={0};     //default is 100 but in my case I only need 4
       uint8 SpecialRamBlock[4];     //default is 100 but in my case I only need 4
       unsigned char pattern;
       uint16 u16writecounter;
       unsigned int  FeeVirtualSectorNumber;
       unsigned char VsState, u8EEPIndex;
       unsigned char u8VirtualSector;
       uint8 Test_Recovery;
       uint8 Test_Cancel;
       unsigned int BlockNumber=0x1;
       unsigned int BlockOffset;
       unsigned int Length;
       unsigned char *Read_Ptr=read_data;
       unsigned int loop;
       
       void save(int16_t p);
       int  read(void);
       void delay(void);
    /* USER CODE END */
    
    int main(void)
    {
    /* USER CODE BEGIN (3) */
       /* Initialize RAM array.*/
       for(loop=0;loop<4;loop++) SpecialRamBlock[loop] = loop;    //default is 100 but in my case I only need 4
       /* 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);
           //use read() function to read from flash
    while(1) {
           //your code...(with save() function)
       }
    /* USER CODE END */
       return 0;
    }
    
    /* USER CODE BEGIN (4) */
    void save(int16_t p){  //save function
       uint16_t j=0; //counter
       char p1[4];
       sprintf(p1, "%4.d", p);  //4 digit number into char
       for(j=0;j<4;j++){           // rest of chars which arent number writes ascii 0
           if ((p1[j]<48)||(p1[j]>57)) {
               p1[j]=48;
           }
       }
       SpecialRamBlock[0]=p1[0]; //1000
       SpecialRamBlock[1]=p1[1]; //100
       SpecialRamBlock[2]=p1[2]; //10
       SpecialRamBlock[3]=p1[3]; //1
       TI_Fee_WriteAsync(BlockNumber, &SpecialRamBlock[0]);
       do    {
           TI_Fee_MainFunction();
           delay();
           Status=TI_Fee_GetStatus(0);
       }    while(Status!=IDLE);
    }
    
    int read(void){ //read function
       int16_t p;  //position
       uint16_t t; //1000
       uint16_t s; //100
       uint16_t d; //10
       uint16_t e; //1
       /* 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);
       /*read from flash*/
       t=(uint16_t)read_data[0]-48; //ascii into integer
       s=(uint16_t)read_data[1]-48;
       d=(uint16_t)read_data[2]-48;
       e=(uint16_t)read_data[3]-48;
       /*calculates digits into number */
       t=t*1000;
       s=s*100;
       d=d*10;
       p=t+s;
       p=p+d;
       p=p+e;
       return p; //returns value
    }
    
    void delay(void) {
       unsigned int dummycnt=0x0000FFU;
       do    {        dummycnt--;    }
       while(dummycnt>0);
    }
    /* USER CODE END */