Open noanight opened 2 years ago
Confirmed: https://github.com/raspberrypi/linux/commit/bdfc988
This was removed with RPi Linux 4.3 already, spi-bcm2835
is available instead.
The same is true for I2C: While the module is still available, it is deprecated in favour of i2c-bcm2835
: https://forums.raspberrypi.com/viewtopic.php?t=133024
PR up to fix this: #5
I think the loadModule and unloadModule Functions, calling modprobe, should be removed, because it's outdated. The Kernel uses device tree.
About the failing assert...
SPI_CS_HIGH Flag is always set when reading the SPI mode...though the assertion fails.
According to https://github.com/raspberrypi/linux/issues/3745
_CS_HIGH handling has changed between 4.19 and 5.4 - the SPI framework forces CS_HIGH then leaves it up to the GPIO layer to handle the ACTIVE_LOW semantics. I don't like the change because it is (ab)using user-facing flags - CS_HIGH no longer means what you think it means. The attitude upstream (and I may be missing some nuance here) seems to be that CS_HIGH is a bus property rather than a device property - if you have to wait until an application starts to reverse the polarity of one of the CS pins then the device has possibly already been responding to and interfering with devices on other CS lines from the same controller.
In short - dropping the device.cshigh = False line not only makes it work but is the right thing to do. Under other circumstances this kernel change might have broken other aspects of the py-spidev library, but I think the fact that it reads the initial value of the mode from spidev means that everything is fine unless you try to clear cshigh._
https://github.com/raspberrypi/linux/issues/4018 https://forums.raspberrypi.com/viewtopic.php?t=304156
Tried the C Version with the same result...SPI_CS_HIGH is set.
wget https://raw.githubusercontent.com/torvalds/linux/master/tools/spi/spidev_test.c
gcc -o spidev_test spidev_test.c
./spidev_test -D /dev/spidev0.0
sudo nano /usr/local/lib/python3.9/dist-packages/WebIOPi-0.7.1-py3.9-linux-armv6l.egg/webiopi/devices/spi.py
SPI_CS_HIGH = 0x04
# SPI_LSB_FIRST = 0x08
# SPI_3WIRE = 0x10
# SPI_LOOP = 0x20
# SPI_NO_CS = 0x40
# SPI_READY = 0x80
...
...
..
class SPI(Bus):
def __init__(self, chip=0, mode=0, bits=8, speed=0):
Bus.__init__(self, "SPI", "/dev/spidev0.%d" % chip)
self.chip = chip
val8 = array.array('B', [0])
val8[0] = mode
if fcntl.ioctl(self.fd, SPI_IOC_WR_MODE, val8):
raise Exception("Cannot write SPI Mode")
if fcntl.ioctl(self.fd, SPI_IOC_RD_MODE, val8):
raise Exception("Cannot read SPI Mode")
self.mode = struct.unpack('B', val8)[0]
self.mode &= ~SPI_CS_HIGH
assert(self.mode == mode)
Setup
WebIOPi Config
Startup log
Errors
modprobe: FATAL: Module spi-bcm2708 not found in directory /lib/modules/5.15.32+
from https://forums.raspberrypi.com/viewtopic.php?p=675658#p675658
Conclusion: so no module load required
Workaround
sudo nano /usr/local/lib/python3.9/dist-packages/WebIOPi-0.7.1-py3.9-linux-armv6l.egg/webiopi/devices/bus.py
replace spi-bcm2708 with spi-bcm2835
BUSLIST = { "I2C": {"enabled": False, "gpio": {0:"SDA", 1:"SCL", 2:"SDA", 3:"SCL"}, "modules": ["i2c-bcm2708", "i2c-dev"]}, "SPI": {"enabled": False, "gpio": {7:"CE1", 8:"CE0", 9:"MISO", 10:"MOSI", 11:"SCLK"}, "modules": ["spi-bcm2835", "spidev"]> "UART": {"enabled": False, "gpio": {14:"TX", 15:"RX"}}, "ONEWIRE": {"enabled": False, "gpio": {4:"DATA"}, "modules": ["w1-gpio"], "wait": 2} }
SPI.init(self, toint(chip), 0, 8, 10000000) File "/usr/local/lib/python3.9/dist-packages/WebIOPi-0.7.1-py3.9-linux-armv6l.egg/webiopi/devices/spi.py", line 98, in init assert(self.mode == mode)
Workaround