Dereferencing an address in memory

I’m trying to get to the values of data stored in memory on the Beaglebone Black and experiencing a very fundamental problem. I have the following C code running in Linux.

int *p;
int value;

p = (int *)0x4A300000; // Start of PRU0 data ram
printf(“p addr: 0x%x\n”, p);
value = *p;
printf(“value: 0x%x\n”, value);

p prints fine but trying to print *p or value gives a Segmentation fault. Can anyone explain to me what is going on and how I can get to the data stored at a memory location on the BeagleBone?

Thanks,

Mike Pitman

In your code, p is a pointer to the user memory space, which goes
through virtual address translation before becoming a physical address
which is what you're trying to use.

You need to mmmap() the physical region you want to use from /dev/mem
into your user memory space. This will give you a user-mode pointer
to the physical memory. There are many examples of how to do this
floating around, but since you're trying to use the PRU, you might
want to checkout something like:

prussdrv (C code for accessing the PRU using uio_pruss):
https://github.com/beagleboard/am335x_pru_package/blob/master/pru_sw/app_loader/interface/prussdrv.c#L70