storage variable in the specific location in memory

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

storage variable in the specific location in memory

4,577 Views
VeronicaFNX
Contributor I

Hello,
how I can storage variable in the specific location in memory?
For example I have

char variable;      //I want have variable on address 0x2000 1500

but how it say to compiler?
I'm using Code warrior 6.3 and m52233demo
please help.
Regards
               Vero

Labels (1)
0 Kudos
Reply
8 Replies

2,258 Views
CrasyCat
Specialist III
Hello
 
The only way you can get that working is defining a variable in a user specific section and placing the section appropriately in the linker control file.
 
Look at section "Defining Sections in Source Code" in the ColdFire_Build_Tools_Reference.pdf manual for more details.
 
CrasyCat
0 Kudos
Reply

2,258 Views
VeronicaFNX
Contributor I
I have watched the pdf and I do not understand it very well. You can write an example? Thanks
0 Kudos
Reply

2,258 Views
CrasyCat
Specialist III
Hello
In your ANSI C source file define the variable as follows:
 
Code:
#pragma push /* Save the compiler’s state. */#pragma define_section myData ".myData" far_absolute RW#pragma pop__declspec(myData) int variable;

 In the Linker Control File, add a new memory area in the MEMORY block and place the section there (in example below variable will be placed at 0x20007FF0).
Code:
MEMORY { vector_ram (RWX) : ORIGIN = 0x20000000, LENGTH = 0x00000500 user       (RWX) : ORIGIN = 0x20000500, LENGTH = 0x00007AF0 varSec      (RWX) : ORIGIN = 0x20007FF0, LENGTH = 0x00000010 ipsbar     (RWX) : ORIGIN = 0x40000000, LENGTH = 0x0}SECTIONS { .ipsbar  : {} > ipsbar .vectors : {  . = ALIGN (0x4); } > vector_ram .text : {  *(.text)  .= ALIGN(0x10);  *(.rodata)    .= ALIGN(0x10); } > user  .myData : {  *(.myData) } > varSec .data :  {          <..continue here ..>

That should be it
 
CrasyCat
0 Kudos
Reply

2,258 Views
VeronicaFNX
Contributor I
well…thanks and now I need storage a function in the specific location in memory?
For example I have

int main(void);      //I want have function on address 0x2000 1500

but how it say to compiler? can you write an example? Thanks
I'm using Code warrior 6.3 and m52233demo
regards
               Vero

0 Kudos
Reply

2,258 Views
CrasyCat
Specialist III
Hello
In the source file define the section / function as follows:
 
Code:
#pragma push /* Save the compiler’s state. */#pragma define_section myCode ".myCode" far_absolute RX#pragma pop
__declspec(myCode) void foo(void)
{
 /* Insert Code here */
}

Then place the section .myCode accordingly in the linker command file (something similar to what you did with the variable.
Define a MEMORY area and place the section in there.
CrasyCat
0 Kudos
Reply

2,258 Views
VeronicaFNX
Contributor I
I have watched the pdf and I do not understand it very well. You can write an example? Thanks
 
Your response:
 
Hello
The only way you can get that working is defining a variable in a user specific section and placing the section appropriately in the linker control file.
Look at section "Defining Sections in Source Code" in the ColdFire_Build_Tools_Reference.pdf manual for more details.
 
CrasyCat
 
My request:

how I can storage variable in the specific location in memory?
For example I have
char variable;      //I want have variable on address 0x2000 1500

but how it say to compiler?
I'm using Code warrior 6.3 and m52233demo
please help.

0 Kudos
Reply

2,258 Views
Lundin
Senior Contributor IV
In the prm file:

SECTION
SOME_SECTION_NAME = READ_WRITE 0x0001 TO 0x0001;
END

PLACEMENT
SOME_SEGMENT_NAME INTO SOME_SECTION_NAME;
END


In the c file:

#pragma DATA_SEG SOME_SEGMENT_NAME
char variable;
#pragma DATA_SEG DEFAULT

It is all in the manual.
0 Kudos
Reply

2,258 Views
CrasyCat
Specialist III
Hello
 
  Be careful that works for HC08 and HC12, but does not work that way for other architecture.
 
  This is one of the reason we always have to know which target CPU is used in CodeWarrior.
 
CrasyCat
0 Kudos
Reply