Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pinMode PWM: Unable to do this when using /dev/gpiomem. Try sudo? #211

Open
Owhenthesaints opened this issue Mar 29, 2024 · 6 comments
Open

Comments

@Owhenthesaints
Copy link

Owhenthesaints commented Mar 29, 2024

I have been scouring the web for a few hours now and I cannot seem to fix the problem. I am using rpi 4b 8GB ram with ubuntu 22.04 server
pinMode PWM: Unable to do this when using /dev/gpiomem. Try sudo?
I am running my executable through ROS2 and hence cannot give it root privileges. I have already tried sudo adduser pi gpio, sudo usermod -a -G gpio $USER, sudo chown root.gpio /dev/gpiomem andsudo chmod g+rw /dev/gpiomem and none will do. Thanking you for your answer if there is one.

@mstroh76
Copy link
Member

mstroh76 commented Mar 29, 2024

What Wiring Pi Version do you use?
It's sounds like you need /dev/mem to use the feature, so changing rights for /dev/gpiomem will not help.

Comment in Source:
See if we're using the /dev/gpiomem interface, if-so then some operations can't be done and will crash the Pi.

Looks like it's not possible without root access. If I find the time I can test if it's really crashing (need to bypass the check).
Maybe PWM its outside of gpiomem memory, like at Pi5, then there is no solution to this problem.

@Owhenthesaints
Copy link
Author

I am using version 3.0

@Owhenthesaints
Copy link
Author

Owhenthesaints commented Mar 29, 2024

i have also changed the rights of /dev/mem still no fix

@Owhenthesaints
Copy link
Author

If it is not doable it is fine I have found a solution to go sudo with ros2. I saw this question pop up on other forums so I think it would be a good idea if it is not doable to just put it down. I would investigate myself but I don't really have the know how yet.

@mstroh76
Copy link
Member

mstroh76 commented Apr 2, 2024

Thanks for the issue.
I didn't even know how it actually worked.

Analysis so far:
Usually /dev/mem is accessed directly, even from a non-root account.
This works for memory areas intended for mapped device address areas. However, only if this was activated in the kernel (compiler option).

If this is not possible WiringPi use /dev/gpiomem (kernel module). However, the addresses for PWM are not available on that memory (only GPIO)! That's why PWM doesn't work. pinMode PWM: Unable to do this when using /dev/gpiomem

Actions:
I will add an additional detection in the next version so that it is clear whether /dev/mem or /devgpiomem is used.
I will retext the error message so that it is clear why the error occurs.
We will do further tests with Ubuntu (I suspect this is where the problem occurs, because of Kernel settings)

Solution:
So the solution for you is to ensure that a normal user can access /dev/mem (device addresses).
You may need a new kernel for this.

Please keep me updated if you were able to solve the problem.

@mstroh76
Copy link
Member

report for analysis finished #221

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants