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

1,343 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
2 Replies

417 Views
mccPaul
Contributor I

Hi Vero,
 
If you declare an automatic variable in a function it will be created somewhere on the heap, if it is a static variable, it will be in the bss section of your linked binary. In both cases there is no way in C to make the compiler create a variable at a specific location.
 
What you can do is create a pointer variable and set that to point to the location you wish to use:
Code:
char *p_variable;p_variable = 0x20001500;// Now you just dereference the pointer to access your char// e.g. to set the variable to *:*p_variable = '*';

 
It is a good idea to declare this type of variable in your linker command file, along with your other memory map declarations in the way that Simon has pointed out.
 
Cheers,
 
Paul.

Message Edited by mccp on 2007-03-1510:02 AM

Message Edited by mccp on 2007-03-1510:03 AM

0 Kudos
Reply

417 Views
SimonMarsden_de
Contributor II
Hi Vero

You can use the Linker Control File (LCF) to do this. Have a look at the following thread, where a similar question was discussed:

http://forums.freescale.com/freescale/board/message?board.id=CFCOMM&message.id=1578#M1578


In particular, the second and third posts in this thread gives some details which might be helpful.

Good luck


Simon
0 Kudos
Reply