fpalma
Posts: 22
Joined: Sat Mar 16, 2013 7:10 pm

mmap: Operation not permitted

Thu Apr 02, 2015 3:44 pm

Hi to all,

I'm trying to convert a code that works, into a class.
This code maps the memory to manage the GPIO of the Raspberry Pi, and I can use it in a "normal" way, but If I convert the code into a class I get the error:

mmap: Operation not permitted
Failed to map the physical GPIO registers into the virtual memory space.


I attach the original code and the class. What can be the cause?
Thanks in advance!
Attachments
src.tar.gz
(10 KiB) Downloaded 196 times

User avatar
joan
Posts: 15377
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: mmap: Operation not permitted

Thu Apr 02, 2015 4:13 pm

...
mmap: Operation not permitted
...
You need to run with permission to mmap /dev/mem.

The simplest way is to run the program with sudo.

fpalma
Posts: 22
Joined: Sat Mar 16, 2013 7:10 pm

Re: mmap: Operation not permitted

Thu Apr 02, 2015 4:17 pm

joan wrote: The simplest way is to run the program with sudo.
Yes, I run the program with sudo in both cases.

StuartF
Posts: 35
Joined: Sun Feb 02, 2014 5:41 pm

Re: mmap: Operation not permitted

Thu Apr 02, 2015 4:35 pm

You may be redefining the struct...

Code: Select all

class RpiMemory
{
	struct bcm2835_peripheral gpio;
maybe should be

Code: Select all

class RpiMemory
{
	bcm2835_peripheral gpio;

fpalma
Posts: 22
Joined: Sat Mar 16, 2013 7:10 pm

Re: mmap: Operation not permitted

Thu Apr 02, 2015 4:44 pm

StuartF wrote: maybe should be

Code: Select all

class RpiMemory
{
	bcm2835_peripheral gpio;
Thanks, it compiles, but happens the same error.

User avatar
jojopi
Posts: 3424
Joined: Tue Oct 11, 2011 8:38 pm

Re: mmap: Operation not permitted

Thu Apr 02, 2015 4:52 pm

fpalma wrote:Thanks, it compiles, but happens the same error.
No, that fixes it. At the time of the mmap, you just need the variable gpio that is in scope to be the one whose .addr_p you have actually initialized.

StuartF
Posts: 35
Joined: Sun Feb 02, 2014 5:41 pm

Re: mmap: Operation not permitted

Thu Apr 02, 2015 4:59 pm

Also you make the same redefinitions throughout the class.
I was hoping that the hint would of made you look through the whole code.

Once you have defined the struct, there is no need to use 'struct', just the name.

fpalma
Posts: 22
Joined: Sat Mar 16, 2013 7:10 pm

Re: mmap: Operation not permitted

Thu Apr 02, 2015 5:10 pm

OK, I have deleted "struct bcm2835_peripheral" from the constructor of the class, and now I can map the memory. Has been a basic mistake ...
Thanks a lot!

Return to “C/C++”