To deal with CAN bus on the Pi3/Pi4 requires access to the SPI bus for the MCP2515. On the Beagle it's the on chip CAN device. And if I want to talk to sensors like I2C or One-Wire plus inexpensive LCD displays I need access to the hardware.
So I installed the PXL library and that's where I ran into the next roadblock. First you can't, from within the IDE and debugging, work with SPI bus without running Lazarus as root. Or it just won't work with the /sys/class/gpio folders. And that's the reason for wanting to free up access to the gpio.
The SPI bus ADAfruit application for a 320x240 display written in Python runs properly rendering LENNA.JPG onto the LCD display. The key outputs are the DC and RESET which are on gpio48 and gpio60. An "ls" of the /sys/class/gpio folder shows on start up those two are not visible.
SPI and I2C rely upon a different PINMUX configuration than GPIO...
GPIO is pretty much all "mode 7". SPI0 pins are "mode 0" and SPI1 pins are
"mode 3".
It's possible to use:
$ sudo echo 48 > /sys/class/gpio/export
Really?
debian@beaglebone:~$ sudo echo 48 > /sys/class/gpio/export
[sudo] password for debian:
echo: write error: Operation not permitted
To my knowledge, the redirection part is still done as the debian user,
only the echo is being done by sudo.
debian@beaglebone:~$ sudo su
root@beaglebone:/home/debian# echo 48 > /sys/class/gpio/export
to create the gpio48 folder and as super user the VXP library can do that but then it fails on the write to SPI.
SPI0 appears on P9_17, _18, _21, and _22 (raw GPIO # 5, 4, 3, 2, aka
gpio0_5, ...). SPI1 are on P9_28, _29, _30, _31 (raw GPIO # 113, 111, 112,
110, aka gpio3_17, _15, _16, _14).
GPIO # 48 (gpio1_16) on P9_15 has no modes for SPI.
debian@beaglebone:~$ ls -l /sys/bus/spi/devices
total 0
lrwxrwxrwx 1 root root 0 Dec 31 1999 spi0.0 ->
../../../devices/platform/ocp/48030000.spi/spi_master/spi0/spi0.0
lrwxrwxrwx 1 root root 0 Dec 31 1999 spi0.1 ->
../../../devices/platform/ocp/48030000.spi/spi_master/spi0/spi0.1
lrwxrwxrwx 1 root root 0 Dec 31 1999 spi1.0 ->
../../../devices/platform/ocp/481a0000.spi/spi_master/spi1/spi1.0
lrwxrwxrwx 1 root root 0 Dec 31 1999 spi1.1 ->
../../../devices/platform/ocp/481a0000.spi/spi_master/spi1/spi1.1
debian@beaglebone:~$
debian@beaglebone:~$ ls -l /sys/devices/platform/ocp/48030000.spi/
total 0
lrwxrwxrwx 1 root gpio 0 May 10 15:42 driver ->
../../../../bus/platform/drivers/omap2_mcspi
-rw-rw-r-- 1 root gpio 4096 May 10 15:42 driver_override
-r--r--r-- 1 root gpio 4096 May 10 15:42 modalias
lrwxrwxrwx 1 root gpio 0 May 10 15:42 of_node ->
../../../../firmware/devicetree/base/ocp/spi@48030000
drwxrwxr-x 2 root gpio 0 May 10 15:42 power
drwxrwxr-x 3 root gpio 0 May 10 15:42 spi_master
lrwxrwxrwx 1 root gpio 0 May 10 15:42 subsystem ->
../../../../bus/platform
-rw-rw-r-- 1 root gpio 4096 May 10 15:42 uevent
debian@beaglebone:~$
debian@beaglebone:~$ ls -l
/sys/devices/platform/ocp/48030000.spi/spi_master/spi0
total 0
lrwxrwxrwx 1 root gpio 0 May 10 15:42 device -> ../../../48030000.spi
lrwxrwxrwx 1 root gpio 0 May 10 15:42 of_node ->
../../../../../../firmware/devicetree/base/ocp/spi@48030000
drwxrwxr-x 2 root gpio 0 May 10 15:42 power
drwxrwxr-x 5 root gpio 0 May 10 15:42 spi0.0
drwxrwxr-x 5 root gpio 0 May 10 15:42 spi0.1
drwxrwxr-x 2 root gpio 0 May 10 15:42 statistics
lrwxrwxrwx 1 root gpio 0 May 10 15:42 subsystem ->
../../../../../../class/spi_master
-rw-rw-r-- 1 root gpio 4096 May 10 15:42 uevent
debian@beaglebone:~$
NOTE: there are two config-pin in Buster, maybe even Stretch. The one
you get if you just enter "config-pin" is a compiled executable with some
limitations (if there is no pinmux file found it objects). I'm using the
older PERL script version which has a few more capabilities.
debian@beaglebone:~$
/opt/source/bb.org-overlays/tools/beaglebone-universal-io/config-pin -i
p9_15
Pin name: P9_15
Function if no cape loaded: gpio
Function if cape loaded: default gpio gpio_pu gpio_pd gpio_input pwm
Function information: gpio1_16 default gpio1_16 gpio1_16 gpio1_16 gpio1_16
ehrpwm1_tripzone_input
Kernel GPIO id: 48
PRU GPIO id: 80
debian@beaglebone:~$
/opt/source/bb.org-overlays/tools/beaglebone-universal-io/config-pin -i
p9_17
Pin name: P9_17
Function if no cape loaded: gpio
Function if cape loaded: default gpio gpio_pu gpio_pd gpio_input spi_cs i2c
pwm pru_uart
Function information: gpio0_5 default gpio0_5 gpio0_5 gpio0_5 gpio0_5
spi0_cs0 i2c1_scl ehrpwm0_synci pru_uart
Kernel GPIO id: 5
PRU GPIO id: 37
debian@beaglebone:~$
/opt/source/bb.org-overlays/tools/beaglebone-universal-io/config-pin -q
p9_15
P9_15 Mode: default Direction: in Value: 1
debian@beaglebone:~$
/opt/source/bb.org-overlays/tools/beaglebone-universal-io/config-pin -q
p9_17
P9_17 Mode: default Direction: in Value: 1
debian@beaglebone:~$
/opt/source/bb.org-overlays/tools/beaglebone-universal-io/config-pin -l
p9_15
default gpio gpio_pu gpio_pd gpio_input pwm
debian@beaglebone:~$
/opt/source/bb.org-overlays/tools/beaglebone-universal-io/config-pin -l
p9_17
default gpio gpio_pu gpio_pd gpio_input spi_cs i2c pwm pru_uart
debian@beaglebone:~$
=============================================================================
debian@ebb:~/lazarus/pxl/Samples/FreePascal/SingleBoard/Generic/DisplaySPI$ sudo ./DisplaySPI
[sudo] password for debian:
An unhandled exception occurred at $00032BB0:
ESysfsSPITransfer: Cannot transfer <1> data byte(s) through SPI bus.
$00032BB0 TSYSFSSPI__TRANSFER, line 247 of /home/debian/lazarus/pxl/Source/PXL.Sysfs.SPI.pas
$00032AC4 TSYSFSSPI__WRITE, line 228 of /home/debian/lazarus/pxl/Source/PXL.Sysfs.SPI.pas
Since you haven't shown the code, I don't know what pins that call is
attempting to access. Especially as you earlier mention gpio 48 -- which
from what I can tell does not have SPI features. For the others, you may
need to pin-mux to activate SPI -- the default may be for them to be GPIO..
debian@beaglebone:~$
/opt/source/bb.org-overlays/tools/beaglebone-universal-io/config-pin p9_17
spi_cs
debian@beaglebone:~$
/opt/source/bb.org-overlays/tools/beaglebone-universal-io/config-pin p9_18
spi
debian@beaglebone:~$
/opt/source/bb.org-overlays/tools/beaglebone-universal-io/config-pin p9_22
spi_sclk
debian@beaglebone:~$
/opt/source/bb.org-overlays/tools/beaglebone-universal-io/config-pin -q
p9_18
P9_18 Mode: spi
debian@beaglebone:~$
Using the other SPI device is trickier -- I believe a device tree
overlay needs to be specified in /boot/uEnv.txt. Config-pin fails
debian@beaglebone:~$
/opt/source/bb.org-overlays/tools/beaglebone-universal-io/config-pin p9_31
spi_sclk
P9_31 pinmux file not found!
bash: /sys/devices/platform/ocp/ocp*P9_31_pinmux/state: No such file or
directory
Cannot write pinmux file: /sys/devices/platform/ocp/ocp*P9_31_pinmux/state
debian@beaglebone:~$ ls /opt/source/bb.org-overlays/src/arm/BB*SPI*
/opt/source/bb.org-overlays/src/arm/BBBLUE-GP0-SPI-00A0.dts
/opt/source/bb.org-overlays/src/arm/BB-LCD-ADAFRUIT-18-SPI1-00A0.dts
/opt/source/bb.org-overlays/src/arm/BB-SPI0-ADS8688-0A00.dts
/opt/source/bb.org-overlays/src/arm/BB-SPI0-AT86RF233-00A0.dts
/opt/source/bb.org-overlays/src/arm/BB-SPI0-MCP23S08-00A0.dts
/opt/source/bb.org-overlays/src/arm/BB-SPI0-MCP3008-00A0.dts
/opt/source/bb.org-overlays/src/arm/BB-SPIDEV0-00A0.dts
/opt/source/bb.org-overlays/src/arm/BB-SPIDEV1-00A0.dts