Coldfire: How to put Flash-Program into Ram

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

Coldfire: How to put Flash-Program into Ram

5,622 Views
Harrie
Contributor I
Our system: MCF5272, 16 bit flash, 32bit DRAM.
 
We have changed the LinkerCommandFile so the Program data gets the adress into ram.
We also changed the copy table, so the program must be copied to ram.
Unfortunally the program doesn't run.
 
We know we do something wrong but what.

Message Edited by CrasyCat on 2007-04-13 02:27 PM

Labels (1)
0 Kudos
Reply
13 Replies

1,260 Views
CrasyCat
Specialist III

 Hello

To get code from some function copied to RAM and executed from there I would try the following:

  1- Define the functions to be copied to RAM in a user defined section.

     This is done as follows:

Code:

#pragma define_section RAMCode ".RAMCode" far_code__declspec(RAMCode) unsigned int Fibonacci(unsigned int n) {  unsigned fib1, fib2, fibo;  int i;  fib1 = 0;  fib2 = 1;  fibo = n;  i = 2;    while (i <= n) {     fibo = fib1 + fib2;           fib1 = fib2;    fib2 = fibo;    i++;         }               return(fibo);}


 

  2- In your .lcf file specify you want to place the user defined section into ROM.

Code:

    .main_application_data : AT(___DATA_ROM) {  . = ALIGN(0x8);  *(.exception)  . = ALIGN(0x8);  __exception_table_start__ = .;  EXCEPTION  __exception_table_end__ = .;    ___sinit__ = .;     STATICINIT  __START_DATA = .;  *(.data)  . = ALIGN(0x8);  __END_DATA = .;  __START_SDATA = .;  *(.sdata)  . = ALIGN(0x8);  __END_SDATA = .;         . = ALIGN(0x8);         StartCopiedCode = .;         *(.RAMCode)         EndCopiedCode = .; } > DATA


 
3. Initialize a copy down block in the linker command file  with information about data to be copied into RAM:

Code:

# Locate the ROM copy table into ROM after the initialized data _romp_at = CodeToCopy + SIZEOF(.CodeInRAM); .romp : AT(_romp_at) {  __S_romp = _romp_at;  WRITEW(___DATA_ROM);  WRITEW(ADDR(.main_application_data));  WRITEW(SIZEOF(.main_application_data));  WRITEW(0);  WRITEW(0);  WRITEW(0); } 


 
This should do it

CrasyCat

0 Kudos
Reply

1,260 Views
Geek19
Contributor III

Hi Clarify Cat,

Could you please elaborate on where you put the code in step 2? Is this another section or another group?

What about "main_application_data" name? Is this the name of a Memory block ? Please clarify. Since I am using CW 5.9 for Power PC I was wondering if there would be any difference between this code and the code I need to run on my version of the compiler?

Thanks;

0 Kudos
Reply

1,260 Views
CrasyCat
Specialist III

Hello

 

Wait a minute. If you are using Power PC, this does not apply to your case. This thread is for Coldfire project only.

 

In order to execute portion of your application from RAM in a PowerPC application, you need to create a ROM image of your application, and then copy this image into RAM

 

Attached document explains how to execute whole application from RAM.

If you need to run only selection portion of the application from RAM, make sure the code is stored in a user defined section and then place the user defined section into a GROUP that is allocated in RAM.

 

Sections .text and .rodata  in this case will stay in ROM.

 

CrasyCat

0 Kudos
Reply

1,260 Views
Geek19
Contributor III

Hello Crasy Cat,

In pursue of getting my code to run partially in RAM I have defined the appropriate sections and memory allocations. The final compilation generates the following error message,

[Link Error: Section ".sdata2" is overwriting the previous section address. So change the starting address of ".sdata2"]

I tried various combinations and nothing changed the error message. Please take a look at the attached .lcf file and let me know what you think is appropriate to be done.

Thanks;

0 Kudos
Reply

1,260 Views
CrasyCat
Specialist III

Hello

 

Can you please specify which value you did specify as RAM BufferAddress and ROM Image Address when generating the ROM image?

 

CrasyCat

0 Kudos
Reply

1,260 Views
Geek19
Contributor III

Hi CrasyCat,

