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.

TMS320F28379D: Issues with writing into flash sectors using flash API

Part Number: TMS320F28379D
Other Parts Discussed in Thread: CONTROLSUITE, C2000WARE
bool FlashWrite(void)
{

    Uint32 u32Index = 0;
    Uint16 i = 0;

    Fapi_StatusType oReturnCheck;
    volatile Fapi_FlashStatusType oFlashStatus;

    DINT;

    //
    // Gain pump semaphore
    //

    SeizeFlashPump();

    Fapi_FlashStatusWordType oFlashStatusWord;

    EALLOW;

    //
    // This function is required to initialize the Flash API based on System
    // frequency before any other Flash API operation can be performed
    //
    oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, 200);

    if(oReturnCheck != Fapi_Status_Success)
    {
        //
        // Check Flash API documentation for possible errors
        //
        return false;
    }

    //
    // Fapi_setActiveFlashBank function sets the Flash bank and FMC for further
    // Flash operations to be performed on the bank
    //
    oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank0);
    if(oReturnCheck != Fapi_Status_Success)
    {
        //
        // Check Flash API documentation for possible errors
        //
        return false;
    }

    //
    // Verify that SectorL is erased.  The Erase step itself does a
    // verify as it goes.  This verify is a 2nd verification that can be done.
    //
    oReturnCheck = Fapi_doBlankCheck((Uint32 *)Bzero_SectorG_start,
                                     Bzero_16KSector_u32length,
                                     &oFlashStatusWord);

    if(oReturnCheck != Fapi_Status_Success)
    {
        //
        // Check Flash API documentation for possible errors
        // If Erase command fails, use Fapi_getFsmStatus() function to get the
        // FMSTAT register contents to see if any of the EV bit, ESUSP bit,
        // CSTAT bit or VOLTSTAT bit is set (Refer to API documentation for
        // more details)
        //
        return false;
    }

    // Start of Some snippet that fills the data to be written
    // Doesn't call a function
    // End of snippet that fills the data to be written

    for(i = 0, u32Index = Bzero_SectorG_start;
       (u32Index < (Bzero_SectorG_start + WORDS_IN_FLASH_BUFFER)) && (oReturnCheck == Fapi_Status_Success);
       i+= 8, u32Index+= 8)
    {
        oReturnCheck = Fapi_issueProgrammingCommand((Uint32 *)u32Index,
                                                     Flash_Array + i,
                                                     8,
                                                     0,
                                                     0,
                                                     Fapi_AutoEccGeneration);

        while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);

        if(oReturnCheck != Fapi_Status_Success)
        {
            //
            // Check Flash API documentation for possible errors
            //
            return false;
        }

        //
        // Read FMSTAT register contents to know the status of FSM after
        // program command for any debug
        //
        oFlashStatus = Fapi_getFsmStatus();

        //
        // Verify the values programmed.  The Program step itself does a verify
        // as it goes.  This verify is a 2nd verification that can be done.
        //
        oReturnCheck = Fapi_doVerify((Uint32 *)u32Index,
                                     4, pFlashArray+(i/2),
                                     &oFlashStatusWord);

        if(oReturnCheck != Fapi_Status_Success)
        {
            //
            // Check Flash API documentation for possible errors
            //
            return false;
        }
    }

    //
    // Enable ECC
    //
    Flash0EccRegs.ECC_ENABLE.bit.ENABLE = 0xA;

    EDIS;
    EINT;

    //
    // Leave control over flash pump
    //
    ReleaseFlashPump();

    return true;

}

I am having an issue with flash APIs here.

Above is a function which (as of now) writes some data in one of the sectors, and is written using the reference codes from controlSUITE.

When I debug, I can see that the value returned by 'Fapi_setActiveFlashBank(Fapi_FlashBank0);' is always 'Fapi_Error_InvalidHclkValue'. I have ensured that InitFlash() is getting called during the one-time initialization before the application loop.

What could be the problem?

Regards,

