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.

[concerto] how to store config on flash

I am writing a code on c28 which accepts config file which is sent to device through ethernet (through m3). Now I need to store this config file on flash for next time running my code. I can not loose this file even if power OFF and ON happens.

Please let me know how can I write a program which is can write data on Flash and read it? c28 itself must write data (not through PC) as the config file can be changed at runtime. Please help.

  • Hi Vijay,

    This can be accomplished using the F021 Flash API.  Please take a look here for the software and documentation:

    http://www.ti.com/tool/f021flashapi

    FYI, I just tried going to that link, but it appears to be down at the moment.  Hopefully by the time you read this it will be back up, but if not wait a day or two and it should be ok.

    Trey

  •  

    I have followed the given link and wrote below function.

    void TestFlash(void)

    {

    uint16 au16DataBuffer[8] = {0x0001, 0x0203, 0x0405, 0x0607, 0x0809, 0x0A0B, 0x0C0D, 0x0E0F};

    uint32 au32ReadDataBuffer[8];

    Fapi_FlashBankType oActiveFlashBank = Fapi_FlashBank0;

    Fapi_StatusType oReturnCheck;

    Fapi_FlashStatusType flashStatusType;

    uint32 u32Index;

        EALLOW; // This is needed to write to EALLOW protected registers

    oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, HCLK_FREQUENCY);

    if(oReturnCheck == Fapi_Status_Success)

    {

    oReturnCheck = Fapi_setActiveFlashBank(oActiveFlashBank);

    if(oReturnCheck == Fapi_Status_Success)

    {

    // Each address location stores 16 bits (2 bytes)

    u32Index = 0x100000;

    // Start address of Flash memore FLASHN.

    oReturnCheck = Fapi_issueProgrammingCommand(

    (uint32 *) u32Index,

    au16DataBuffer,

    0x8,

    0,

    0,

    Fapi_AutoEccGeneration);

    while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);

    flashStatusType = Fapi_getFsmStatus();

    //if(flashStatusType == Fapi_Status_Success)

    //{

    oReturnCheck = Fapi_doMarginRead(

    (uint32 *) u32Index,

    au32ReadDataBuffer,

    0x8,

    Fapi_NormalRead);

    while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);

    //}

    }

    }

        EDIS;  
    }

    But This function does not write anything on flash. The status at flashStatusType variable is 0x1010. It indicates that function failed to write on flash. Will you please help me knowing what is going wrong here? I am running this code in c28.

  • Hello Vijay!

    As I see you have set u32Index = 0x100000. Try 0x0 istead (offset not absolute address).


    I am looking for an external flash tool for concerto. Do you know about one?

  • Hi Vijay,

    Ulrich is incorrect.  The address should indeed be 0x100000.

    There are a number of things that need to be done to get the flash API to work.  I just went over this with someone else in another post.  Take a look:

    http://e2e.ti.com/support/microcontrollers/tms320c2000_32-bit_real-time_mcus/f/171/t/156845.aspx

    There are some minor differences between the flashing the C28 and the M3.  One is that you need to write a different key to the flash pump semaphore:

        // Wait for flashpump to be idle
        while(CtoMIpcRegs.CPUMPREQUEST != 0)
        {
        }
        
        // Take control of the flash pump
        CtoMIpcRegs.CPUMPREQUEST = 0x4CE73950 | 0x01;

    Here is my flash test function which I've verified erases and writes to flash:

    #pragma CODE_SECTION(flashTest, "ramfuncs");
    void flashTest(void)
    {
        unsigned char pucProgTest[0x100];
        unsigned int i;
        
        volatile Fapi_StatusType oReturnCheck;
        volatile Fapi_FlashStatusType oFlashStatus;
        Fapi_FlashBankSectorsType oMyBank;
        Fapi_FlashStatusWordType oBlankStatus;
        
        for(i=0 ; i<0x100; i++)
            pucProgTest[i] = i;


        // Disable ECC   
        //*(unsigned int*)(0x4300) = 0;    
        
        oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, 150);
        oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank0);
        
        oReturnCheck = Fapi_getBankSectors(Fapi_FlashBank0, &oMyBank);
        
        
        oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, (uint32 *)0);
        while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy)
        {
        }
        oFlashStatus = Fapi_getFsmStatus();
        
        oReturnCheck = Fapi_doBlankCheck((uint32 *)0x100000, 0x1000, &oBlankStatus);
        
        for(i=0 ; i<0x10; i++)
        {
            oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)0x100000 + (i*0x08), (uint16 *)pucProgTest + (i*0x08), 0x08, 0, 0, Fapi_AutoEccGeneration);
            while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy)
            {
            }
            oFlashStatus = Fapi_getFsmStatus();    
        }
        
        while(1);
        
    }

    You may or may not need the line that sets address location 0x4300 to 0.  This disables ECC in the flash.  I have a pre-production controlcard and was getting an NMI due to some ECC stuff not being programmed.  You shouldn't need this line, but if you start getting NMIs comment this line in.

    Regards,

    Trey

  • Ulrich,

    To the best of my knowledge there aren't any third party flash programming solutions currently available, but these are being worked on.  I know for a fact that a USB flash bootloader is also being developed here at TI internally and should be released in a few months.  Do you have any specific requirements for this flash tool?

    Trey

  • Hi Trey!

    No specific requirements. I am looking for a simple possibillity to write binary data from a file into a selectable flash location for tests similar to "load memory" at CCS5 Memory Browser. My Idea: Load the data via Memory Browser into RAM and flash it with the F021 API. Perhaps it is possible to give the file to the "On-Chip Flash" Utiliity of CCS5 in future?

    Sorry for my mistake above!

    Ulrich+

  • Ulrich,

    That should be reasonably easy to accomplish.  You can load data from a file into RAM using the CCS memory window and then use a small helper application with the Flash API to program the actual flash.

    I know for a fact CCS will program .out files directly into flash, but I'm not sure if it will do it for other types of files.  I agree this could be a useful feature and I will push to get this included in future releases.

    Trey

  • After

    // Wait for flashpump to be idle

    while(CtoMIpcRegs.CPUMPREQUEST != 0) {    }

    // Take control of the flash pump

        CtoMIpcRegs.CPUMPREQUEST = 0x4CE73950 | 0x01;

     

    the API "Fapi_issueProgrammingCommand" started working without any error code returned by "Fapi_getFsmStatus()".

    But now issue is, if I try to read the data written on flash using API "Fapi_doMarginRead", I get only 0xFFFF as return data in the buffer. The data written is not getting read again?

    I used "Fapi_flushPineLine" API as well.

    After writing data into flash using your flashTest function I call below two functions.

    Fapi_flushPipeline();

    oReturnCheck = Fapi_doMarginRead(

    (uint32 *) 0x100000,

    au32ReadDataBuffer,

    0x8,

    Fapi_NormalRead);

     

    The values in au32ReadDataBuffer are only 0xFFFF and it does not read data written by flashTest function. Please help? what is going wrong?

  • Hmmm...  I've not used the MarginRead function before, so I'm not quite sure how it works.  Have you tried viewing the memory in the CCS memory window?  The values I programmed showed up immediately after calling the issueProgrammingCommand function.

    Later today, I'll play around with the MarginRead function and see if I get similar results.  I'll keep you updated.

    Trey

  • Yes, I have tried viewing the memory in the CCS memory window. It does not show updated values. It shows 0xFFFF only.

  •  

    Oh! One thing I was doing is I was running my code from RAM. So now I tried running it through Flash.

    Then now I do get NMI while calling API "Fapi_setActiveFlashBank". The Init API is successful. I tried setting "*(unsigned int*)(0x4300) = 0;" also as you have explained in your code. It does not help me. Is there anything more I need to do?

    I am using Concerto Control Card for this testing.


    Thanks.

  • Ok. Now everything is working good for me. The trick of writing 0 at 0x4300 worked. (in previous attemp it was not writing value correctly at that location because of some programming error at my side).

    But I am not sure why do we need to write 0 at 0x4300? I have observed that calling InitFlash() causes change in value at that location. Can you explain please.

     

    Otherwise thing are working good for me now. Thanks a lot for the help.

  • Glad to here that it is working for you now.  Writing a 0 to 0x4300 disables ECC checking.  That is strange that you had to do that to get it to work.  Our flash experts here are working on an example, so I will bring up this issue with them and get to a better understanding of what is really going on.

    Trey