ROM-RAM copying - placing function/file in RAM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ROM-RAM copying - placing function/file in RAM

4,733 Views
james-lee
NXP Employee
NXP Employee

Hello,

 

I am using the MPC5603P device and the CodeWarrior for MPC55xx/56xx v2.5.

 

I would like to execute some function in the RAM in order to improve the execution time. Can you please let me know how to make a user-defined section, how to put some functions to this section, and how to copy these functions into the RAM.?

 

Best regards,

 

James

Labels (1)
10 Replies

1,721 Views
CrasyCat
Specialist III

Hello

 

I assume you are already generating a ROM image for your application as described in the attached Technical Note. Am I right?

 

Once this is done in order to get code copied over to RAM you need to:

   1- define a user defined section

      For a section containing code this is done as follows:
          #pragma section RX ".myCodeSec"

   

  2- Place the function in the section

      This is done as follows:

        __declspec (section ".myCodeSec") void myFunc(void)
           {

           ....

           }

      The #pragma section defining the section should appear prior to the declspec to the section.

 

  3- Place the function in a memory area located in RAM in the .lcf file.

      For example:

 

    GROUP : {   
       .__uninitialized_into_handlertable ALIGN(0x10) : {}
       .data   : {}
       .sdata  : {}
       .sbss   : {}
       .sdata2 : {}
       .sbss2  : {}
       .bss    : {}

       .myCodeSec : {}
    } > internal_ram

  Watch the cases while doing this. both compiler & linker are case sensitive.

 

I hope this helps.

 

CrasyCat

0 Kudos

1,721 Views
Geek19
Contributor III

Hello Crazy Cat,

I appreciate your response since I have the same exact problem and I am using Power PC  MPC5566 processor as well as CW 2.8. To my surprise when I tried to use the code you are suggesting the compiler complains about a syntax problem with the first line of code you are suggesting. I was just wondering if you are using a different version of the compiler or my setup is causing this error message. I would be thankful if you can suggest a verified piece of the code on CW 2.8 for this  problem. The first code line and the error message are as follows:

 

#pragma section RAMCode  ".MyRAMCode"

ERROR: pragma section expected an object type or access permission..................................

0 Kudos

1,721 Views
stanish
NXP Employee
NXP Employee

Hi Geek19,

 

This is possibly caused by typo.

You shoud use

 

  #pragma section RX ".MyRAMCode"

 

instead of

 

  #pragma section RAMCode  ".MyRAMCode"

 

where RX means permission ( Read only + eXecute  permision)

 

 

In order to avoid "Link error: Relocation(40) of symbol 'MyFunc' in 'main.o'is out of range. (1073738570 not in range [-16777216..33554430]'"

you should use:

 

  #pragma section RX ".MyRAMCode" code_mode=far_abs

 

for more information about #pragma section  I'd invite you to see the "Power Architecture Build Tools Reference.pdf"  located in "<CodeWarrior root dir.>\Help\Pdf" folder.

 

Stanish

 


1,721 Views
vramalingam
Contributor II

Hi Sliva,

i also want to copy some functions from flash to RAM..

i doing in below way!!

but @ memory map in .map file .code

.my_ram_code 40009000 00000000 00001df8          0(its allocating memory but not copying function in that location)

#pragma push

#pragma section code_type ".code_ram" ".code_ram" code_mode=far_abs
void Sector_Erase_Function (void);

#pragma pop

void Sector_Erase_Function (void)
{

..

}

in .LCF file i declared

MEMORY
{
    resetvector:           org = 0x00000000,   len = 0x00000008
    init:             org = 0x00000020,   len = 0x00000FE0
    exception_handlers:    org = 0x00001000,   len = 0x00001000
    internal_flash:        org = 0x00002000,   len = 0x0003E000

    internal_ram:          org = 0x40000000,   len = 0x00003000
    code_ram:      org = 0x40009000,   len = 0x00001000 //ADDED EXTRA
    heap  :                org = 0x40003000,   len = 0x00001000
    stack :                org = 0x40004000,   len = 0x00001000

}

    GROUP : {

       .__uninitialized_intc_handlertable ALIGN(2048) : {}

       .data   : {}

       .sdata  : {}

       .sbss   : {}

       .sdata2 : {}

       .sbss2  : {}

       .bss    : {}

    } > internal_ram

   

    .code_ram (VLECODE) : {} > code_ram //ADDED EXTRA

}

what might be the prblem?/

kindly help>>> i am using MPC5602p

0 Kudos

1,721 Views
stanish
NXP Employee
NXP Employee

Hi,

I suspect the function Sector_Erase_Function() is probably not referenced anywhere in your code (Sector_Erase_Function is probably not listed in the map file, section size = 0). Therefore it's probably dead-stripped by the linker.

If you'd like to avoid linker to remove a non-referenced object please add  a object/function name into FORCEACTIVE  section in your .lcf:

e.g.

FORCEACTIVE{ "Sector_Erase_Function" "bam_rchw" "bam_resetvector"}

Hope it helps

Regards,

Stan

0 Kudos

1,721 Views
james-lee
NXP Employee
NXP Employee

Hello CrasyCat,

 

Thanks for your answer. But the error message occurs when I compile the source codes.

 

"Link Error : Linker command file output section '.myCodeSec' has a type or input which is incompatible with section '. myCodeSec' in file 'C:\Lab\SENT_560P_v0.3\src\SENT_Driver\SENT_Driver.o'. Change the type or add input for this section."

 

How can I fix this error?

 

Best regards,

James

0 Kudos

1,721 Views
CrasyCat
Specialist III

Hello

 

Attached is a small sample project I did create back with CodeWarrior for MPC55xx V2.3.

 

I hope it is still working with later releases.

 

Make sure to build the target internal_FLASH

 

CrasyCat

0 Kudos

1,721 Views
Gus_Guzzler
NXP Employee
NXP Employee

Hello!

I get the same error when linking.

@CrasyCat

      In your project if setting Generate VLE instruction and Translate PPC Asm to VLE Asm from EPPC Processor tab I get the same error.

Changing the lcf to:

 

    GROUP : {
       .__uninitialized_intc_handlertable ALIGN(0x10) : {}
       .data   : {}
       .sdata  : {}
       .sbss   : {}
       .sdata2 : {}
       .sbss2  : {}
       .bss    : {}
       .RAM_Code (VLECODE): {}
    } > internal_ram

the error disappears :smileyvery-happy:

 

Hope it helps,

Gus_Guzzler

0 Kudos

1,721 Views
AhmadNasser
Contributor I

any idea how we can place a complete file into a RAM location without using the #pragma section?

Adding the pragmas to each file that has to be placed in RAM is not possible for me because the files are shared with other platforms that use different micro/compiler combination, so it is desirable to be able to do this through the linker file only.

 

Note, I have several files in my project, the majority will be placed in flash.

0 Kudos

1,721 Views
OliverTian
NXP Employee
NXP Employee

Hi,

    I am also doing the things.

    I found your code didn't use the sub_function of MyFunc().

    When I tried to call it, the error will be as

 'Link error: Relocation(40) of symbol 'MyFunc' in 'main.o'

is out of range. (1073738570 not in range [-16777216..33554430]'

 

   When the main does not call the function, I check the .map file, not MyFunc() embedded.

I am thinking how to call the relocationed function if it does have been relocationed.

 

Oliver

0 Kudos