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.

F28M35H52C: Executing Flash Control function calls from RAM does not program data in to FLASH sectors on C28

Part Number: F28M35H52C
Other Parts Discussed in Thread: CONTROLSUITE

Hi guys,

I need some support for following issue's seen while developing a custom bootloader application on concerto C28 core. 

NOTABLE MENTIONS:

- C28 bootloader application uses F021_API_C28x_FPU32.lib for erasing and programming the FLASH sectors of C28 core. 

- Now I make sure the above library is executed off of RAM.

GROUP
{
.TI.ramfunc
{ -l F021_API_C28x_FPU32.lib}

} LOAD = FLASHA,
RUN = RAML0,
LOAD_START(_RamfuncsLoadStart),
LOAD_SIZE(_RamfuncsLoadSize),
RUN_START(_RamfuncsRunStart),
PAGE = 0

- Some of the other functions i run off of RAM are : 

#pragma CODE_SECTION(InitFlash, ".TI.ramfunc");
#pragma CODE_SECTION(SetupFlash, ".TI.ramfunc");
#pragma CODE_SECTION(FlashGainPump,".TI.ramfunc");
#pragma CODE_SECTION(FlashLeavePump,".TI.ramfunc");

- Apart from above function i execute some self written function's off of RAM and these are : (I have attached the source code as reference for anybody to see what these functions do ! )

//
//
//	File:
//  Description:
//
//
//
//
//
//###########################################################################
//
//	Author:
//
//###########################################################################

//###########################################################################
//
// 						Device Related Header files
//
//###########################################################################

#include "../include/Flash Control Interface/FlashControlInterface.h"

// Functions that will be run from RAM need to be assigned to
// a different section.  This section will then be mapped to a load and
// run address using the linker cmd file.

#ifdef __TI_COMPILER_VERSION__
    #if __TI_COMPILER_VERSION__ >= 15009000
        #pragma CODE_SECTION(eraseFlashSectors, ".TI.ramfunc");
        #pragma CODE_SECTION(programFlashSectors, ".TI.ramfunc");
    #else
        #pragma CODE_SECTION(eraseFlashSectors, "ramfuncs");
        #pragma CODE_SECTION(programFlashSectors, "ramfuncs");
    #endif
#endif

//###########################################################################
// 						   Function Defination
//###########################################################################

//###########################################################################
//
//								Error
//
//###########################################################################
void Error(Fapi_StatusType status)
{
	for(;;);

}

//###########################################################################
//
//							eraseFlashSectors
//
//###########################################################################

