Keil™, An ARM® Company

Technical Support

ARM: LOCATING VARIABLES AT ABSOLUTE MEMORY ADDRESSES


Information in this article applies to:

  • MDK-ARM All Versions
  • CARM All Versions
  • GNU C Compiler for ARM All Versions

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

Last Reviewed: Wednesday, January 09, 2008


Did this article provide the answer you needed?
 
Yes
No
Not Sure