1

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?

1
  • Ordinarily this would be done in the device tree via /boot/config.txt - or in raspi-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.
    – Seamus
    Commented Jan 28, 2022 at 14:24

1 Answer 1

0

First of all, the errors shown in the OP with sudo pip3 install spidev can be easily resolved by installing the missing linux-headers (sudo apk add linux-headers), but this doesn't resolve the underlying problems here.

I've asked around on multiple platforms and apparently I ran into some unresolved issues with the kernel build process for the RPi aarch64 images and some other questionable design issues.

I'm far from proficient in this area, but apparently some kernel modules, including SPI(-support?) are built for the aarch64 kernel image, but are not included. The developer channel has been informed about this and I reckon they'll look into this. This would mean, that my issue could be resolved by changing to the armv7 or armhf images, as the build process includes the kernel modules for those. From what I've gathered, the linux-rpi4 apk package should also include the required kernel modules - so I assume things would be different on a Raspberry Pi 4.

Furthermore, Alpine Linux uses the 5.15.x kernel for the RPi images, which is currently not officially supported by the Raspberry Foundation and in the Beta. This could result in problems originating from the kernel version chosen by the Alpine Linux team on Raspberry Pies.

I'm not sure if any of the identified issues will be addressed and corrected by the Alpine Linux team, but I hope that the support and compatibility for RPi will grow in future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.