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.

Compiler/TMS320F28379S: Fapi_setActiveFlashBank Blocks the Code and Doesn't Allow Flash to Program

Part Number: TMS320F28379S
Other Parts Discussed in Thread: CONTROLSUITE, C2000WARE

Tool/software: TI C/C++ Compiler

Hey,

I am working with the Flash API for the TMS320F28379S. I am trying to program Flash, but cannot because the code goes to an unknown location after Fapi_SetActiveFlashBank. I have mainly took the code from the example from control suite:

void Program_FlashAPI(void)
{
	Fapi_StatusType oReturnCheck;
	volatile Fapi_FlashStatusType oFlashStatus;
    Fapi_FlashStatusWordType oFlashStatusWord;
	//uint16 au16DataBuffer[8] = {0x0001, 0x0203, 0x0405, 0x0607, 0x0809, 0x0A0B, 0x0C0D, 0x0E0F};
	//uint32 *DataBuffer32 = (uint32 *)FlashMirrorBuffer;
	uint32 u32Index = 0;
    uint16 i = 0;

	EALLOW;
	PUMPREQUEST = 0x5A5A0002;           // Give pump ownership to FMC0(Bank0)

	oReturnCheck = Fapi_initializeAPI(F021_CPU0_W0_BASE_ADDRESS, 200);
	if(oReturnCheck != Fapi_Status_Success)
	{Example_Error(oReturnCheck);}

	oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank0);
	if(oReturnCheck != Fapi_Status_Success)
	{Example_Error(oReturnCheck);}

	oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, (uint32 *)FLASH_SectorE_start);

	while(Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}

	oReturnCheck = Fapi_doBlankCheck((uint32 *)FLASH_SectorE_start, FLASH_64KSectorE_u32length, &oFlashStatusWord);
	if(oReturnCheck != Fapi_Status_Success)
	{
//		Example_Error(oReturnCheck);
	}

	// Program Sector E
	for(i=0, u32Index = FLASH_SectorE_start; (u32Index < (FLASH_SectorE_start + WORDS_IN_FLASH_BUFFER)) &&
	(oReturnCheck == Fapi_Status_Success); i+= 8, u32Index+=8)
	{
		//
		// Issue program command
		//
		oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)u32Index, (uint16 *)EEPROM_52.Buffer+i, 8, 0, 0, Fapi_DataOnly);
		//
		// Wait until the Flash program operation is over
		//
		while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
		if(oReturnCheck != Fapi_Status_Success)
		{Example_Error (oReturnCheck);}
//		oFlashStatus = Fapi_getFsmStatus();
//		if(oFlashStatus != 0)
//		{
			//
			//Check FMSTAT and debug accordingly
			//
			//FMSTAT_Fail();
//		}
		//
		// Verify the programmed values
		//
//		oReturnCheck = Fapi_doVerify((uint32 *)u32Index, 4, FLASH_SectorE_start + i, &oFlashStatusWord);
//		if(oReturnCheck != Fapi_Status_Success)
//		{
			//
			// Check Flash API documentation for possible errors
			//
//			Example_Error(oReturnCheck);
//		}
	}

	PUMPREQUEST = 0x5A5A0000;
	EDIS;
//
// Example is done here
//
///Example_Done();
}

The linker has already had this modification done to it:

   #ifdef __TI_COMPILER_VERSION__
    #if __TI_COMPILER_VERSION__ >= 15009000
        GROUP
        {
            .TI.ramfunc
            { -l F021_API_F2837xS_FPU32.lib}

        } LOAD = FLASHD,
          RUN  = RAMD0,
          LOAD_START(_RamfuncsLoadStart),
          LOAD_SIZE(_RamfuncsLoadSize),
          LOAD_END(_RamfuncsLoadEnd),
          RUN_START(_RamfuncsRunStart),
          RUN_SIZE(_RamfuncsRunSize),
          RUN_END(_RamfuncsRunEnd),
          PAGE = 0
     #else
        GROUP
        {
            ramfuncs
            { -l F021_API_F2837xS_FPU32.lib}

        } LOAD = FLASHD,
          RUN  = RAMD0,
          LOAD_START(_RamfuncsLoadStart),
          LOAD_SIZE(_RamfuncsLoadSize),
          LOAD_END(_RamfuncsLoadEnd),
          RUN_START(_RamfuncsRunStart),
          RUN_SIZE(_RamfuncsRunSize),
          RUN_END(_RamfuncsRunEnd),
          PAGE = 0
     #endif
	#endif

