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.

Code execution speed in TMS320F28335

Other Parts Discussed in Thread: TMS320F28335, TMS320F2808

Hi all,

My application has a loop than needs to be executed at faster speed. During debug process, I was executing my code within RAM and thus speed was ok. I realized once we run code from Flash it got significiantly slower. Thus I copied my function ( which needed to be executed fast) by using MemCopy( &RamfunctionLoadStart.........) as described in TI's sample code and documentation. My function does not use any shared library so it is more or less stand alone.

Unfortunately even after this, my code is not as fast as it running from RAM even though it  is faster than running from flash. Is there any way we can execute our code entirely from RAM or increase code execution speed to match with optimum level.

Thanks in advance,

Regards

Sandesh

  • Hi Sandesh

    Are you sure, your code is running from RAM now? Did you mark your time critical code with the pragma

    #pragma

     

    CODE_SECTION("section name") // CPP Syntax...
    #pragma CODE_SECTION(symbol, "section name") // C Syntax...

     

    Depending on your code size it will be difficult or even impossible to run it entirely from RAM, you need to copy the critical sections and run the rest from FLASH

    Best regards,

    Andreas

  • That's one of the reasons I went to the 28346, everything runs from RAM.

     

    John

     

  • If the code size is small enough to fit in the internal ram, you can copy all of the initialized sections from Flash to RAM. I wrote an app note and code that explains this process. It is available at:

    http://focus.ti.com/general/docs/litabsmultiplefilelist.tsp?literatureNumber=spraau8

    I have attached an updated code file for DSP28xxx_SectionCopy_nonBIOS.asm. Please use this one instead of the one provided with the download. It will be replaced on the web soon.

    Regards,

    Tim Love

    DSP28xxx_SectionCopy_nonBIOS.asm
  • Yes Andreas,

    I have done that.

    #pragma CODE_SECTION(adcTick, "ramfuncs");
    #pragma CODE_SECTION(cpu_timer0_isr, "ramfuncs");
    #pragma CODE_SECTION(epwm1_isr, "ramfuncs");
    #pragma CODE_SECTION(spiTxFifoIsr, "ramfuncs");

    But still wonder why my function adcTick is not as fast as running form RAM.

    Regards

    Sandesh

  • Hi Tim,

    I tried to implement your application note and got multiple error. One problem was once as implemented "copy_sections" , i am confused where to put

    LB _c_int00 ; Branch to start of boot.asm in RTS library

    Also in DSP28xx_SectionCopy_nonBIOS.asm has extra line of SUBB ACC,#1 , which has not been speciifed in your app note.

    And few more errors. Is there any specific example to do this for TMS320F28335 as your application demonstrates using TMS320F2808.

     

    Also do you have any idea why my function, which as been specified to run form RAM, is not as fast as running entire things from RAM. My function does not uses any lib function nor has any fucntions call.

     

    Regards

    Sandesh

  • Hi Sandeesh

    I can think of three issues that you might be having:

    1. You forgot to edit the linker file to specify different load and run addresses. So while you do copy the function from FLASH to RAM, it is the function in the Flash that gwets called. You can easily check this by observing th PC (program counter) when you enter the function.

    or

    2. Within the function you have multiple accesses to constants/data placed in FLASH

    or

    3. the function is in the same memory block as the date the function is working on so you get multiple pipeline stalls

    Regards, Mitja

     

  • Hi Mitja,

    Thanks for the response.

    I can definitely rule out possibility 1 because my code does get faster ( only problem is, it is not as fast as running whole setup entirely from ram). Had it been running form Flash i would not have seen speed improvement. My program Counter before main is 0x33C000. and before ram fucntion is 0x33C71D. I am not sure what that means.

    Regarding 2 and 3, all my varialbes are located in @data sections. My code and data memory ( so far as i know from CMD file) is located in different RAM section.

    I checked by expanding my variable size equal to allowed RAM size and it compiled fine.

     

    Regards

    Sandesh

  • Hi Sandesh

    check the program counter when you enter the function and not before you enter the function. It should be in some RAM block. If I remember correctly some of the RAM blocks in 28335 have wait-states (check memory maps in SPRS439)

    Regarding the code and data placement be aware that you can still put two different sections (e.g. .ebss and .text) in the same memory block (L0SARAM), so check precisely in which memory block each section goes (maybe you did, but I can not tell from your answer as you must be very specific if you are talking about memory section or blocks)

    Regards, Mitja

  • Hi Mitja,

    I think you are right. I am just a beginner at C2000 but here is my obervation. 

    My Program counter has address 0x33C91C when in this function.

    e.g. 0x33C924:   0622        MOVL       ACC,@34 ( when viewed in disassembly)

    Now my F28334.cmd commnds says that...

     FLASHA      : origin = 0x33C000, length = 0x003F80     /* on-chip FLASH */

    This actually contains my PC, which is 0x33C924.

     

    Does that mean my code is still running form Flash. If yes, can you please tell why,

    I use, #pragma CODE_SECTION(sampleData, "ramfuncs");  for running it in RAM 

    i declare

    extern Uint16 RamfuncsLoadStart;
    extern Uint16 RamfuncsLoadEnd;
    extern Uint16 RamfuncsRunStart;

     

    and call

       MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);

    // Call Flash Initialization to setup flash waitstates
    // This function must reside in RAM
       InitFlash();

    in main code. I folow all steps specified in DSP2833x_HeaderFiles_QuickStart_Readme.pdf file.....

     

    Regards

    Sandesh

     

     

     

     

     

     

  • Hi Sandesh

    as all engineers (myself included) you are just skimming over the manuals - typicall mistake. If you would read the mentioned document more carefully, you'd see that you also need to modify the .cmd file in order for linker to replace calling address for the function from FLASH with the one form RAM (you basically have two similar functions)

    Regards, Mitja

  • Mitja,

    I did go through all the steps as instructed in "DSP2833x_HeaderFiles_QuickStart_Readme.pdf".

    - I first linked F28334.cmd

    - included password.asm file.

    - added files to be executed from RAM by

    #pragma CODE_SECTION(sampleData, "ramfuncs");
    #pragma CODE_SECTION(adcTick, "ramfuncs");
    #pragma CODE_SECTION(cpu_timer0_isr, "ramfuncs");
    #pragma CODE_SECTION(epwm1_isr, "ramfuncs");
    #pragma CODE_SECTION(spiTxFifoIsr, "ramfuncs");

    - then i checked SECTION code in my CMD file and it is what the pdf file says...

       /* Allocate program areas: */
       .cinit              : > FLASHA      PAGE = 0
       .pinit              : > FLASHA,     PAGE = 0
       .text               : > FLASHA      PAGE = 0
       codestart           : > BEGIN       PAGE = 0
       ramfuncs            : LOAD = FLASHD,
                             RUN = RAML0,
                             LOAD_START(_RamfuncsLoadStart),
                             LOAD_END(_RamfuncsLoadEnd),
                             RUN_START(_RamfuncsRunStart),
                             PAGE = 0

    - included DSP2833x_MemCopy.c in project and added MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);

    - define RAMfunctions varialbes....

    - finally add

     MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart); and

    InitFlash(); in my main code...

     

    Can you see anything wrong with this....

    Thanks for your reply...

    Regards

    Sandesh

     

     

     

     

     

  • Hi Sandesh,

    Firs let me apologize for my wrong conclusion.

    It seems that you have more pesky problem.

    I'd compile, flash, load symbols and then put check tha addresses of mentioned functions in watch window (e.g. sampleData). It should be somewhere in RAML0

    If they are not in RAML0, go to compile options and check the boxes "keep asm files" and "generate asm listing files. Compile again check .asm file where sampleData is in and make sure that the compiler switched section. If it did, then you have a linker problem otherwise you have a compiler problem. Also check compiler generated .map file wher does it place "ramfuncs" section and what is the run time address.

    Hope this will shed some light

    Regards, Mitja

  • Hi Mitja,

    Thank you so much for your presistent reply. I finally go to get it running from RAM and yes, it did improve my execution speed.

    Problem; actually there was not any. I had all the #pragma CODE_SECTION(......., "ramfuncs"); directives put in main and that seems to be problem. Thanks to you, I checked the location of all these function that needed to run form ram and i was actually in flash.

    So when i checked 0x008000 ( RAML0) it has only two function, which was InitFlash() and delay_us. I saw that, #pragma CODE_SECTION(InitFlash, "ramfuncs"); was declared in DSP2833x_SysCtrl.c and not it main. So I did the same. I put all the corresponding #pragma for my functions in same file as it was been defined in. And that worked....

    This could be bug in CCS or my ignorance...

     

    Regards

    Sandesh