[arm-gnu] Placing variable at absolute address in RAM
Moses McKnight
moses at texband.net
Thu Apr 5 17:04:04 UTC 2012
Actually, I think it does. That example just reserved 4 bytes
(sizeof(int)), but you can just as easily use a struct or probably even
an array.
Here's an example from the LPC17xx.h header from and NXP cortex-M3 chip.
typedef struct
{
volatile uint32_t mask[512];
} LPC_CANAF_RAM_TypeDef;
#define LPC_APB0_BASE (0x40000000UL)
#define LPC_CANAF_RAM_BASE (LPC_APB0_BASE + 0x38000)
#define LPC_CANAF_RAM ((LPC_CANAF_RAM_TypeDef *) LPC_CANAF_RAM_BASE)
See the core_cm3.h file from CMSIS for more examples.
If I'm not mistaken when you declare a variable the compiler/linker
always reserves enough memory for that type - even when you specify the
starting address like this.
On 04/05/2012 11:40 AM, JM wrote:
> I have come across that one a few times, but it doesn't reserve memory.
>
> ------------------------------------------------------------------------
> *From:* Moses McKnight <moses at texband.net>
> *To:* JM <hondgm at yahoo.com>
> *Sent:* Thursday, April 5, 2012 11:45 AM
> *Subject:* Re: [arm-gnu] Placing variable at absolute address in RAM
>
> with a quick search I came up with the following link (among many others):
> http://stackoverflow.com/questions/4067811/how-to-place-a-variable-at-a-given-absolute-address-in-memory-with-gcc
>
> This is the way it is done in the CMSIS headers and in the device
> headers for the LPC chips I'm using.
>
> Moses
>
> On 04/05/2012 09:37 AM, JM wrote:
> > The only reason I mentioned about GCC not making it easy is that
> > apparently at least one compiler makes it easy. I'm so jealous!
> >
> > With the RealView ARM C Compiler, you may use either pointer definitions
> > (as shown above) or *__attribute__((at(/address/)))* keyword to define a
> > variable at a fixed memory address. In contrast to the pointer
> > construct, the following definition also makes a correct memory
> > reservation, so that the area cannot be used twice.
> >
> > int var __attribute__((at(0x40001000)));
More information about the arm-gnu
mailing list