relocating code from FLASH to RAM

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

relocating code from FLASH to RAM

Jump to solution
2,087 Views
sandeepsirpatil
Contributor I

Hello,

 

Code warrior version: 10.3

Processor: MPC5605B

 

I am trying to relocate a function from flash to RAM and having trouble with the linker. I have made necessary changes as per the App note AN4497. The linker is not obeying the relocation directive and placing the code at memory address of 0x000000.  I have attached the project.

 

Following the guideline in the appnote (AN4497) i have been successful in relocating a block of data (const data) form flash to RAM. When I try for a function I am having this trouble.

 

I have tried as suggested in this post (How to Copy Function from Flash to RAM & execute it) and it did not work.

 

Any help is appreciated.

Thanks,

Sandeep Sirpatil

 

in  main.c i have the following :

#pragma section ".myCodeInRAM" data_mode=far_abs

__declspec(section ".myCodeInRAM") void serviceWatchdog(void);

void serviceWatchdog(void)

{

  SWT.SR.R = 0x0000A602; /* Service Watchdog: write 0xA602 followed by 0xB480 */

  SWT.SR.R = 0x0000B480;

}

 

in LCF file i have:

 

internal_ram:     org = 0x40000000,   len = 0x0000D000 /* 56K */  
myram:            org = 0x4000D000,   len = 0x00001000 /* 4K */
heap  :           org = 0x4000E000,   len = 0x00001000 /* 4K */

 

.my_ram :
{
*(myCodeInRAM)
} > myram



In the MAP file:

 

.my_ram section layout

  Starting        Virtual  File

  address  Size   address  offset

  ---------------------------------

 

.myCodeInRAM section layout

  Starting        Virtual  File

  address  Size   address  offset

  ---------------------------------

  00000000 000022 00000000 00001000  1 .myCodeInRAM     main_c.obj

  00000000 000022 00000000 00001000  2 serviceWatchdog     main_c.obj

 

Memory map:

     .myCodeInRAM 00000000 00000024 00001000 00003800 00003800     0

 

 

 

 


 


Original Attachment has been moved to: testCodeinRam.zip

Labels (1)
Tags (2)
0 Kudos
Reply
1 Solution
1,079 Views
Carlos_Musich
NXP Employee
NXP Employee

Hello Sandeep,

You can see below a very simple example:

In main.c

 

#pragma section ".myCodeInRAM" code_mode=far_abs    //For routines code_mode need to be mentioned

__declspec(section ".myCodeInRAM") int _add(int a , int b);

 

int main(void) {

   volatile int i = 0; 

   volatile int total = 0;

 

   for (;;)

   {

      total = _add(i , i);

      i++;

  }

}

__declspec (section ".myCodeInRAM") int _add(int a , int b)

{

  returna + b;

}

In .LCF

GROUP : {

   .my_ram (VLECODE): {    //instruction mode VLECODE has to mentioned

        *(.myCodeInRAM)

   }

} > myram

Hope it helps.

Carlos

View solution in original post

0 Kudos
Reply
3 Replies
1,080 Views
Carlos_Musich
NXP Employee
NXP Employee

Hello Sandeep,

You can see below a very simple example:

In main.c

 

#pragma section ".myCodeInRAM" code_mode=far_abs    //For routines code_mode need to be mentioned

__declspec(section ".myCodeInRAM") int _add(int a , int b);

 

int main(void) {

   volatile int i = 0; 

   volatile int total = 0;

 

   for (;;)

   {

      total = _add(i , i);

      i++;

  }

}

__declspec (section ".myCodeInRAM") int _add(int a , int b)

{

  returna + b;

}

In .LCF

GROUP : {

   .my_ram (VLECODE): {    //instruction mode VLECODE has to mentioned

        *(.myCodeInRAM)

   }

} > myram

Hope it helps.

Carlos

0 Kudos
Reply
1,079 Views
sandeepsirpatil
Contributor I

This seems to be the trick. The linker places the function at the correct address (Flash and RAM). I also tested it in my main project code and it seems to work correctly.

Thank you very much.

0 Kudos
Reply
1,079 Views
trytohelp
NXP Employee
NXP Employee

Hi,

Can I recommend you to contact the support team via CRM system ?

This issue will be probably moved to another team.

For Technical Support Issues please use Freescale on line support web page.

  - Go to following URL: http://www.freescale.com/TechSupport

  - Click on Submit a Service Request. You will come to a login page.

  - If you are already registered with Freescale (using the Forum, subscribed to newsletter, ...) use your Freescale login and password. Otherwise, Click on "Register Now" to get registered.

  - You can submit your request through the web from there.

Else you can send an email to support@freescale.com

Regards

Pascal

0 Kudos
Reply