Why does SetFlashBank cause the code to get lost?

  • Robert,

    Instead of Controlsuite, can you try the example from latest C2000Ware? 

    Please note that Controlsuite is not supported anymore for this device.

    When you try the C2000Ware example, please try it as-is and let me know whether it works for you or not.

    We will go from there.

    Thanks and regards,
    Vamsi

  • Hey Vamsi,

    I have simply built the example given in C2000 to see if it works on the processor I have. It does, but the memory allocation of ramfuncs appear to be in different places.

    In the example, TI.ramfunc.1 and .TI.ramfunc.* are located within RAMLS03, along with FLASHD.

    In my project, I just seem to have TI.ramfunc.* located in RAMD0 (where i link it to). I can't seem to find the TI.ramfunc.1 object.

    Is there any reason why this is happening?

  • Robert,

    Thank you for checking the example in C2000Ware as suggested.

    I looked at the Flash programming example located at \C2000Ware_2_00_00_02\device_support\f2837xs\examples\cpu1\flash_programming\cpu01 .

    I could not find TI.ramfunc.1 anywhere. Please provide more details on where you found this.

    Please note that TI.ramfunc should be mapped to Flash address for load and RAM address for run. This means the code that you map to this section will be linked to Flash address and gets loaded to Flash when you load the code to Flash. However, at runtime, this code should be copied to RAM before executing it. This can be accomplished by using memcpy(). Please step through the example and try it out.

    Any code that you need to execute from RAM (Configuration like Flash initialization OR any ISRs that you want to execute from 0-wait RAM etc.) should be assigned to TI.ramfunc section. 

    Thanks and regards,
    Vamsi

  • Above is the memory allocation for Ti.ramfunc located in RAMLS03, as specified in the linker.

    Above is the memory allocation for Ti.ramfunc located in RAMD0, changed to that location in my project. It appears there is a section of TI.ramfunc missing? My linker is described in the first post.

  • Robert,

    .TI.ramfunc.1 is created by the linker since Flash API library and .TI.ramfunc section are GROUPed in the linker cmd.

    You mentioned that you also GROUPed these two in your linker cmd file. 

    But the memory allocation of your project does not show the Flash API. Can you share your linker cmd file and map file so that I can take a closer look?

    Few other things to check in your project:

    1. Make sure the functions that call the Flash API are also mapped to Flash for load and RAM for run. For example, Program_FlashAPI() in your project.

    2. Make sure to not erase the sectors that have Flash API in it.

    3. Make sure to always program ECC along with Flash content. In your code, I see you use Fapi_DataOnly parameter for program command.  I would suggest to program the ECC as well, using Fapi_AutoEccGeneration parameter. If not, ECC errors will occur.

    Thanks and regards,

    Vamsi                  

  • I have readjusted where the FLASH writes happen in my initialization. Turns out an interrupt was being accessed in the middle of the SetActiveFlashBank, causing the code to get lost. I have moved the FLASH write to happen before interrupts are active, which seems to have removed the problem of code getting lost. Switching the flash write setting to AutoEccGeneration also made the flash writes work. Thank you for your help.

  • Robert,

    Glad that it helped and that you are able to execute fine now.

    As mentioned in the Flash API guide, there should not be any access to Flash (ISRs etc.) during Flash API execution. Application can take interrupts but ISRs should be mapped to RAM or to the other Flash bank (on which Flash erase/program operations are not targeted).

    Thanks and regards,
    Vamsi