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/TMS320F28379S: Software trapped at memcpy after initialize the FLASH API

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

Tool/software: Code Composer Studio

Hi, I am trying to apply the flash api into my software. But one strange issue shows up. As long as I call the  FLASH_initAPI() function shows below, then the software will be trapped in memcpy in function FLASH_init(). Can anyone help me with that?

void FLASH_init(void)

{

memcpy(&apiRamRunStart,&apiFlashLoadStart, (size_t)(&apiFlashLoadSize));
memcpy(&RamfuncsRunStart,&RamfuncsLoadStart, (size_t)(&RamfuncsLoadSize));
InitFlash_Bank0();
InitFlash_Bank1();

}

#pragma CODE_SECTION(FLASH_initAPI, "libFuncs");
void FLASH_initAPI(void)
{
Fapi_StatusType oReturnCheck;

EALLOW;
Flash0EccRegs.ECC_ENABLE.bit.ENABLE = 0x0;
//
// Give pump ownership to FMC0(Bank0)
//
PUMPREQUEST = 0x5A5A0002;
//
// This function is required to initialize the Flash API based on
// System frequency before any other Flash API operation can be performed
// Note that the FMC0 register base address is passed as the parameter
//
oReturnCheck = Fapi_initializeAPI(F021_CPU0_W0_BASE_ADDRESS, 200);
if(oReturnCheck != Fapi_Status_Success)
{
/*TODO*/
}
//
// Fapi_setActiveFlashBank function sets the Flash bank0 and FMC0 for
// further Flash operations to be performed on the bank0.
// Note that the parameter passed is Fapi_FlashBank0 since FMC0 register
// base address is passed to Fapi_initializeAPI()
//
oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank0);
if(oReturnCheck != Fapi_Status_Success)
{
/*TODO*/
}
Flash0EccRegs.ECC_ENABLE.bit.ENABLE = 0xA;
EDIS;
}

Below is the cmd file definition:

/*Ram function specific sections*/
.TI.ramfunc: {} LOAD = BOOTF,
RUN = FASTRAM,
LOAD_START(_RamfuncsLoadStart),
LOAD_SIZE(_RamfuncsLoadSize),
LOAD_END(_RamfuncsLoadEnd),
RUN_START(_RamfuncsRunStart),
RUN_SIZE(_RamfuncsRunSize),
RUN_END(_RamfuncsRunEnd),
PAGE = 0, ALIGN(4)

