I've set up Alpine on a Raspberry Pi 3B in diskless mode and it runs exceptionally smooth. I've managed to address GPIO pins (e.g. to read from temperature sensors) without much effort.
Now I'm trying to address an RFID card reader (RC522), as documented here. Now I'm not sure how to enable the SPI interface on the system, which can be done on Raspberry OS with the raspi-config
tool.
I'm assuming I somehow have to load the spi_bcm2835
kernel module on Alpine, but have no clue how to achieve that.
I've added the following line in the usercfg.txt on the Alpine partition:
dtparam=spi=on
Then I run the following commands:
# I've enabled the latest-stable community repository for apk
sudo modprobe spi_bcm2835
sudo apk update
sudo apk add python3 py3-pip gcc musl-dev python3-dev
sudo python3 -m pip install --upgrade pip
sudo pip3 install spidev
sudo pip3 install mfrc522
The kernel module seems to be loaded, but not in use.
$ sudo lsmod | grep spi
spi_bcm2835 24576 0
Installing spidev
fails:
Collecting spidev
Downloading spidev-3.5.tar.gz (10 kB)
Preparing metadata (setup.py) ... done
Using legacy 'setup.py install' for spidev, since package 'wheel' is not installed.
Installing collected packages: spidev
Running setup.py install for spidev ... error
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-du52fzwb/spidev_c57b66c989df468ea4e6b88d0b83de57/setup.py'"'"'; __file__='"'"'/tmp/pip-install-du52fzwb/spidev_c57b66c989df468ea4e6b88d0b83de57/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-_1qfksf7/install-record.txt --single-version-externally-managed --compile --install-headers /usr/include/python3.9/spidev
cwd: /tmp/pip-install-du52fzwb/spidev_c57b66c989df468ea4e6b88d0b83de57/
Complete output (12 lines):
running install
running build
running build_ext
building 'spidev' extension
creating build
creating build/temp.linux-aarch64-3.9
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -g -fno-semantic-interposition -g -fno-semantic-interposition -g -fno-semantic-interposition -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/include/python3.9 -c spidev_module.c -o build/temp.linux-aarch64-3.9/spidev_module.o
spidev_module.c:33:10: fatal error: linux/spi/spidev.h: No such file or directory
33 | #include <linux/spi/spidev.h>
| ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
error: command '/usr/bin/gcc' failed with exit code 1
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-du52fzwb/spidev_c57b66c989df468ea4e6b88d0b83de57/setup.py'"'"'; __file__='"'"'/tmp/pip-install-du52fzwb/spidev_c57b66c989df468ea4e6b88d0b83de57/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-_1qfksf7/install-record.txt --single-version-externally-managed --compile --install-headers /usr/include/python3.9/spidev Check the logs for full command output.
Furthermore, I have nothing listed as/under /dev/spi*
$ uname -a
Linux name 5.15.4-0-rpi #1-Alpine SMP PREEMPT Mon Nov 22 09:13:17 UTC 2021 aarch64 Linux
How can I enable the SPI interface with Alpine 3.15.0 on a Raspberry Pi 3B to address a RC522?
/boot/config.txt
- or inraspi-config
. I have no idea how running Alpine as your OS might change that, but I tend to doubt that the advantages of Alpine over RPiOS are worth the added complications you've created for yourself. But of course this is your choice.