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.

Fapi_setActiveFlashBank() execution crashes with custom command linker file.



Hi,

I have a C2000 project working with ability to erase and write memory using Fapi provided by TI. For the purpose of downloading a binary .out of this project using a USB project, the command linker file was edited. The aim was to separate different sections (.cinit, .pinit, .text, ramfuncs, .econst, .switch) into separate flash memory sections. However, execution of Fapi_setActiveFlashBank() crashes if the location of Fapi_setActiveFlashBank() in flash memory is in different section from ramfuncs.

given the 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 = 0x0B8002, length = 0x001FFE /* 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 */

This works fine:

.cinit : > FLASHA PAGE = 0
.pinit : > FLASHA, PAGE = 0
.text : >> FLASHA | FLASHB | FLASHC | FLASHD PAGE = 0
codestart : > BEGIN PAGE = 0
ramfuncs : LOAD = FLASHA,
                     RUN = RAMLS0 | RAMLS1 | RAMLS2 |RAMLS3,
                     LOAD_START(_RamfuncsLoadStart),
                     LOAD_SIZE(_RamfuncsLoadSize),
                     LOAD_END(_RamfuncsLoadEnd),
                     RUN_START(_RamfuncsRunStart),
                     RUN_SIZE(_RamfuncsRunSize),
                     RUN_END(_RamfuncsRunEnd),
                     PAGE = 0

.econst : > FLASHA PAGE = 0
.switch : > FLASHA PAGE = 0

However, if a flash memory sector B is used for ramfuncs:

ramfuncs : LOAD = FLASHB

the execution of Fapi_setActiveFlashBank() crashes. After a more thorough investigation it crashes if : Fapi_setActiveFlashBank() is in different Flash section than ramfuncs.

if I take FlashB and split it in two:

FLASHB1 : origin = 0x082000, length = 0x001000 /* on-chip Flash */

FLASHB2 : origin = 0x083000, length = 0x001000 /* on-chip Flash */

and try this:

.text : >>  FLASHB2 | FLASHC | FLASHD PAGE = 0
codestart : > BEGIN PAGE = 0
ramfuncs : LOAD = FLASHB1,

it fails as Fapi_setActiveFlashBank() is in FLASHB2 and ramfuncs is in FLASHB1.

This however works:

.text : >>  FLASHB2 | FLASHC | FLASHD PAGE = 0
codestart : > BEGIN PAGE = 0
ramfuncs : LOAD = FLASHB2,

If I check the ramfuncs section it has three funtions.

ramfuncs 0           00080a37 0000002D RUN ADDR = 00008000
                                00080a37 00000025 F2837xD_SysCtrl.obj (ramfuncs:_InitFlash)
                                00080a67 00000004 F2837xD_usDelay.obj (ramfuncs)
                                00080a6b 00000004 sysctl.obj (ramfuncs)

Any Ideas of why does one of these have to be in same memory section as Fapi_setActiveFlashBank() ?

  • Hi Ugnius,

    Please note that the Flash API functions have to be executed from RAM only.  See below linker command file snippet from TI in which Flash API functions are set to load in to Flash but to run from RAM.  Application code should copy the API functions from Flash to RAM using memcpy before calling these functions during execution.  You might have noticed the usage of memcpy function in the InitSysCtrl() function provided by TI.  If the Flash API functions are executed from Flash, Flash erase and program operations will not succeed.       

    GROUP

    {
    ramfuncs
    { -l F021_API_F2837xD_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

    Thanks and regards,
    Vamsi

  • Thanks for the reply. I will give this a try. I thought only the InitFlash() function has to be run from RAM. If all of the Flash API functions have to be run from RAM though, it's interesting how it was working without that being defined as you suggest.
  • Thanks Vamsi.

    I put the fapi library into different section and load it to RAM as you suggested. All is working fine now.