That's the section heading on page 302 of Derek Molloy's second edition "Exploring Beaglebone"
I found the section lacking in information on exactly how to do this. A web search showed up the following pages.
https://github.com/adafruit/adafruit-beaglebone-io-python/issues/137
https://linuxize.com/post/how-to-add-user-to-group-in-linux/
https://github.com/cnobile2012/RobotControl/tree/master/contrib
I'm still not sure of the actual process with this revision of the OS.
debian@ebb:~/lazarus$ uname -a
Linux ebb 4.14.108-ti-r136 #1stretch SMP PREEMPT Mon Jun 8 15:38:30 UTC 2020 armv7l GNU/Linux
Robert Nelson mentions 4.11+ as having support for "it" so is any of what is in the first link needed?
"it's created after you export 0 (or 1) in the pwm system node. only v4.11.x+ has the udev patch for permissions. (didn't want to break older userspace, we still need to fix bonescript before i backport that patch to v4.4.x/v4.9.x)"
I don't have a
/etc/udev/rules.d/80-gpio-permissions.rules
So I'm thinking I do have to create that file with
KERNEL=="gpio*", SUBSYSTEM=="gpio", ACTION=="add", PROGRAM="/usr/local/bin/udev-gpio-permissions.sh"
And then create the shell script as outlined but with user debian in group gpio?
Eg:
chown -R nick:digital /sys/devices/gpio
becomes
chown -R debian:gpio /sys/devices/gpio
That's where it starts to fall apart for me as far as instructions go. There's an assumption of knowledge about something except I don't know what that is.
debian@ebb:~/lazarus$ ls -al /etc/udev/rules.d/
total 84
drwxr-xr-x 2 root root 4096 Apr 24 17:05 .
drwxr-xr-x 4 root root 4096 Jul 14 2020 ..
-rw-r--r-- 1 root root 372 Jul 10 2020 10-of-symlink.rules
-rw-r--r-- 1 root root 48 Oct 7 2018 50-hidraw.rules
-rw-r--r-- 1 root root 44 Oct 7 2018 50-spi.rules
-rw-r--r-- 1 root root 142 Oct 7 2018 60-omap-tty.rules
-rw-r--r-- 1 root root 921 Jul 10 2020 80-eeprom-noroot.rules
-rw-r--r-- 1 root root 569 Feb 25 06:10 80-gpio-noroot.rules
-rw-r--r-- 1 root root 308 Feb 25 06:10 80-i2c-noroot.rules
-rw-r--r-- 1 root root 2113 Feb 25 06:10 81-pwm-noroot.rules
-rw-r--r-- 1 root root 339 Feb 1 2019 82-gpio-config-pin.rules
-rw-r--r-- 1 root root 359 Jul 10 2020 83-eqep-noroot.rules
-rw-r--r-- 1 root root 509 Aug 15 2018 84-gpio-noroot.rules
-rw-r--r-- 1 root root 188 Aug 15 2018 85-gpio-noroot.rules
-rw-r--r-- 1 root root 1414 Jul 10 2020 86-remoteproc-noroot.rules
-rw-r--r-- 1 root root 352 Jul 10 2020 86-rpmsg-noroot.rules
-rw-r--r-- 1 root root 218 Jul 10 2020 87-iio-noroot.rules
-rw-r--r-- 1 root root 308 Feb 25 06:10 88-leds-noroot.rules
-rw-r--r-- 1 root root 855 Oct 7 2018 beagle-tester.rules
-rw-r--r-- 1 root root 97 Oct 7 2018 tisdk.rules
-rw-r--r-- 1 root root 108 Oct 7 2018 uio.rules
debian@ebb:~/lazarus$
From
debian@ebb:~/lazarus$ more /etc/group
I get:
gpio:x:999:debian,node-red,john
What else is required so I don't have to use sudo for C, Lazarus or python programs to access GPIO?
debian@ebb:~/lazarus$ cat /etc/udev/rules.d/80-gpio-noroot.rules
# /etc/udev/rules.d/80-gpio-noroot.rules
#
# Stolen from Pi: https://github.com/RPi-Distro/raspberrypi-sys-mods/blob/master/etc.armhf/udev/rules.d/99-com.rules#L9-L14
#
SUBSYSTEM=="gpio", GROUP="gpio", MODE="0660"
SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c '\
chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio;\
chown -R root:gpio /sys/class/gpio/*export && chmod -R 220 /sys/class/gpio/*export;\
chown -R root:gpio /sys/devices/virtual/gpio && chmod -R 770 /sys/devices/virtual/gpio;\
chown -R root:gpio /sys$devpath && chmod -R 770 /sys$devpath\
'"
Or is it all as simple as this which is 7 years old:
https://github.com/cnobile2012/RobotControl/tree/master/contrib
Trouble with the read me here is that it doesn't show what the end result should look like and I already have the 80-gpio-noroot.rules file.
Very confused…
John
Thanks.
It's easy enough of course to sudo user_program and then enter password to run it but a pain. Perhaps this will fix that issue
But the more important issue is whether I can get the Lazarus IDE along with the debugger (separate program I believe) to run elevated as super user.
I need to be able to set break points and look at parameters before the system calls for sending data to the SPI port. But since the code doesn't make it past the gpio48 and gpio60 control (due to permissions) I don't even get a chance to see if the parameters are correctly formed for the system call.
If the attached zip comes through you can see a simple program that just toggles gpio48 attached to an LED. The memo component shows the results of the calls to the create/open/close links for the gpio access. This small application is the test for reconfiguring the debian user to be part of the gpio group for access. And once it runs from the command line or from the IDE without sudo then I know I've succeeded in that part.
It's likely the same issue is happening with access to the SPI1.0 although you'd think running the bigger program that does SPI access elevated with sudo wouldn't have that problem.
To try this program do sudo apt install lazarus.
John
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/12eed06d-2d12-402a-a82f-0ca2603d4a8fn%40googlegroups.com.
Hi Dennis,
I've got a pretty stable pxl gpio library working now.
Here is the original ExportPin function with the problem you identified where the OS needs time to create the files but fails when it tries to write out.
procedure TSysfsGPIO.ExportPin(const Pin: TPinIdentifier);
begin
TryWriteTextToFile(FExportFileName, IntToStr(Pin));
SetPinBit(Pin, ExportedBitmask);
end;
A bit of a mystery in how it works other than it creates an OS fault to signal issues. My new function is more complicated:
{
The ExportPin procedure has been expanded to test to see if it is already
exported. If it was already there then a new bit flag is set so that when
the application calls to unexport pins, the ones that were there are left alone.
}
procedure TSysfsGPIO.ExportPin(const Pin: TPinIdentifier);
var val : StdChar;
begin
// First check to see if we already exported this pin inside this application.
if (not IsPinBitSet(Pin, ExportedBitmask)) then begin
// Check to see if the pin was set before program started by reading from it.
// If the read fails then the /sys/class/gpio/gpio__ folder does not exist.
if (TryReadCharFromFile(FAccessFileName + IntToStr(Pin) + '/direction',val)) then begin
// It's already exported and folder exists so don't bother trying again.
SetPinBit(Pin, ExportDefinedBitmask); // Set that it was already exported on start
SetPinBit(Pin, ExportedBitmask); // and that it's exported.
end
else begin // File didn't exist
// Wasn't exported when program started so now let's export it.
if TryWriteTextToFile(FExportFileName, IntToStr(Pin)) then
SetPinBit(Pin, ExportedBitmask);
end;
end;
end;
The only problem with the above procedure is that it's not a function that returns a successful or not successful export. So we don't know if the pin was actually exported yet.
So where does the delay suggestion you made come in? When we try and set the direction of the pin! Which is done in the user application.
// Switch LED pin for output.
GPIO.PinMode[PinLED] := TPinMode.Output;
The delay is not done in the original but should come after the call to export it or ExportPin needs to be changed to a function and the delay done there. Here's the original.
procedure TSysfsGPIO.SetPinMode(const Pin: TPinIdentifier; const Mode: TPinMode);
begin
if Pin > MaximumSupportedPins then
raise EGPIOInvalidPin.Create(Format(SGPIOSpecifiedPinInvalid, [Pin]));
if not IsPinExported(Pin) then
ExportPin(Pin);
if Mode = TPinMode.Input then
begin
WriteTextToFile(FAccessFileName + IntToStr(Pin) + '/direction', 'in');
ClearPinBit(Pin, DirectionBitmask);
end
else
begin
WriteTextToFile(FAccessFileName + IntToStr(Pin) + '/direction', 'out');
SetPinBit(Pin, DirectionBitmask);
end;
SetPinBit(Pin, DirectionDefinedBitmask);
end;
Instead I've done as you suggested but let the program try with short intervals.
{
When we try and set the pin mode we first test to see if the pin was exported.
When the program first runs we don't know yet if it existed as exported but after
that even if the pin mode is set again we will know because of the new alreadyexportedflag
and the exported flag.
}
procedure TSysfsGPIO.SetPinMode(const Pin: TPinIdentifier; const Mode: TPinMode);
var
escapeCounter : integer;
begin
if Pin > MaximumSupportedPins then
raise EGPIOInvalidPin.Create(Format(SGPIOSpecifiedPinInvalid, [Pin]));
if not IsPinExported(Pin) then begin // First time we don't know if the pin was already exported.
ExportPin(Pin); // So we have to try which will set the proper flags.
if not IsPinAlreadyExported(Pin) then begin // If it wasn't already exported then wait to see if it now is.
escapeCounter := 10; // Wait 5 seconds max for OS to create file structure.
repeat
Sleep(500); // Let the OS have time to create the files.
if (TryReadCharFromFile(FAccessFileName + IntToStr(Pin) + '/direction',val)) then
escapeCounter := 0
else
dec(escapeCounter);
until escapeCounter <= 0;
end;
end;
// Finally set the direction.
if Mode = TPinMode.Input then
begin
WriteTextToFile(FAccessFileName + IntToStr(Pin) + '/direction', 'in');
ClearPinBit(Pin, DirectionBitmask);
end
else
begin
WriteTextToFile(FAccessFileName + IntToStr(Pin) + '/direction', 'out');
SetPinBit(Pin, DirectionBitmask);
end;
SetPinBit(Pin, DirectionDefinedBitmask);
end;
The only issue I've run into is the repeat until loop. Seems like the file is readable in about 100mS but fails with the write unless the delay is 500mS.
John
> -----Original Message-----
> From: beagl...@googlegroups.com [mailto:beagl...@googlegroups.com] On Behalf Of Dennis Lee Bieber
> Sent: May-12-21 9:24 AM
> To: Beagleboard
> Subject: [beagleboard] Re: Using GPIOs without Using sudo
>
> On Tue, 11 May 2021 18:51:22 -0700, in gmane.comp.hardware.beagleboard.user
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit