Directly accessing ARM registers from C/C++

I’ve got a BeagleBone Black running Angstrom, and I want to directly access the ARM335 registers from my C/C++ programs. A trivial example would be to “read” the Device_ID at memory location 0x44E10600. To do this I tried:

using namespace std;

unsigned long int *p;
unsigned long int DevID = 0x44E10600;

p1 = DevID; // <= this gives a compiler error: "invalid conversion from ‘long unsigned int’ to ‘long unsigned int*’
cout << *p1 << endl; // <= if I “cheat” around the compiler error, I get a Segmentation fault from this statement

// etc

Note 1: just the p1 = DevI statement causes a fatal compiler error (as indicated in the comment.
Note 2: I can get around this by using the -fpermissive compiler option, but then the cout statement (or any other way of extracting the contents of that memory location) gives me the segmentation fault.

I think this is a permissions thing – which means I ought to be able to fix it with some command. Is this correct? In any case, can someone tell me how to read/write to a particular memory location using c/c++? Much obliged!


I personally have not tried this, but have you thought about trying to use mmap to link the device driver io file directly into memory?


You are running on a system with virtual memory, so you can't just
access the physical memory location and expect it to work. There's a
re-mapping system of memory pages between your process address space and
the physical memory bus.

The way you do this is to mmap the /dev/mem file, with appropriate
offset and length values. This gets you a memory pointer in your
program you can use to access the physical memory address you want.

I'd provide full details, but I live in Topeka and am a KU fan! :slight_smile:

Actually, I'm typing on a netbook in a hotel room, or I'd dig something
up for should be pretty easy to find on-line with a bit of a
search. If you're still stuck tomorrow, I can dig up some code when I'm
at the office.'s one example, not the best, but maybe it will get you started:

Here’s[1] and example I use with my students.