Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » pinMode PWM: Unable to do this when using /dev/gpiomem. Try sudo?(Remote debugging c+ application with wiringPi on a raspberry zero )
pinMode PWM: Unable to do this when using /dev/gpiomem. Try sudo? [message #1852166] Tue, 03 May 2022 10:15 Go to next message
Kurt Struevy is currently offline Kurt StruevyFriend
Messages: 45
Registered: May 2016
Member
Hello,
since several weeks I try to find any solution for my problem.
I created an application using eclipse 2022-03 CDT. It works perfect!
a big compliment to the designers of eclipse.
After some time I got eclips running on a Windows machine using a toolchain for a raspberry pi.
Debugging for remote application works perfect.
But when I try to run an application where I use wiringpi then I get a problem where I havn't find any solution at all.
I use this code :
	pinMode(motor_l_u, OUTPUT);
	pinMode(motor_l_v, OUTPUT);
	pinMode(motor_r_u, OUTPUT);
	pinMode(motor_r_v, OUTPUT);
       .....
	pinMode(motor_l_u, PWM_OUTPUT);
	pinMode(motor_l_v, PWM_OUTPUT);
	pinMode(motor_r_u, PWM_OUTPUT);
	pinMode(motor_r_v, PWM_OUTPUT);

Executing the first lines makes no problem.
But when I to try execute the lines
	pinMode(motor_l_u, PWM_OUTPUT);
	pinMode(motor_l_v, PWM_OUTPUT);
	pinMode(motor_r_u, PWM_OUTPUT);
	pinMode(motor_r_v, PWM_OUTPUT);
I get this error:
pinMode PWM: Unable to do this when using /dev/gpiomem. Try sudo?
Child exited with status 1
logout

Sometimes I think there is no way to debug such a programm when it needs wiringPi.
When I run the application on a console as normal user I get the same error.
When I run this application on a console typing
 sudo MyApp
then it works.
Is there really no solution available?
I'm almost very frustrated because eclipse is a wonderfull IDE but without debugging such an appliation it's not usefull.
Kurt
Re: pinMode PWM: Unable to do this when using /dev/gpiomem. Try sudo? [message #1852173 is a reply to message #1852166] Tue, 03 May 2022 14:41 Go to previous messageGo to next message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 742
Registered: August 2014
Senior Member
You have to add your user to gpio group, then log out and log in again.

--

Tauno Voipio
Re: pinMode PWM: Unable to do this when using /dev/gpiomem. Try sudo? [message #1852174 is a reply to message #1852173] Tue, 03 May 2022 16:01 Go to previous messageGo to next message
Kurt Struevy is currently offline Kurt StruevyFriend
Messages: 45
Registered: May 2016
Member
Hallo Tauno Voibio,
thanks for your quick replay!
No it's not necessary to
add your user to gpio group

I found a working solution:

  1. create a script (e.G.: gdbscript) on the raspberry with the content
    #! /bin/bash
    #
    sudo gdbserver $*

  2. store it
  3. mak it executable
    chmod +x gdbscript

  4. on eclipse modify

      Debug Configurations ...
    1. tab: -->Debugger
    2. tab: ----> Gdbserver Settings
    3. tab ------> in Gdbserver path write:
      /home/raspi/gdbscript


the result is:
Last login: Tue May  3 18:08:32 2022 from 192.168.180.38

/home/raspi/gdbscript  :2345 /home/raspi/Eclipse/RoboCar;exit

raspi@raspberrypi:~$ /home/raspi/gdbscript  :2345 /home/raspi/Eclipse/RoboCar;exit
Process /home/raspi/Eclipse/RoboCar created; pid = 4686
Listening on port 2345
Remote debugging from host 192.168.180.38

see attached picture
that should work.

[Updated on: Tue, 03 May 2022 16:23]

Report message to a moderator

Re: pinMode PWM: Unable to do this when using /dev/gpiomem. Try sudo? [message #1852176 is a reply to message #1852174] Tue, 03 May 2022 16:43 Go to previous messageGo to next message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 742
Registered: August 2014
Senior Member
Your solution is to run the target as root, which is not secure. Adding the user to the gpio group is sufficient for running wiringPi, so the target code does not have other unnecessary superuser powers.

--

Tauno Voipio
Re: pinMode PWM: Unable to do this when using /dev/gpiomem. Try sudo? [message #1852193 is a reply to message #1852176] Wed, 04 May 2022 13:40 Go to previous messageGo to next message
Kurt Struevy is currently offline Kurt StruevyFriend
Messages: 45
Registered: May 2016
Member
Hi Tauno Voipio,
thanks for your answer.
Yes I did it but it doesn't work.
raspi@raspberrypi:~ $ sudo adduser raspi gpio
The user `raspi' is already a member of `gpio'.
raspi@raspberrypi:~ $ cd Eclipse/
raspi@raspberrypi:~/Eclipse $ ./RoboCar
Hello World

init Wiringppi !!

init ist OK!!
+++++++++++++
pinMode PWM: Unable to do this when using /dev/gpiomem. Try sudo?


I think it's not a real security problem if I do it with my private application which runs only on a restricted area.
Kurt
Re: pinMode PWM: Unable to do this when using /dev/gpiomem. Try sudo? [message #1852203 is a reply to message #1852193] Wed, 04 May 2022 18:26 Go to previous messageGo to next message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 742
Registered: August 2014
Senior Member
What does ls -l /dev/gpiomem show?


--

Tauno Voipio
Re: pinMode PWM: Unable to do this when using /dev/gpiomem. Try sudo? [message #1852221 is a reply to message #1852203] Thu, 05 May 2022 08:57 Go to previous messageGo to next message
Kurt Struevy is currently offline Kurt StruevyFriend
Messages: 45
Registered: May 2016
Member
Hi Tauno Voipio,
the output shows:
ls -la /dev/gpiomem
crw-rw---- 1 root gpio 246, 0 May  4 18:17 /dev/gpiomem

[Updated on: Thu, 05 May 2022 08:59]

Report message to a moderator

Re: pinMode PWM: Unable to do this when using /dev/gpiomem. Try sudo? [message #1852222 is a reply to message #1852221] Thu, 05 May 2022 08:57 Go to previous messageGo to next message
Kurt Struevy is currently offline Kurt StruevyFriend
Messages: 45
Registered: May 2016
Member
No Message Body
Re: pinMode PWM: Unable to do this when using /dev/gpiomem. Try sudo? [message #1852238 is a reply to message #1852221] Thu, 05 May 2022 16:01 Go to previous messageGo to next message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 742
Registered: August 2014
Senior Member
That seems fine.

Can you run the test binary from Raspberry console?

Are you sure that the target binary is owned by the user in gpio group?

I did run a wiringPi test on my Raspberry 3b and it runs fine.


--

Tauno Voipio
Re: pinMode PWM: Unable to do this when using /dev/gpiomem. Try sudo? [message #1852255 is a reply to message #1852238] Fri, 06 May 2022 09:34 Go to previous messageGo to next message
Kurt Struevy is currently offline Kurt StruevyFriend
Messages: 45
Registered: May 2016
Member
Hi Tauno Voipio,
yes I checked this.
raspi@raspberrypi:~/Eclipse $ groups raspi
raspi : raspi adm dialout cdrom sudo audio video plugdev games users input netdev spi i2c gpio lpadmin
raspi@raspberrypi:~/Eclipse $ ./TestMotorProgramm
pinMode PWM: Unable to do this when using /dev/gpiomem. Try sudo?
raspi@raspberrypi:~/Eclipse $ sudo ./TestMotorProgramm
====> Vorwaerts mit Tempo =1023
====> Vorwaerts mit Tempo =1022

I use this image
Linux raspberrypi 5.10.17+ #1414 Fri Apr 30 13:16:27 BST 2021 armv6l GNU/Linux

Isn't it crazy?
Re: pinMode PWM: Unable to do this when using /dev/gpiomem. Try sudo? [message #1852422 is a reply to message #1852255] Mon, 16 May 2022 07:04 Go to previous messageGo to next message
Emmanuel Torres is currently offline Emmanuel TorresFriend
Messages: 1
Registered: May 2022
Junior Member
Hi Kurt,

I am facing the same issue! Did you find a solution??
Re: pinMode PWM: Unable to do this when using /dev/gpiomem. Try sudo? [message #1852537 is a reply to message #1852422] Sun, 22 May 2022 10:36 Go to previous messageGo to next message
Kurt Struevy is currently offline Kurt StruevyFriend
Messages: 45
Registered: May 2016
Member
No Message Body

[Updated on: Sun, 22 May 2022 10:39]

Report message to a moderator

Re: pinMode PWM: Unable to do this when using /dev/gpiomem. Try sudo? [message #1852538 is a reply to message #1852537] Sun, 22 May 2022 10:38 Go to previous messageGo to next message
Kurt Struevy is currently offline Kurt StruevyFriend
Messages: 45
Registered: May 2016
Member
Hi Emmanuel Torres
No this is the only solution which I found.
Re: pinMode PWM: Unable to do this when using /dev/gpiomem. Try sudo? [message #1853042 is a reply to message #1852166] Wed, 15 June 2022 15:37 Go to previous message
Johnny Bravo is currently offline Johnny BravoFriend
Messages: 2
Registered: June 2022
Location: United States
Junior Member
Same issue... Can't find the solution. If you come across anything, please mention it here.

Previous Topic:Illegal virtual folder names?
Next Topic:Making a GUI
Goto Forum:
  


Current Time: Thu Apr 18 08:46:13 GMT 2024

Powered by FUDForum. Page generated in 0.02319 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top