Would be nice if you support me: https://buymeacoffee.com/bmks — thank you very much!!
Important: Use at your own risk. You, the device owner, are responsible for any damage, data loss, or bricked devices.
Creates multiple virtual device nodes (e.g. /dev/spi-bridge<BUS>.<0..N-1>) that serialize and queue SPI operations.
By default all virtual nodes use one backing SPI device (for strict single-device arbitration), and optionally each virtual index can map to its own chip-select.
sudo apt-get update
sudo apt-get install -y \
build-essential \
dkms \
kmod \
debhelper \
devscriptsKernel headers are required for DKMS builds:
sudo apt-get install -y raspberrypi-kernel-headerssudo apt-get install -y linux-headers-$(uname -r)From the project root:
./build-deb.shArtifacts are written to the parent directory.
sudo dpkg -i ../spi-bridge_1.1-1_all.debEdit:
/etc/spi-bridge/bridge.conf
Example:
BACKING=/dev/spidev0.0
NDEV=6
DEVNAME=spi-bridge
BUS=0
TIMEOUT_MS=30000
PER_MINOR_BACKING=0
OWNER_HOLD_MS=5Use this when app1 and app2 should both talk to the same slave via different virtual nodes:
BACKING=/dev/spidev0.0
BUS=0
NDEV=4
PER_MINOR_BACKING=0
OWNER_HOLD_MS=5Then run app1 on /dev/spi-bridge0.1 and app2 on /dev/spi-bridge0.2.
OWNER_HOLD_MS=0: pure FIFO switching on every operationOWNER_HOLD_MS=5..20: reduces harmful interleaving between clients on the same slave- increase
OWNER_HOLD_MSif two clients still disturb each other
Apply:
sudo systemctl restart spi-bridge.serviceIf you want /dev/spi-bridge0.1 and /dev/spi-bridge0.2 to target different chip-selects, set:
BUS=0
PER_MINOR_BACKING=1Then mappings are:
/dev/spi-bridge0.0->/dev/spidev0.0/dev/spi-bridge0.1->/dev/spidev0.1/dev/spi-bridge0.2->/dev/spidev0.2
Use this only when those are truly different chip-select devices.
ls -l /dev/spi-bridge*.*
lsmod | grep spibridge
dmesg | tail -n 50Devices are owned by group spi (created on install). Add your user:
sudo usermod -aG spi $USER
newgrp spiEach operation (read, write, ioctl) enters a strict FIFO ticket queue.
Only the current ticket may execute against the backing /dev/spidevX.Y.
This prevents collisions and interleaving at the SPI-device level.
With OWNER_HOLD_MS > 0, the active client gets a short temporary ownership window.
This keeps short request bursts together and improves stability for stateful protocols on one shared slave.
- Ensure shared mode is enabled:
PER_MINOR_BACKING=0
BACKING=/dev/spidev0.0- Start with:
OWNER_HOLD_MS=5- If unstable, try
OWNER_HOLD_MS=10or20. - If startup appears blocked, temporarily set
OWNER_HOLD_MS=0and compare behavior. - Restart service after each change:
sudo systemctl restart spi-bridge.service- Verify current settings and module state:
cat /etc/spi-bridge/bridge.conf
lsmod | grep spibridge
dmesg --ctime | tail -n 100sudo apt-get remove spi-bridge
sudo apt-get purge spi-bridge