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.

Running functions from RAM

Other Parts Discussed in Thread: TMS570LS20216

Hello,

I am using a TMS570LS20216 with code composer studio 5.1

I have two questions:

   -First, does code run faster in RAM than in FLASH?

   -Second, I want to run some time critical functions from RAM and I am having problems.

My code is in C++, compiled in thumb2 mode and my command file looks like this:

MEMORY

{

     VECTORS (X) : origin=0x00000000 length=0x00000040

     FLASH (RX) : origin=0x00000040 length=0x001FFFC0

     STACKS (RW) : origin=0x08000000 length=0x00001500

     RAM (RWX) : origin=0x08001500 length=0x00026000

 }

 SECTIONS

    .intvecs : {} > VECTORS

     .text : {} > FLASH

     .const : {} > FLASH

     .cinit : {} > FLASH

     .pinit : {} > FLASH

     .bss : {} > RAM

     .data : {} > RAM

   ramfuncs : LOAD = FLASH,

                       RUN = RAM,

                       LOAD_START(__RamfuncsLoadStart),

                      LOAD_END(__RamfuncsLoadEnd),

                     RUN_START(__RamfuncsRunStart)

}

 

For  the functions that I want to run in RAM, I use a pragma directive like this:

#pragma CODE_SECTION( "ramfuncs" );

void MyClass::MyFunction( void )

{

   // Code

}

At the beginning of my main function I added a routine that copies the ramfuncs section from FLASH to RAM:

   char *src = (char *)&__RamfuncsLoadStart;
   char *end = (char *)&__RamfuncsLoadEnd;
   char*dest = (char *)&__RamfuncsRunStart;

   while ( src < end )
   {
      *dest++ = *src++;
   }

When I compile, I don't get any error and the map file looks good, I get something like this so my ramfuncs section loads from FLASH and runs in RAM and the size looks good.

SEGMENT ALLOCATION MAP

run origin      load origin      length       init length   attrs   members
----------       -----------     ----------     -----------    -----    -------
  08006b5c    000017e2    0000001e   0000001e      r-x     ramfuncs

 

My first problem is that when I try to load the resulting .out file to the developpement board with the XDS100V2 emulator (Everything works ok if I don't try to put functions in RAM) I get the error "File: C:/myfil.out: a data verification error occured, file load failed."

My second and most important problem is that we made a program that repackages the .out file (ELF format) to be loaded via CAN by a custom debugging application and in the .out file I only have the RUN address for section ramfuncs (I can't find the LOAD address) so my program doesn't know where to put this section in flash. On previous projects with a F28335 and CCS3 we did a similar scheme and it worked fine.

Is it possible to du what I want?

Can somebody help me, how do I get the LOAD address in the .out file?

 

 

 

 

  • Hi Martin,

    CCS is not able to load the program to the FLASH. Please program your code to FLASH. After reset, your code will copy the RamFunc to RAM and execute in RAM.

    Regards,

    QJ

  • Hello,

    Sorry, my question was not clear, I am unable to program the code on the developpement board FLASH, I keep getting error "File: C:/myfil.out: a data verification error occured, file load failed." .

    What about my other questions:

    - Does code run faster in RAM? Do you have an idea of how much faster?

    - My second and most important problem is that we made a program that repackages the .out file (ELF format) to be loaded via CAN by a custom debugging application and in the .out file I only have the RUN address for section ramfuncs (I can't find the LOAD address) so my program doesn't know where to put this section in flash. On previous projects with a F28335 and CCS3 we did a similar scheme and it worked fine.

    Thanks,

    Martin Beaucage

  • Hi QJ.

    I think the critical question to answer is related to this information in the post:

    run origin      load origin      length       init length   attrs   members
    ----------       -----------     ----------     -----------    -----    -------
      08006b5c    000017e2    0000001e   0000001e      r-x     ramfuncs

    The linker supports a separate load and run address for code.   Load address is where the code lives when it's downloaded or programmed.

    Run address is where the code lives when executed.   If load address != run address then you need some code to copy the section to the run address

    before it's executed, which appears to be fine in this case.

    The question is really for John Hall I think - to confirm that the flash programming utility knows the difference between load and run addresses and handles them properly.   If it looks at the run address in this case it might try to program the "RAM" which would be a problem.   It should be using the load address for programming.

  • Anthony, Based on the error message, he is trying to use integrated programming within CCS. Something in his data file is falling outside the device's memory map.
  • Hi,

    I scalled down my investigation of functions in RAM to a very simple program included in the post.

    4705.ramfunc.zip

    In this small program, I was able to load the program in flash with CSS and it works, I copy my function in RAM and it is executed there. I don't know why it doesn't work with my application project which is more complex (compiled in C++, including libraries, ...) but it is probably  a configuration problem on my part.

    I was also able to find the relocation (LOAD and RUN address) information in the .out file. Usually I only check the SECTION information which in this case only contains the RUN address but in the SEGMENT information we have both addresses.

    The original goal of this activity was to have code run faster from RAM then FLASH but with this example, I found out that my code is running at the same speed in RAM than in FLASH. So for me this issue is closed and I posted a new one which is called "Code execution speed". Because I think my code is running slower that it should.

    Thanks everyone.

    Martin Beaucage

     

  • Hi Martin,

    Did you measure how long it took to copy your RAM code from flash to RAM? I worked on a bootloader on ARM9 device before, and I copied the code in flash to run address in DDR in assembly code instead of C code.

    Regards,

    QJ

  • Hi,

    No I did not measure the copy time. What I was focusing on was how fast the function executes in RAM compared to FLASH. If I had been faster I would eventually have optimized the copy function to speed up boot time.

    Regards,

     

    Martin B.

  • Hi Martin,

    It is faster to access the internal RAM than the flash. About how faster, it depend on how often your code access the memory, etc? Thanks

    Regards,

    QJ