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.

CCS/TMS320F28374S: Fapi_EccOnly

Part Number: TMS320F28374S
Other Parts Discussed in Thread: C2000WARE

Tool/software: Code Composer Studio

I am facing a problem when I program data and ecc separately, using Fapi_issueProgrammingCommand() with Fapi_DataOnly and Fapi_EccOnly.

I have no problem when programming data, but I probably do some error when calculating or writing ecc.

Where is the problem with the following code?

short FlashProg_WriteEcc(unsigned long 64bitAlignedAddr)
{
    uint64_t        data;
    uint64_t        *flash_p;
    uint16_t        ecc;
    Fapi_StatusType fapiSts;
    int16_t         rv;

    rv = -1;

    flash_p = (uint64 *) 64bitAlignedAddr;
    memcpy(&data, flash_p, 4);

    ecc = Fapi_calculateEcc(64bitAlignedAddr << 1, data);

    SysCtl_disableWatchdog();

    fapiSts = Fapi_issueProgrammingCommand((uint32_t *) 64bitAlignedAddr, NULL, 0, &ecc, 1, Fapi_EccOnly);

    while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);

    SysCtl_enableWatchdog();

    // si verfica l'esito
    if (fapiSts == Fapi_Status_Success)
    {
        rv = 0;
    }

    ASSERT(fapiSts == Fapi_Status_Success);
    return rv;
}

Thank you,

