ARM Technical Support Knowledge Articles

LOCATING VARIABLES AT ABSOLUTE MEMORY ADDRESSES

Applies to: ARM Development Tools

Answer


Information in this article applies to:


QUESTION

I need to locate a variable at a fixed memory address. How can I do this using C source code?

ANSWER

With the GNU GCC Compiler you may use only pointer definitions to access absolute memory locations. For example:

/* General Purpose Input/Output (GPIO) */
#define IOPIN0         (*((volatile unsigned long *) 0xE0028000))
.
.
.
IOPIN0 = 0x4;

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)));
.
.
.
var = 4;   // changes the memory location at 0x40001000

With the Keil CARM C Compiler, you may use either pointer definitions (as shown above) or _at_ keyword to define a variable at a fixed memory address. As with the RealView C Compiler, the following definition also makes a correct memory reservation, so that the area cannot be used twice.

int var _at_ 0x40001000;
.
.
.
var = 4;   // changes the memory location at 0x40001000

MORE INFORMATION

Article last edited on: 2008-01-09 07:47:55

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential