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

--Mark

[1] http://elinux.org/EBC_Exercise_11b_gpio_via_mmap 

On Monday, March 3, 2014 9:29:14 PM UTC-5, Charles Steinkuehler wrote:
>
> 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!  :) 
>
> Actually, I'm typing on a netbook in a hotel room, or I'd dig something 
> up for you...it 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. 
>
> ...here's one example, not the best, but maybe it will get you started: 
>
>
> https://github.com/cdsteinkuehler/linuxcnc/blob/MachineKit-ubc/src/hal/drivers/hal_bb_gpio.c#L73
>  
>
> On 03/03/14 14:48, dep...@phys.ksu.edu <javascript:> wrote: 
> > 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: 
> > 
> > #include <iostream> 
> > 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! 
> > 
> > BDD 
> > 
>
>

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to beagleboard+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to