Prasad

  • Hi,

    Can you check (and confirm) the RWAIT value in the register space before executing Fapi_setActiveFlashBank()?

    Thanks and regards,
    Vamsi
  • It is 0x3. System clock is 200 MHz.
  • Prasad,

    Were you able to successfully execute the C2000Ware example without any modifications?

    Can you attach your project by removing any confidential stuff from it?

    Thanks and regards,
    Vamsi

  • Hi Vamsi, thanks for responding.

    When I posted this question, I had not programmed my device with the flash_programming example from controlSUITE. I have just tried that example, which does work.

    I am in process of identifying the difference between the example and the actual code I am developing, which might take a couple of hours to look at all steps of initialization that has something to do with Flash registers.

    If at all after that, I am still stuck, I will share the project with you. I am certain that the project contains confidential information, and it would take a lot of effort get rid of all the dependencies. Its a long shot which I might have to try if everything fails.

    The only input could help me is, I can see that the flash_programming example is for dual CPU. Is the a similar example for CPU-1 directly usable?

    As of now we are using CPU-1 only. And, of course the question would be, does CPU-1 vs Dual make difference w.r.t flash operations?

    I appreciate you continued support and in any case I will update on my progress here.


    Thank you.

    Regards,
    Prasad

  • Hi Prasad,

    The example written for Dual CPU will work for CPU1, even if you use just CPU1.

    My suggestion for your debug is to try to make changes to the example incrementally and see if your changes are breaking the flow.

    Thanks,
    Katta
  • Prasad,

    Just wanted to provide a minor info: Flash pump is shared between CPU1 and CPU2. Hence, only one core (CPU1 or CPU2) can perform Flash erase and program operations at a time. Since you mentioned that you are using only CPU1 as of now, you just need to make sure that CPU1 owns the pump. Go through the SeizeFlashPump() function used in the example - it is used to gain the pump for a core using pump semaphore.

    As Katta mentioned, the CPU1 example should work without any dependency on CPU2.

    Thanks and regards,
    Vamsi
  • Hi Vamsi,

    I am attaching a zip file which contains the project. There are no errors in compilation. Its just that it ends up in an ILLEGAL_ISR. 

  • Prasad,

    Since you say that it is ending up in illegal ISR: Please search for "Why does application end up in illegal ISR when using Flash API?" in the C2000 Flash wiki page: processors.wiki.ti.com/.../Flash_FAQ

    Once you fix it, please reattach your project.

    Thanks and regards,
    Vamsi
  • Hi Vamsi, thank you for the input regarding the issue with ILLEGAL_ISR. I have fixed it.

    Please refer the attached project for your review. I am still stuck with Fapi_setActiveFlashBank() returning Fapi_Error_InvalidHclkValue.

    I think the project that I had added an hour ago was not the one that I intended to share with you.

     

    Project: milind5 - Copy.zip

     

    Regards,

    Prasad

  • Hi Prasad,

    I have debugged the project you have shared above. The project didn't build for me. The error was that file "Registers_FMC_BE.h" was not found.

    With a small change by commenting the following line in Flash_CPU1.c, I could build the project. 

    #include "FlashAPI/F021.h"

    I didn't see any error in Fapi_setActiveFlashBank() while running the project.

    Did you try clean build? Did you make any changes in the controlsuite?

    Thanks,

    Katta

  • Hi, thanks for responding. I think I have just (a few minutes ago) resolved the issue.

    I re-installed controlSUITE today to make sure everything is in place, and I guess it is indeed about the header inclusions. If I include
    "F021_F2837xD_C28x.h" after "F021.h", it doesn't work, and reports a missing header file "Registers_FMC_BE.h". Which it didn't last night when I uploaded the zipped code. The idea of re-installation came when I tried the same thing last night on a different computer. So I had a hint that the code I have uploaded would compile on my machine but may not compile on your machine. The only difference could have been environment and controlSUITE.

    So when I changed the order to

    #include "FlashAPI/F021_F2837xD_C28x.h"
    #include "FlashAPI/F021.h"

    I can now compile the code without a problem and I can verify the data in memory browser.

    I thank you and Vamsi for continued support.

    Regards,

    Prasad

  • Prasad,

    As mentioned in section 2.3.2.2 Distribution Files of the F2837xD Flash API reference guide (http://www.ti.com/lit/pdf/spnu629) and shown in the C2000Ware example, the only header file that you need to include for using the Flash API library is "F021_F2837xD_C28x.h".  This file includes other necessary files.

    Thanks and regards,

    Vamsi