void eraseFlashSectors (void)
{
	FlashGainPump();

    Fapi_StatusType            oReturnCheck;
    volatile Fapi_LibraryInfoType       oLibInfo;
    volatile Fapi_FlashStatusType       oFlashStatus;
    Fapi_FlashBankSectorsType  oFlashBankSectors;
    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
    #if CPU_FRQ_150MHZ
    oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, 150);
    #endif

	#if CPU_FRQ_125MHZ
    oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, 125);
    #endif

    #if CPU_FRQ_100MHZ
    oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, 100);
    #endif

    #if CPU_FRQ_60MHZ
    oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, 60);
    #endif

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

    // Fapi_getLibraryInfo function can be used to get the information specific
    // to the compiled version of the API library
    oLibInfo = Fapi_getLibraryInfo();

    // 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
        Error(oReturnCheck);
    }

    // Fapi_getBankSectors function returns the bank starting address, number of
    // sectors, sector sizes, and bank technology type
    // Above information is returned in a structure oFlashBankSectors of type
    // Fapi_FlashBankSectorsType
    oReturnCheck = Fapi_getBankSectors(Fapi_FlashBank0,&oFlashBankSectors);
    if(oReturnCheck != Fapi_Status_Success)
    {
        //Check Flash API documentation for possible errors
        Error(oReturnCheck);
    }

    // Erase Sector C
    oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, (uint32 *)Bzero_SectorC_start);
    while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
    oReturnCheck = Fapi_doBlankCheck((uint32 *)Bzero_SectorC_start, Bzero_16KSector_u32length, &oFlashStatusWord);
    if(oReturnCheck != Fapi_Status_Success)
    {
        Error(oReturnCheck);
    }

    // Erase Sector D
    oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, (uint32 *)Bzero_SectorD_start);
    while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
    oReturnCheck = Fapi_doBlankCheck((uint32 *)Bzero_SectorD_start, Bzero_16KSector_u32length, &oFlashStatusWord);
    if(oReturnCheck != Fapi_Status_Success)
    {
        Error(oReturnCheck);
    }

    // Erase Sector E
    oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, (uint32 *)Bzero_SectorE_start);
    while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
    oReturnCheck = Fapi_doBlankCheck((uint32 *)Bzero_SectorE_start, Bzero_16KSector_u32length, &oFlashStatusWord);
    if(oReturnCheck != Fapi_Status_Success)
    {
        Error(oReturnCheck);
    }

    // Erase Sector F
    oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, (uint32 *)Bzero_SectorF_start);
    while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
    oReturnCheck = Fapi_doBlankCheck((uint32 *)Bzero_SectorF_start, Bzero_16KSector_u32length, &oFlashStatusWord);
    if(oReturnCheck != Fapi_Status_Success)
    {
        Error(oReturnCheck);
    }

    // Erase Sector G
    oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, (uint32 *)Bzero_SectorG_start);
    while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
    oReturnCheck = Fapi_doBlankCheck((uint32 *)Bzero_SectorG_start, Bzero_16KSector_u32length, &oFlashStatusWord);
    if(oReturnCheck != Fapi_Status_Success)
    {
        Error(oReturnCheck);
    }

    // Erase Sector H
    oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, (uint32 *)Bzero_SectorH_start);
    while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
    oReturnCheck = Fapi_doBlankCheck((uint32 *)Bzero_SectorH_start, Bzero_16KSector_u32length, &oFlashStatusWord);
    if(oReturnCheck != Fapi_Status_Success)
    {
        Error(oReturnCheck);
    }

    // Erase Sector I
    oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, (uint32 *)Bzero_SectorI_start);
    while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
    oReturnCheck = Fapi_doBlankCheck((uint32 *)Bzero_SectorI_start, Bzero_16KSector_u32length, &oFlashStatusWord);
    if(oReturnCheck != Fapi_Status_Success)
    {
        Error(oReturnCheck);
    }

    // Erase Sector J
    oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, (uint32 *)Bzero_SectorJ_start);
    while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
    oReturnCheck = Fapi_doBlankCheck((uint32 *)Bzero_SectorJ_start, Bzero_16KSector_u32length, &oFlashStatusWord);
    if(oReturnCheck != Fapi_Status_Success)
    {
        Error(oReturnCheck);
    }

    // Erase Sector K
    oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, (uint32 *)Bzero_SectorK_start);
    while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
    oReturnCheck = Fapi_doBlankCheck((uint32 *)Bzero_SectorK_start, Bzero_16KSector_u32length, &oFlashStatusWord);
    if(oReturnCheck != Fapi_Status_Success)
    {
        Error(oReturnCheck);
    }

    // Erase Sector L
    oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, (uint32 *)Bzero_SectorL_start);
    while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
    oReturnCheck = Fapi_doBlankCheck((uint32 *)Bzero_SectorL_start, Bzero_16KSector_u32length, &oFlashStatusWord);
    if(oReturnCheck != Fapi_Status_Success)
    {
        Error(oReturnCheck);
    }

    // Erase Sector M
    oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, (uint32 *)Bzero_SectorM_start);
    while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
    oReturnCheck = Fapi_doBlankCheck((uint32 *)Bzero_SectorM_start, Bzero_16KSector_u32length, &oFlashStatusWord);
    if(oReturnCheck != Fapi_Status_Success)
    {
        Error(oReturnCheck);
    }

    // Erase Sector N
    oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, (uint32 *)Bzero_SectorN_start);
    while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
    oReturnCheck = Fapi_doBlankCheck((uint32 *)Bzero_SectorN_start, Bzero_16KSector_u32length, &oFlashStatusWord);
    if(oReturnCheck != Fapi_Status_Success)
    {
        Error(oReturnCheck);
    }

    EDIS;

	// Leave control over pump
	FlashLeavePump();

}

