[Icc-avr] Re: Doubts using external memory variables

Andy Syms asyms at technosoft.co.uk
Tue Oct 30 07:37:49 PST 2007


If you enable external RAM in the project options the compiler allocates ALL
global variables in the external RAM and uses the internal RAM purely for
the two stacks.

If you wish to assign certain variables as internal RAM and others as
external RAM do not enable the external RAM option in the project options.
All 'normal' global variables would then be allocated in the internal RAM.

Below is an extract from a previous post by John Barraclough (edited
slightly) demonstrating how to then define variables in the external RAM
area....


#pragma data:externalram
  /* Define your external RAM variables here */
#pragma data:data

Then, under the 'Project->Options->Target' tab, put the following in the
'Other options' edit box:

-bexternalram:0x8000


Assuming, in this case, that the external RAM starts on the 32k boundary,
all variables declared between the two '#pragma data:xxxxxx' statements will
be assigned in the external RAM.

You will also have to enable the external RAM access from your software.  If
you wish to use initialised variables this will mean modifying the startup
code.  If you don't need initialised variables just do it at the start of
main () but remember that the contents of the external RAM variables will be
undefined (ie not the usual zero) until their first assignment.


Regards

Andy



Hi,
Thanks Steven for your answer.
I have told the compiler about the external memory, so I don´t have to
control the bus (I have set the bit that enables the External SRAM in the
MCUCR register of the ATMega 128).
I want to allocate some variables in external memory and others in internal
one, not all of them in one specific memory (my external memory has a
back-up battery, so I want to save there some variables to not lose them if
I turn off my system). Moreover, it isn´t important for me the address
assigned by the compiler to a variable in external memory. I only want the
compiler to avoid variables overlaps.
Regards,
Guillermo Megía




More information about the Icc-avr mailing list