both values are 0x00020000 and that is starting address of my internal_flash memory block as specified in my .lcf file.

Thanks;

0 Kudos
Reply

1,260 Views
CrasyCat
Specialist III

Hello

 

Why did you place section .sdata2 in internal_flash.?

.sdata2 and .sbss2 should always be allocated next to one another.

So if you want to move sdata2 to flash you have to move there sbss2 as well.

 

Then the LOAD modified is only needed to placement of sections located in flash.

You do not need them on the section you place in internal_ram (.ivor_branch_table , .intc_hw_branch_table , .ivor_handlers ).

 

 

CrasyCat

0 Kudos
Reply

1,260 Views
Geek19
Contributor III

Hi CrasyCat,

I appreciate your response, the modification you suggested is in place and I get an out of range error message in regards to pointers to my interrupt routine calls in hardware interrupts table! They are considered out of range eventhough the entire table is asked to be placed in RAM. I do not know how to redefine these labels to avoid these error message. I have 10 functions as such and there are 10 error message complaining that the labels in hardware interrupt table are out of range! Be the way, is there any tutorial or guidelines that specifies why these sections such as sbss or sdata2 and the like shall be placed in certain areas of memory? The .LCF and my HW branch table is attached for your verification.

Thanks;

Geek19

0 Kudos
Reply

1,260 Views
CrasyCat
Specialist III
Spoiler
 

Hello

 

There seems to be an issue in your project.

I am unable to reproduce the trouble on a simple project.

 

I would recommend you to submit a service request for that.

Click here to submit a service request.

Make sure to attach a reproducible project and installed product information to the service request.

CrasyCat

0 Kudos
Reply

1,260 Views
BitGen
Contributor I
Great info! I was just considering this myself. But I have a few Q's and I'm not very good with the LCF stuff.
 
I understand the code from step 1.
 
From step 2, is it necessary to declare the ".RAMcode" section within MEMORY? I'm assuming the supplied code segment is declared within SECTIONS. It looks very similar to my ".user : { ... } > user" declaration.
 
Within step 3, the variables "CodeToCopy" and ".CodeInRAM" are not referenced in the previous code segments. How are these defined? And where did "__S_romp" come from? Is that for the execution to read to know where to start copying from?
 
TIA,
John
0 Kudos
Reply

1,260 Views
CrasyCat
Specialist III
Hello
 
In step 2, it mainly depends if you want to copy the code next to the data or if you want to place it at a
separate location.
If you do not want to get the code copied right after the data, then you have to define the memory area where you want to place it in the MEMORY block.
 
Step 3. I was too quick here I did a mismatch with another sample program I have written. Sorry.
 
Code:
 _romp_at = ___DATA_ROM + SIZEOF(.main_application_data); .romp : AT(_romp_at) {  __S_romp = _romp_at;  WRITEW(___DATA_ROM);  WRITEW(ADDR(.main_application_data));  WRITEW(SIZEOF(.main_application_data));  WRITEW(0);  WRITEW(0);  WRITEW(0); } 

 
where .main_application_data is the name of the section where application data are located 
__DATA_ROM is pointing at the end of the code segment.
Refer to ColdFire_Build_Tools_Reference.pdf, chapter "Coldfire Linker", section "LCF Syntax" ->  "ROM-RAM Copying" for more info.
 
CrasyCat
0 Kudos
Reply

1,260 Views
DaveTonyCook
Contributor IV

Hi There,

 

Does it matter where you place the .romp section?  I've move mine to follow the initialised data section which places .romp before the .bss section now. It used to be after the .bss section and just before the end of stack.

 

Could you tell me also what .romp does and how it does it please.  If this has already been answered on the forum please point me to the thread.

 

Thanks

 

Dave

0 Kudos
Reply

1,260 Views
CrasyCat
Specialist III

Hello

 

I did never try to move the .romp section down in the linker file.

So I do not know whether this will work.

 

The data in the .romp section are processed by the function  __copy_rom_sections_to_ram. This function is called from startup code and is implemented in

   {Install}\MCU\ColdFire_Support\ewl\EWL_Runtime\Runtime_ColdFire\Source\ROMCopy.c
 

CrasyCat

 

0 Kudos
Reply