//###########################################################################
//
//							programFlashSectors
//
//###########################################################################
unsigned char programFlashSectors (Uint32 flashsectoraddress, Uint16* data, Uint16 reclength)
{

	FlashGainPump();

	EALLOW;

	Uint16 data_buffer[8];
	Fapi_StatusType oReturnCheck;

	data_buffer[0] = (data[0] >> 8) | (data[0] << 8);
	data_buffer[1] = (data[1] >> 8) | (data[1] << 8);
	data_buffer[2] = (data[2] >> 8) | (data[2] << 8);
	data_buffer[3] = (data[3] >> 8) | (data[3] << 8);
	data_buffer[4] = (data[4] >> 8) | (data[4] << 8);
	data_buffer[5] = (data[5] >> 8) | (data[5] << 8);
	data_buffer[6] = (data[6] >> 8) | (data[6] << 8);
	data_buffer[7] = (data[7] >> 8) | (data[7] << 8);


    // Example:  Program 0xFF bytes in Flash Sector B with out ECC
    // Disable ECC so that error is not generated when reading Flash contents
    // without ECC
    FlashEccRegs.ECC_ENABLE.bit.ENABLE = 0x0;

    if(reclength == 0x0C)
    {
    	oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)flashsectoraddress,
    				   data_buffer,
    				   6,
    				   0,
    				   0,
					   Fapi_DataOnly);
    }
    else if (reclength == 0x04)
    {
    	oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)flashsectoraddress,
    	    				   data_buffer,
    	    				   2,
    	    				   0,
    	    				   0,
							   Fapi_DataOnly);
    }
    else
    {
    	oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)flashsectoraddress,
    				   data_buffer,
    				   8,
    				   0,
    				   0,
					   Fapi_DataOnly);
    }


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

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

    EDIS;

	// Leave control over pump
	FlashLeavePump();

	return oReturnCheck;
}

#pragma CODE_SECTION(eraseFlashSectors, ".TI.ramfunc"); 
#pragma CODE_SECTION(programFlashSectors, ".TI.ramfunc");

Problem I am facing: 

Now in my software i perform erase of sectors before i program any sectors. Later when i try to program flash sectors at certain calculated addresses with out applying a breakpoint on  "Fapi_issueProgrammingCommand" , to my surprise the api returns a "Fapi_Status_Success" but in reality no data will be programmed in the FLASH when i look in the Memory Browser view on CCS ! 

But when i apply a break point at "Fapi_issueProgrammingCommand" and step over the data contents will be programmed. I do not understand whats going on here ? Should i provide some delay here ? 

I used FLASH Porgamming example provided in control suite. 

Thanks

 

  • Preetham,

    Do you have watchdog enabled? If it is enabled, is your application servicing it as needed?
    I think your application programs Flash fine, but a reset causes your application to trigger the erase sequence again.

    Thanks and regards,
    Vamsi
  • Hi Vamsi,

    Thanks for your reply. I got this problem corrected by adding "while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);" after i perform program operation. 


    But stuck with other issue which i have posted here :

    Thanks

  • Preetham,

    Glad it is working now. It is very important to make sure FSM is ready before you initiate the next operation. It is shown in Flash programming example provided in controlSuite for this device, and also mentioned in Flash API guide and wiki.

    Regarding the hex utility, I see our team is helping you - please continue to discuss there.

    Thanks and regards,
    Vamsi