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.

Exactly which section of codes do I copy to RAM from flash?

Other Parts Discussed in Thread: TMS320F28335, SYSBIOS

Hi there

It's known that when C28x users want to boot their apps from flash, they need to :

1、use the proper linker.cmd

2、and call the classic memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (unsigned long)&RamfuncsLoadSize) before InitFlash()  (well of course, don't forget the variable declarations)

This method has been proven and it did work on my programmes, but I've got a question that's been haunting me:

See these codes first:

//----------------------

//in the main.c

//----------------------

……

void main()

{

        InitSysCtrl();

        memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (unsigned long)&RamfuncsLoadSize);
        InitFlash();

       user_fxn(bla);

       ……

}

//----------------------

//and in the linker.cmd we've got: (take the linker file for TMS320F28335 w/SYSBIOS for example)

//----------------------

SECTIONS
{
/* Allocate program areas: */
.cinit : > FLASH PAGE = 0
.pinit : > FLASH PAGE = 0
.text : > FLASH PAGE = 0
codestart : > BEGIN PAGE = 0
ramfuncs : LOAD = FLASH PAGE = 0,
RUN = L07SARAM PAGE = 1,
LOAD_START(_RamfuncsLoadStart),
LOAD_SIZE(_RamfuncsLoadSize),
LOAD_END(_RamfuncsLoadEnd),
RUN_START(_RamfuncsRunStart)

……

}

We can easily tell that which section of code is copied from flash to ram is actually determined by RamfuncsLoadStart and the other three variable exist. But I can find only these two places that  these four variables locate. So I really don't understand, how the compiler, or system, decides the value of these four variables, and how can I know which section of my code, or which user fxn,  is actually copied to RAM. Or this method simply copies all my fxns to RAM?

Thanks for reading and I do expect for your valuable reply.

  • Somewhere in your code base, there should be a named section called "ramfuncs" without the quotation marks.  For C code, this would be a compiler pragma CODE_SECTION directive which will identify which labels (ie. functions) will be included in this named section.

    Then the linker will place this named section called "ramfuncs" into flash (ie. LOAD time) and run from RAM.  The 4 variables you are referencing, ie. RamfuncsLoadStart, RamfuncsLoadSize, RamfuncsLoadEnd and RamfuncsRunStart are defined by the linker.

  • I think this question is of great importance. Say, I've got a delfino F28335, which has 34K RAM and 256K FLASH on board. My previous projects were quite simply and code size is quite small so it's OK to simply follow the traditional way and copy them all to the RAM. But what if my codes are way larger than 34K? One can't always expect to copy all the codes to RAM or what's the point for 256K Flash?

    Following up questions:

    1、 Can I control what fxn will be copied to RAM by calling memcpy() in different place or in a different way? If yes, how? If not, how to control that?

    2、Say we wanna copy all constant arrays to RAM, so we change RamfunsLoadStart, RamfuncsBLABLA to econstBLABLA (in both main,c and linker.cmd). Do the IDE or compiler or whatever decides the value of econstBLABLA automatically?

    Again thank you for reading

    P.S I've read SPRA958L many times so if you think I should turn to that, plz point out which section is more relevant. And I think SPRA958L is quite outdated, so whoever responsible for it, WOULD YOU PLEASE have it revised?)

  • Thank you for your reply

    #pragma CODE_SECTION thing? Well I have to confess I'm a newbie to C code so I don't really understand how that work. Would you please recommend me some files to learn more about that? Thank you very much!

  • I'm sorry if my response did not answer your initial questions.  I will attempt to be clearer now.

    ZuWei He said:

    I think this question is of great importance. Say, I've got a delfino F28335, which has 34K RAM and 256K FLASH on board. My previous projects were quite simply and code size is quite small so it's OK to simply follow the traditional way and copy them all to the RAM. But what if my codes are way larger than 34K? One can't always expect to copy all the codes to RAM or what's the point for 256K Flash?

    My first suggestion would be to only place performance critical code into RAM and leave the remaining (ie. majority) of the code in Flash and just execute from it.  I certainly understand that RAM is a precious resource therefore would only suggest performance critical code to be allocated to it.

     

    ZuWei He said:

    1、 Can I control what fxn will be copied to RAM by calling memcpy() in different place or in a different way? If yes, how? If not, how to control that?

    Yes, you can control which functions are copied to RAM.  As I mentioned in my above post, the use of the #pragma CODE_SECTION() construct in your C code will allow you to determine which functions are included in the named section.

     

    ZuWei He said:

    2、Say we wanna copy all constant arrays to RAM, so we change RamfunsLoadStart, RamfuncsBLABLA to econstBLABLA (in both main,c and linker.cmd). Do the IDE or compiler or whatever decides the value of econstBLABLA automatically?

    You need to direct which variables/lables are included in named sections.  You have the opportunity to create as many named sections as you desire.

    ZuWei He said:

    P.S I've read SPRA958L many times so if you think I should turn to that, plz point out which section is more relevant. And I think SPRA958L is quite outdated, so whoever responsible for it, WOULD YOU PLEASE have it revised?)

    The above literature number is associated with the Data Manual (aka. data sheet) of the processor.  This does not have any information regarding the compiler, linker, data sections, code sections, named sections, etc.  The documents you should be looking at for this information are the C28x C/C++ Optimizing Compiler User's Guide and C28x Assembly Language Tools User's Guide.
     
    Regarding the Data Manual itself, yes there is a newer version.  I would suggest you go back to the product folder and download the latest version (ie. SPRA958M).  You should also sign up for Product Alerts for that device which gives you an email notification of any documentation/collateral updates.

     

  • Well my detailed questions are being editted when you answered my first question, you may notice that I'm not native English speaker so it took me too long to write them all. It's completely my mistake, all I wanna say to you is thank you.

    I can't thank you enough for answering my questions and giving me these docs. I thought these docs only focus on asembly codes so I just skip them. As of SPRA958L, I'm sure when one browse the F28335 product page first and then click on "tech document", he'll get SPRA958L instead pf 958M, and a TI employee who answered me another question yesterday gave me the link to 958L, that's why I mistaked it as the latest version.:-)

    So all in all, thank you!                                                                                                                                                               

    Regards, He