Carlo

  • Carlo,

    What is the problem that you faced? What error did you get from the program function? Did you check for FMSTAT using Fapi_getFsmStatus() after the program function?

    Thanks and regards,
    Vamsi
  • Hello Vamsi,

    this is my problem.

    I am writing a bootloader to upgrade the target application.

    The target application is allocated on Flash sectors E and F (0x88000 - 0x97FFF).

    The bootloader perfoms theese steps:

    - Write data (code and CRC), using Fapi_issueProgrammingCommand() in Fapi_DataOnly mode.

    - Write ECC, using  Fapi_issueProgrammingCommand() in Fapi_EccOnly mode.

    - Verify CRC on code.

    Apparently I don't have any problem when writing data and ECC.

    Fapi_issueProgrammingCommand() returns always Fapi_Status_Success and Fapi_getFsmStatus() returns always 0.

    However, when I perform CRC verification, I got a NMI, when reading data at address 0x80010.

    At this address I have the following 64bit data 0x026B1E420201B343.

    The corresponding ECC calculated by Fapi_calculateEcc() is 0xFF.

    This is the code for ECC calculation and writing:

    static short CalculateAndWriteEcc(void)
    {
        uint32_t        addr;
        int16_t         rv;
    
        addr = 0x88000;
        rv = 0;
    
        while ((addr <=  0x97FFF) && (rv == 0))
        {
            rv = FlashProg_WriteEcc(addr);
            addr = addr + 4;
        }
    
        return rv;
    }

    short FlashProg_WriteEcc(uint32_t addr)
    {
        uint64_t                data;
        uint16_t                ecc;
        Fapi_StatusType         fapiSts;
        Fapi_FlashStatusType    fapiFlashSts;
        int16_t                 rv;
    
        data = *(uint64_t *) addr;
    
        ecc = Fapi_calculateEcc((addr << 1), data);
    
        // si scrive il valore di ecc in flash
        SysCtl_disableWatchdog();
    
        fapiSts = Fapi_issueProgrammingCommand((uint32_t *) addr, NULL, 0, &ecc, 1, Fapi_EccOnly);
    
        while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);
    
        SysCtl_enableWatchdog();
        
        if (fapiSts == Fapi_Status_Success)
        {
            fapiFlashSts = Fapi_getFsmStatus();
    
            rv = 0;
        }
    
        ASSERT(fapiFlashSts == 0);
        ASSERT(fapiSts == Fapi_Status_Success);
        return rv;
    }

    Thank you,

    Carlo



  • Carlo,

    I will try the data and address that you provided. I may not be able to check it until mid next week.

    Thanks and regards,
    Vamsi
  • Carlo,

    Sorry for the delay, I was out of office for couple of weeks.

    Can you confirm that you are using the Flash API library provided at C:\ti\c2000\C2000Ware_1_00_05_00\libraries\flash_api\f2837xs\lib?

    Thanks and regards,
    Vamsi

  • Carlo,

    Could you please confirm the API that you used?

    Thanks and regards,
    Vamsi
  • Hello Vamsi,

    I am using the flash API library provided with the following version of C2000Ware:

    C:\ti\c2000\C2000Ware_1_00_04_00\libraries\flash_api\f2837xs.

    Thank you,
    Carlo
  • Carlo,

    I tried the address/data that you provided and the ECC value returned by Fapi_calculateEcc() is 0xDB.

    uint16 ecc_data = Fapi_calculateEcc((0x80010 << 1), 0x026B1E420201B343);

    Can you confirm that you called Fapi_calculateEcc() after executing Fapi_setActiveFlashBank(Fapi_FlashBank0)?

    Thanks and regards,
    Vamsi

  • Hello Vamsi,

    yes, before using any other flash library API, I perform the following initialization:

    void FlashProg_Init(void)

    {

    Fapi_StatusType fapiSts;

     

    // Give pump ownership to FMC0(Bank0)

    PUMPREQUEST = 0x5A5A0002;

    fapiSts = Fapi_initializeAPI(F021_CPU0_W0_BASE_ADDRESS, SYSCLK_FREQ_MHz);

     

    if (fapiSts == Fapi_Status_Success)

    {

    fapiSts = Fapi_setActiveFlashBank(Fapi_FlashBank0);

    }

    ASSERT(fapiSts == Fapi_Status_Success);

    }

    Thank you,

    Carlo

  • Carlo,

    What is the system frequency and wait-state configuration that you are using?
    Can you share your entire code (remove non Flash API stuff) so that I can compile and check what's going on?

    Thanks and regards,
    Vamsi
  • // clock configuration
    #define DEVICE_SETCLOCK_CFG         (SYSCTL_OSCSRC_XTAL | SYSCTL_IMULT(8) | \
                                         SYSCTL_FMULT_0 | SYSCTL_SYSDIV(1) |    \
                                         SYSCTL_PLL_ENABLE)
    									 
    // flash frequency and wait states
    #define SYSCLK_FREQ_MHz				192
    #define FLASH_WAITSTATES            3
    
    // 
    // Hardware inizializion
    //
    void HW_Init(void)
    {
        bool    clockRunning;
    
        clockRunning = false;
    	
        SysCtl_disableWatchdog();
    	SysCtl_setWatchdogPrescaler(SYSCTL_WD_PRESCALE_64);
    
        memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t) &RamfuncsLoadSize);
        Flash_initModule(FLASH0CTRL_BASE, FLASH0ECC_BASE, FLASH_WAITSTATES);
    
        // initialize clock
        while (!clockRunning)
        {
            clockRunning = SysCtl_setClock(DEVICE_SETCLOCK_CFG);
    
            if (!clockRunning)
            {
                ASSERT(0);
                SysCtl_resetMCD();
            }
        }
    
        ASSERT(SysCtl_getClock(OSCSRC_FREQ) == SYSCLK_FREQ);
    
    	// other initializations...
    }
    
    //
    //	Flash API initialization
    //
    void FlashProg_Init(void)
    {
        Fapi_StatusType     fapiSts;
    
        // si inzializzano le informazioni locali al modulo
        memset(&info, 0, sizeof(info));
    
        // Give pump ownership to FMC0(Bank0)
        PUMPREQUEST = 0x5A5A0002;
    
        fapiSts = Fapi_initializeAPI(F021_CPU0_W0_BASE_ADDRESS, SYSCLK_FREQ_MHz);
    
        if (fapiSts == Fapi_Status_Success)
        {
            fapiSts = Fapi_setActiveFlashBank(Fapi_FlashBank0);
        }
    
        ASSERT(fapiSts == Fapi_Status_Success);
    }
    
    //
    //	ECC calculation and write
    //
    short FlashProg_WriteEcc(uint32_t addr)
    {
        uint64_t                data;
        uint16_t                ecc;
        Fapi_StatusType         fapiSts;
        Fapi_FlashStatusType    fapiFlashSts;
        int16_t                 rv;
    
        data = *(uint64_t *) addr;
    
        ecc = Fapi_calculateEcc((addr << 1), data);
    
        SysCtl_disableWatchdog();
    
        fapiSts = Fapi_issueProgrammingCommand((uint32_t *) addr, NULL, 0, &ecc, 1, Fapi_EccOnly);
    
        while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);
    
        SysCtl_enableWatchdog();
    
        if (fapiSts == Fapi_Status_Success)
        {
            fapiFlashSts = Fapi_getFsmStatus();
    
            rv = 0;
        }
    
        ASSERT(fapiFlashSts == 0);
        ASSERT(fapiSts == Fapi_Status_Success);
        return rv;
    }
    
    //
    //	Routine to calculate and program ECC on the entire code address space
    //
    static short CalculateAndWriteEcc(void)
    {
        uint32_t        addr;
        int16_t         rv;
    
        addr = 0x88000;
        rv = 0;
    
        while ((addr <=  0x97FFF) && (rv == 0))
        {
            rv = FlashProg_WriteEcc(addr);
    
            addr = addr + 4;
        }
    
        return rv;
    }
    
    
    Hello Vamsi,

    it is difficult for me to isolate a self consistent slice of code that you can compile, because it strictly depends from the overall bootloader architecture.

    I have attached a file with all the defines and routines, that I hope can help to reproduce the problem.

    At the moment we have workarounded the problem, using the Fapi_AutoEccGeneration mode.

    Remember that we are using C2000Ware V.1.00.04.00.

    Thank you,

    Carlo.

  • Carlo,

    Thank you for the code.

    Since I verified on my side that the function is working correctly and you decided to use AutoEccGeneration mode, I am not planning to debug your code.  Hope this is OK.  If you want me to look at it for any reason, let me know.

    Also, note that the minimum programming Flash word size is 64-bits (Please check device errata for the Advisory Flash: Minimum Programming Word Size).  Since you program 64-bits at a time anyways, the best option would be to use AutoEccGeneration.

    Thanks and regards,

    Vamsi

  • Hello Vamsi,

    thank you for support.

    For the moment we are ok.
    In case we need to face this problem another time, I will let you know.

    Carlo.
  • Carlo,

    Ok, I am closing this post for now.

    FYI for others that may refer to this post: Fapi_calculateECC() function works fine. It is validated. For this device, note that address provided for this function should be left shifted by 1 position. This is mentioned in the Flash API guide ( www.ti.com/.../spnu630) and wiki.

    Thanks and regards,
    Vamsi