libFuncs: LOAD = FLASHAPI,
RUN = FLASHAPIRAM,
LOAD_START(_apiFlashLoadStart),
LOAD_SIZE(_apiFlashLoadSize),
LOAD_END(_apiFlashLoadEnd),
RUN_START(_apiRamRunStart),
RUN_SIZE(_apiRamRunSize),
RUN_END(_apiRamRunEnd),
PAGE = 0, ALIGN(4)
{
-l F021_API_F2837xS_FPU32.lib <*> (.text)
}

  • Hi,

    Could you please let me know the memory address of "BOOTF", "FASTRAM", "FLASHAPI" and "FLASHAPIRAM"?

    Is there a reference linker command file you have used from the controlSUITE or C2000Ware?

    Thanks,
    Katta
  • Hi Katta,

    Thanks for the reply. Here is the definition:

    FASTRAM : origin = 0x01A000, length = 0x002000
    FLASHAPIRAM : origin = 0x016000, length = 0x001000
    FLASHAPI : origin = 0x0FA000, length = 0x002000 /* on-chip Flash */
    BOOTF : origin = 0x082000, length = 0x00E000/* on-chip Flash */


    I am using my own cmd file. And here is the map output of libFuncs section:
    libFuncs 0 000fa000 00000972 RUN ADDR = 00016000
    000fa000 00000276 F021_API_F2837xS_FPU32.lib : FlashStateMachine.obj (.text:__Fapi_setupFlashStateMachine)
    000fa276 0000019e : Program.obj (.text:_Fapi_issueProgrammingCommand)
    000fa414 00000082 : Read.obj (.text:__Fapi_loopRegionForValue)
    000fa496 0000005f : Init.obj (.text:_Fapi_initializeAPI)
    000fa4f5 00000055 : FlashStateMachine.obj (.text:_Fapi_setupEepromSectorEnable)
    000fa54a 0000003d : BlankCheck.obj (.text:_Fapi_doBlankCheck)
    000fa587 00000036 : FlashStateMachine.obj (.text:_Fapi_isAddressEcc)
    000fa5bd 00000032 : Read.obj (.text:__Fapi_checkRegionForValue)
    000fa5ef 0000002f : FlashStateMachine.obj (.text:__Fapi_issueFsmCommand)
    000fa61e 0000002c : Utilities.obj (.text:_Fapi_calculateFletcherChecksum)
    000fa64a 0000002a : Utilities.obj (.text:__Fapi_divideUnsignedLong)
    000fa674 00000029 : FlashStateMachine.obj (.text:__Fapi_setupSectorsForWrite)
    000fa69d 00000026 : Read.obj (.text:_Fapi_flushPipeline)
    000fa6c3 00000026 : FlashStateMachine.obj (.text:_Fapi_setActiveFlashBank)
    000fa6e9 00000025 : FlashStateMachine.obj (.text:_Fapi_setupBankSectorEnable)
    000fa70e 00000024 : Async.obj (.text:_Fapi_issueAsyncCommandWithAddress)
    000fa732 0000001a : Verify.obj (.text:_Fapi_doVerify)
    000fa74c 0000001a : Utilities.obj (.text:_Fapi_waitDelay)
    000fa766 0000000f : Utilities.obj (.text:__Fapi_scaleCycleValues)
    000fa775 0000000b : FlashStateMachine.obj (.text:_Fapi_checkFsmForReady)
    000fa780 0000000b : Utilities.obj (.text:__Fapi_calculateOtpChecksum)
    000fa78b 00000002 : Fapi_UserDefinedFunctions.obj (.text:_Fapi_serviceWatchdogTimer)
    000fa78d 000001c3 FlashInterface.obj (libFuncs)
    000fa950 00000022 flash_library.obj (libFuncs)


    But the memcpy will trap into a forever loop. I have no idea why. Everything is normal.
  • Hi,

    Sorry for the late reply.

    Is it possible to use the linker command file from the C2000Ware and make only a few modifications as per your need?

    Also please refer to an example at <C2000Ware>\device_support\f2837xs\examples\cpu1\flash_programming\cpu01


    I see a few issues in your sections memory range. Please use the memory range as given the linker command file.

    Please let me know if you have any concern.

    Thanks,
    Katta

  • Hi Katta,

    Can u please clarify what kind of issue u saw?

    I am waiting for the reply for one week and you are telling me the answer is "you have issues and go read examples to find the answer" without letting me know what the issues are? I believe everyone comes to the forum have already done some researches and tried to solve the issued by themselves. So please stop just post a link and tell people to go find the answer yourself, I have tried, that is the reason I am here.

    Back to engineering discuss, you mentioned I have sections memory range issue, I checked there is no mem overlap and no issue for the definition, what is the issue you mean?
  • Hi,

    I expected an issue with combining the FLASH memory sections in BOOTF : origin = 0x082000, length = 0x00E000/*. Please ignore.

    I have used your code changes and modified the example linker command file to reflect your memory definitions.

    I have attached the source code(flash_programming_cpu01.c) and linker command file(flash_programming_cpu1_FLASH.txt).

    I could run the program without any problem. Please check if linker command file attached works at your setup.

    Thanks, Katta

    /*
    //###########################################################################
    // FILE:    flash_programming_cpu1_FLASH.cmd
    // TITLE:   Linker Command File For all F28X7x devices
    //###########################################################################
    // $TI Release: F2837xS Support Library v3.06.00.00 $
    // $Release Date: Thu Mar 14 06:47:43 CDT 2019 $
    // $Copyright:
    // Copyright (C) 2014-2019 Texas Instruments Incorporated - http://www.ti.com/
    //
    // Redistribution and use in source and binary forms, with or without 
    // modification, are permitted provided that the following conditions 
    // are met:
    // 
    //   Redistributions of source code must retain the above copyright 
    //   notice, this list of conditions and the following disclaimer.
    // 
    //   Redistributions in binary form must reproduce the above copyright
    //   notice, this list of conditions and the following disclaimer in the 
    //   documentation and/or other materials provided with the   
    //   distribution.
    // 
    //   Neither the name of Texas Instruments Incorporated nor the names of
    //   its contributors may be used to endorse or promote products derived
    //   from this software without specific prior written permission.
    // 
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    // $
    //###########################################################################
    */
    
    /* ======================================================
    // For Code Composer Studio V2.2 and later
    // ---------------------------------------
    // In addition to this memory linker command file,
    // add the header linker command file directly to the project.
    // The header linker command file is required to link the
    // peripheral structures to the proper locations within
    // the memory map.
    // The header linker files are found in <base>\headers\cmd
    // For BIOS applications add:      F28X7x_Headers_BIOS.cmd
    // For nonBIOS applications add:   F28X7x_Headers_nonBIOS.cmd
    ========================================================= */
    
    /* Define the memory block start/length for the F28X7x
       PAGE 0 will be used to organize program sections
       PAGE 1 will be used to organize data sections
    
       Notes:
             Memory blocks on F28M3Xx are uniform (ie same
             physical memory) in both PAGE 0 and PAGE 1.
             That is the same memory region should not be
             defined for both PAGE 0 and PAGE 1.
             Doing so will result in corruption of program
             and/or data.
    
             Contiguous SARAM memory blocks or flash sectors can be
             be combined if required to create a larger memory block.
    */
    
    MEMORY
    {
    PAGE 0:    /* Program Memory */
              /* Memory (RAM/FLASH) blocks can be moved to PAGE1 for data allocation */
              /* BEGIN is used for the "boot to Flash" bootloader mode   */
    
       BEGIN           	: origin = 0x080000, length = 0x000002
       RAMM0           	: origin = 0x000122, length = 0x0002DE
       RAMD0           	: origin = 0x00B000, length = 0x000800
       RAMLS03          : origin = 0x008000, length = 0x002000
    /*	RAMLS1           : origin = 0x008800, length = 0x000800
        RAMLS2           : origin = 0x009000, length = 0x000800
        RAMLS3           : origin = 0x009800, length = 0x000800 */
       RAMLS4      		: origin = 0x00A000, length = 0x000800
       RESET           	: origin = 0x3FFFC0, length = 0x000002
      
    	/* Flash sectors */
       FLASHA           : origin = 0x080002, length = 0x001FFE	/* on-chip Flash */
    //   FLASHB           : origin = 0x082000, length = 0x002000	/* on-chip Flash */
    //   FLASHC           : origin = 0x084000, length = 0x002000	/* on-chip Flash */
    //   FLASHD           : origin = 0x086000, length = 0x002000	/* on-chip Flash */
    //   FLASHE           : origin = 0x088000, length = 0x008000	/* on-chip Flash */
       FLASHF           : origin = 0x090000, length = 0x008000	/* on-chip Flash */
       FLASHG           : origin = 0x098000, length = 0x008000	/* on-chip Flash */
       FLASHH           : origin = 0x0A0000, length = 0x008000	/* on-chip Flash */
       FLASHI           : origin = 0x0A8000, length = 0x008000	/* on-chip Flash */
       FLASHJ           : origin = 0x0B0000, length = 0x008000	/* on-chip Flash */
       FLASHK           : origin = 0x0B8000, length = 0x002000	/* on-chip Flash */
       FLASHL           : origin = 0x0BA000, length = 0x002000	/* on-chip Flash */
       FLASHM           : origin = 0x0BC000, length = 0x002000	/* on-chip Flash */
       FLASHN           : origin = 0x0BE000, length = 0x002000	/* on-chip Flash */
    
    	FLASHAPI        : origin = 0x0FA000, length = 0x002000   /* on-chip Flash */
    	BOOTF	        : origin = 0x082000, length = 0x00E000   /* on-chip Flash */
        FASTRAM         : origin = 0x01A000, length = 0x002000
        FLASHAPIRAM     : origin = 0x016000, length = 0x001000
    
    PAGE 1 :   /* Data Memory */
             /* Memory (RAM/FLASH) blocks can be moved to PAGE0 for program allocation */
    
        BOOT_RSVD       : origin = 0x000002, length = 0x000120     /* Part of M0, BOOT rom will use this for stack */
    	RAMM1           : origin = 0x000400, length = 0x000400     /* on-chip RAM block M1 */
        RAMD1           : origin = 0x00B800, length = 0x000800
    
        RAMLS5      : origin = 0x00A800, length = 0x000800
    
    	RAMGS0          : origin = 0x00C000, length = 0x001000
    	RAMGS1          : origin = 0x00D000, length = 0x001000
    	RAMGS2          : origin = 0x00E000, length = 0x001000
    	RAMGS3          : origin = 0x00F000, length = 0x001000
    	RAMGS4          : origin = 0x010000, length = 0x001000
    	RAMGS5          : origin = 0x011000, length = 0x001000
    	RAMGS6          : origin = 0x012000, length = 0x001000
    	RAMGS7          : origin = 0x013000, length = 0x001000
    
    }
    
    
    SECTIONS
    {
    
       /* Allocate program areas: */
       .cinit              : > FLASHH      PAGE = 0
       .pinit              : > FLASHH,     PAGE = 0
       .text               : >> FLASHH | FLASHI      PAGE = 0
       codestart           : > BEGIN	PAGE = 0
    /*
    #ifdef __TI_COMPILER_VERSION__
        #if __TI_COMPILER_VERSION__ >= 15009000
            GROUP
            {
                .TI.ramfunc
                { -l F021_API_F2837xS_FPU32.lib}
             
            } LOAD = FLASHD,
              RUN  = RAMLS03, 
              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  = RAMLS03, 
              LOAD_START(_RamfuncsLoadStart),
              LOAD_SIZE(_RamfuncsLoadSize),
              LOAD_END(_RamfuncsLoadEnd),
              RUN_START(_RamfuncsRunStart),
              RUN_SIZE(_RamfuncsRunSize),
              RUN_END(_RamfuncsRunEnd),
              PAGE = 0    
        #endif
    #endif
       
       /*Ram function specific sections*/
    		.TI.ramfunc: {}
    			LOAD = BOOTF,
           		RUN = FASTRAM,
    			LOAD_START(_RamfuncsLoadStart),
    			LOAD_SIZE(_RamfuncsLoadSize),
    			LOAD_END(_RamfuncsLoadEnd),
    			RUN_START(_RamfuncsRunStart),
    			RUN_SIZE(_RamfuncsRunSize),
    			RUN_END(_RamfuncsRunEnd),
    			PAGE = 0, ALIGN(4)
    
    		libFuncs:
    			LOAD = FLASHAPI,
    			RUN = FLASHAPIRAM,
    			LOAD_START(_apiFlashLoadStart),
    			LOAD_SIZE(_apiFlashLoadSize),
    			LOAD_END(_apiFlashLoadEnd),
    			RUN_START(_apiRamRunStart),
    			RUN_SIZE(_apiRamRunSize),
    			RUN_END(_apiRamRunEnd),
    			PAGE = 0, ALIGN(4)
    			{
    			-l F021_API_F2837xS_FPU32.lib <*> (.text)
    			}
    
    
       /* Allocate uninitalized data sections: */
       .stack              : > RAMM1       PAGE = 1
       .ebss               : >> RAMLS5 | RAMGS0 | RAMGS1       PAGE = 1
       .esysmem            : > RAMLS5       PAGE = 1
    
       /* Initalized sections go in Flash */
       .econst             : >> FLASHF | FLASHG       PAGE = 0
       .switch             : > FLASHH      PAGE = 0
    
       .reset              : > RESET,     PAGE = 0, TYPE = DSECT /* not used, */
    
       Filter_RegsFile     : > RAMGS0,	   PAGE = 1
    
       SHARERAMGS0		: > RAMGS0,		PAGE = 1
       SHARERAMGS1		: > RAMGS1,		PAGE = 1
    
       /* Flash Programming Buffer */
       BufferDataSection : > RAMD1, PAGE = 1, ALIGN(4)  
       
    }
    
    /*
    //===========================================================================
    // End of file.
    //===========================================================================
    */
    
    
    
    
    

    //###########################################################################
    // FILE:   flash_programming_cpu01.c
    // TITLE:  Flash Programming Example for F2837xS.
    //
    //! \addtogroup cpu01_example_list
    //! <h1> Flash Programming </h1>
    //!
    //! This example demonstrates F021 Flash API usage to program
    //! Flash Bank0 and Bank1 on F2837xS.
    //!
    //! \b Important: The Bank1 code is only applicable for devices that have the
    //!               second bank. Check the data manual to determine if your
    //!               device part number is compatible.
    //!
    //
    //###########################################################################
    // $TI Release: F2837xS Support Library v3.06.00.00 $
    // $Release Date: Thu Mar 14 06:47:43 CDT 2019 $
    // $Copyright:
    // Copyright (C) 2014-2019 Texas Instruments Incorporated - http://www.ti.com/
    //
    // Redistribution and use in source and binary forms, with or without 
    // modification, are permitted provided that the following conditions 
    // are met:
    // 
    //   Redistributions of source code must retain the above copyright 
    //   notice, this list of conditions and the following disclaimer.
    // 
    //   Redistributions in binary form must reproduce the above copyright
    //   notice, this list of conditions and the following disclaimer in the 
    //   documentation and/or other materials provided with the   
    //   distribution.
    // 
    //   Neither the name of Texas Instruments Incorporated nor the names of
    //   its contributors may be used to endorse or promote products derived
    //   from this software without specific prior written permission.
    // 
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    // $
    //###########################################################################
    
    //
    // Included Files
    //
    #include "F28x_Project.h"
    #include <string.h>
    #include "flash_programming_c28.h"      // Flash API example header file
    #include "F021_F2837xS_C28x.h"
    
    //
    // Defines
    //
    #define  WORDS_IN_FLASH_BUFFER    0xFF  // Programming data buffer, words
    #define PUMPREQUEST *(unsigned long*)(0x00050024)
    
    #ifdef __TI_COMPILER_VERSION__
        #if __TI_COMPILER_VERSION__ >= 15009000 
            #define ramFuncSection ".TI.ramfunc"
        #else
            #define ramFuncSection "ramfuncs"
        #endif
    #endif
    
    //
    // Globals
    //
    #pragma DATA_SECTION(Buffer,"BufferDataSection");
    uint16   Buffer[WORDS_IN_FLASH_BUFFER + 1];
    uint32   *Buffer32 = (uint32 *)Buffer;
    
    //
    // Function Prototypes
    //
    void Example_Error(Fapi_StatusType status);
    void Example_Done(void);
    void Example_CallFlashAPI(void);
    void FLASH_initAPI(void);
    
    void FLASH_init(void);
    
    extern Uint16 apiFlashLoadStart;
    extern Uint16 apiFlashLoadEnd;
    extern Uint16 apiFlashLoadSize;
    extern Uint16 apiRamRunStart;
    extern Uint16 apiRamRunEnd;
    extern Uint16 apiRamRunSize;
    
    //
    // Main
    //
    void main(void)
    {
    //
    // Step 1. Initialize System Control:
    // Enable Peripheral Clocks
    // This example function is found in the F2837xS_SysCtrl.c file.
    //
        InitSysCtrl();
    
    //
    //  Unlock CSM
    //
    //  If the API functions are going to run in unsecured RAM
    //  then the CSM must be unlocked in order for the flash
    //  API functions to access the flash.
    //  If the flash API functions are executed from secure memory
    //  then this step is not required.
    //
        //DcsmZ1Unlock();
    
    //
    // Step 2. Initialize GPIO:
    // This example function is found in the F2837xS_Gpio.c file and
    // illustrates how to set the GPIO to it's default state.
    //
    // InitGpio();  // Skipped for this example
    
    //
    // Step 3. Clear all interrupts and initialize PIE vector table:
    // Disable CPU interrupts
    //
        DINT;
    
    //
    // Initialize the PIE control registers to their default state.
    // The default state is all PIE interrupts disabled and flags
    // are cleared.
    // This function is found in the F2837xS_PieCtrl.c file.
    //
        InitPieCtrl();
    
    //
    // Disable CPU interrupts and clear all CPU interrupt flags:
    //
        IER = 0x0000;
        IFR = 0x0000;
    
    //
    // Initialize the PIE vector table with pointers to the shell Interrupt
    // Service Routines (ISR).
    // This will populate the entire table, even if the interrupt
    // is not used in this example.  This is useful for debug purposes.
    // The shell ISR routines are found in F2837xS_DefaultIsr.c.
    // This function is found in F2837xS_PieVect.c.
    //
        InitPieVectTable();
    
    //
    // Copy time critical code and Flash setup code to RAM
    // This includes InitFlash_Bank0(), Flash API functions and any functions that are
    // assigned to ramfuncs section.
    // The  RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart
    // symbols are created by the linker. Refer to the device .cmd file.
    //
       //memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
    
    //
    // Call Flash Initialization to setup flash waitstates
    // This function must reside in RAM
    //
        //InitFlash_Bank0();
        //InitFlash_Bank1();
    
        FLASH_init();
    //
    // Jump to RAM and call the Flash API functions
    //
        FLASH_initAPI();
        //Example_CallFlashAPI();
    }
    
    
    void FLASH_init(void)
    {
        memcpy(&apiRamRunStart,&apiFlashLoadStart, (size_t)(&apiFlashLoadSize));
        memcpy(&RamfuncsRunStart,&RamfuncsLoadStart, (size_t)(&RamfuncsLoadSize));
        InitFlash_Bank0();
        InitFlash_Bank1();
    
    }
    
    #pragma CODE_SECTION(FLASH_initAPI, "libFuncs");
    void FLASH_initAPI(void)
    {
        Fapi_StatusType oReturnCheck;
    
        EALLOW;
        Flash0EccRegs.ECC_ENABLE.bit.ENABLE = 0x0;
        //
        // Give pump ownership to FMC0(Bank0)
        //
        PUMPREQUEST = 0x5A5A0002;
    
        //
        // This function is required to initialize the Flash API based on
        // System frequency before any other Flash API operation can be performed
        // Note that the FMC0 register base address is passed as the parameter
        //
        oReturnCheck = Fapi_initializeAPI(F021_CPU0_W0_BASE_ADDRESS, 200);
    
        if(oReturnCheck != Fapi_Status_Success)
        {
        /*TODO*/
        }
    
        //
        // Fapi_setActiveFlashBank function sets the Flash bank0 and FMC0 for
        // further Flash operations to be performed on the bank0.
        // Note that the parameter passed is Fapi_FlashBank0 since FMC0 register
        // base address is passed to Fapi_initializeAPI()
        //
        oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank0);
        if(oReturnCheck != Fapi_Status_Success)
        {
        /*TODO*/
        }
    
        Flash0EccRegs.ECC_ENABLE.bit.ENABLE = 0xA;
        EDIS;
    }
    
    
    //
    // Example_CallFlashAPI - This function will interface to the flash API.
    //                        Flash API functions used in this function are
    //                        executed from RAM.
    //
    #pragma CODE_SECTION(Example_CallFlashAPI, ramFuncSection);
    void Example_CallFlashAPI(void)
    {
        uint32 u32Index = 0;
        uint16 i = 0;
    
        Fapi_StatusType oReturnCheck;
        volatile Fapi_FlashStatusType oFlashStatus;
        Fapi_FlashStatusWordType oFlashStatusWord;
    
        //
        // Bank0 Erase Program
        //
        EALLOW;
    
        //
        //Give pump ownership to FMC0
        //
        PUMPREQUEST = 0x5A5A0002;
    
        //
        // This function is required to initialize the Flash API based on System
        // frequency before any other Flash API operation can be performed
        // Note that the FMC0 register base address is passed as the parameter
        //
        oReturnCheck = Fapi_initializeAPI(F021_CPU0_W0_BASE_ADDRESS, 200);
    
        if(oReturnCheck != Fapi_Status_Success)
        {
            //
            // Check Flash API documentation for possible errors
            //
            Example_Error(oReturnCheck);
        }
    
        //
        // Fapi_setActiveFlashBank function sets the Flash bank0 and FMC0 for
        // further Flash operations to be performed on the bank0.
        // Note that the parameter passed is Fapi_FlashBank0 since FMC0 register
        // base address is passed to Fapi_initializeAPI()
        //
        oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank0);
        if(oReturnCheck != Fapi_Status_Success)
        {
            //
            // Check Flash API documentation for possible errors
            //
            Example_Error(oReturnCheck);
        }
    
        //
        // Erase Sector C
        //
        oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector,
                                                    (uint32 *)Bzero_SectorC_start);
    
        //
        // Wait until FSM is done with erase sector operation
        //
        while(Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
    
        //
        // 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_SectorC_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)
            //
            Example_Error(oReturnCheck);
        }
    
        //
        // A data buffer of max 8 words can be supplied to the program function.
        // Each word is programmed until the whole buffer is programmed or a
        // problem is found. However to program a buffer that has more than 8
        // words, program function can be called in a loop to program 8 words for
        // each loop iteration until the whole buffer is programmed
        //
    
        //
        // Example: Program 0xFF bytes in Flash Sector C along with auto-
        // generated ECC
        //
    
        //
        // In this case just fill a buffer with data to program into the flash.
        //
        for(i=0; i<=WORDS_IN_FLASH_BUFFER; i++)
        {
            Buffer[i] = i;
        }
    
        for(i=0, u32Index = Bzero_SectorC_start;
            (u32Index < (Bzero_SectorC_start + WORDS_IN_FLASH_BUFFER)) &&
            (oReturnCheck == Fapi_Status_Success); i+= 8, u32Index+= 8)
        {
            oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)u32Index,Buffer+i,
                                                        8,0,0,
                                                        Fapi_AutoEccGeneration);
    
            while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);
    
            if(oReturnCheck != Fapi_Status_Success)
            {
                //
                // Check Flash API documentation for possible errors
                //
                Example_Error(oReturnCheck);
            }
    
            //
            // 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,Buffer32+(i/2),
                                         &oFlashStatusWord);
    
            if(oReturnCheck != Fapi_Status_Success)
            {
                //
                // Check Flash API documentation for possible errors
                //
                Example_Error(oReturnCheck);
            }
        }
    
        //
        // Erase the sectors that we have programmed above
        // Erase Sector C
        //
        oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector,
                                                    (uint32 *)Bzero_SectorC_start);
    
        //
        // Wait until FSM is done with erase sector operation
        //
        while(Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
    
        //
        // Verify that SectorC 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_SectorC_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)
            //
            Example_Error(oReturnCheck);
        }
    
        //
        // Bank1 Erase Program
        //
    
        //
        // Give pump ownership to FMC1
        //
        PUMPREQUEST = 0x5A5A0001;
    
        //
        // This function is required to initialize the Flash API based on System
        // frequency before any other Flash API operation can be performed
        // Note that the FMC1 register base address is passed as the parameter
        //
        oReturnCheck = Fapi_initializeAPI(F021_CPU0_W1_BASE_ADDRESS, 200);
    
        if(oReturnCheck != Fapi_Status_Success)
        {
            //
            // Check Flash API documentation for possible errors
            //
            Example_Error(oReturnCheck);
        }
    
        //
        // Fapi_setActiveFlashBank function sets the Flash bank1 and FMC1 for
        // further Flash operations to be performed on the bank1.
        // Note that the parameter passed is Fapi_FlashBank1 since FMC0 register
        // base address is passed to Fapi_initializeAPI()
        //
        oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank1);
        if(oReturnCheck != Fapi_Status_Success)
        {
            //
            // Check Flash API documentation for possible errors
            //
            Example_Error(oReturnCheck);
        }
    
        //
        // Erase Sector P
        //
        oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector,
                                                     (uint32 *)BOne_SectorP_start);
    
        //
        // Wait until FSM is done with erase sector operation
        //
        while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
    
        //
        // Verify that SectorP 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 *)BOne_SectorP_start,
                                         BOne_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)
            //
            Example_Error(oReturnCheck);
        }
    
        //
        // Example:  Program 0xFF bytes in Flash Sector P with out ECC
        // Disable ECC so that error is not generated when reading Flash contents
        // without ECC
        //
        Flash1EccRegs.ECC_ENABLE.bit.ENABLE = 0x0;
    
        for(i=0, u32Index = BOne_SectorP_start;
            (u32Index < (BOne_SectorP_start + WORDS_IN_FLASH_BUFFER)) &&
            (oReturnCheck == Fapi_Status_Success); i+= 8, u32Index+= 8)
        {
            oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)u32Index,
                                                        Buffer+i,8,0,0,
                                                        Fapi_DataOnly);
    
            while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);
    
            if(oReturnCheck != Fapi_Status_Success)
            {
                //
                // Check Flash API documentation for possible errors
                //
                Example_Error(oReturnCheck);
            }
    
            //
            // 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,Buffer32+(i/2),
                                         &oFlashStatusWord);
    
            if(oReturnCheck != Fapi_Status_Success)
            {
                //
                // Check Flash API documentation for possible errors
                //
                Example_Error(oReturnCheck);
            }
        }
    
        //
        // Erase Sector P
        //
        oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector,
                                                     (uint32 *)BOne_SectorP_start);
    
        //
        // Wait until FSM is done with erase sector operation
        //
        while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady){}
    
        //
        // Verify that SectorP 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 *)BOne_SectorP_start,
                                         BOne_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)
            //
            Example_Error(oReturnCheck);
        }
    
        //
        // Enable ECC
        //
        Flash1EccRegs.ECC_ENABLE.bit.ENABLE = 0xA;
    
        //
        // Give pump ownership back to FMC0
        //
        PUMPREQUEST = 0x5A5A0000;
    
        EDIS;
    
        //
        // Example is done here
        //
        Example_Done();
    }
    
    //
    // Example_Error - For this example, if an error is found just stop here
    //
    #pragma CODE_SECTION(Example_Error,ramFuncSection);
    void Example_Error(Fapi_StatusType status)
    {
        //
        //  Error code will be in the status parameter
        //
        __asm("    ESTOP0");
    }
    
    //
    // Example_Done - For this example, once we are done just stop here
    //
    #pragma CODE_SECTION(Example_Done,ramFuncSection);
    void Example_Done(void)
    {
        __asm("    ESTOP0");
    }
    
    //
    // End of file
    //
    

  • Hi Katta,

    I found the issue based on the code you gave me. It is nothing related to the cmd file itself, but caused by when u call the flash init function. I called the flash init and flash init api function before the initialization of the interrupt vector. That is the cause for the memcpy trapped into an infinite loop. I am still curious about why it happens.

    But thanks anyway! 

    Regards,

    Li