Renegade supports hardware SPI on the 40-pin GPIO header with the same pinout as Raspberry Pi 2/3/4 Model B/B+ boards.
- MOSI on pin 19
- MISO on pin 21
- SCLK on pin 23
- CE0 on pin 24
- CE1 on pin 26
They can be used directly with hardware drivers or exposed as /dev/spidev0.0 and /dev/spidev0.1.
If you only have 1 SPI slave device, you only need CE0 on pin 24. To activate /dev/spidev0.0, run:
sudo ldto enable spi0 spi0-spidev
If you have two SPI slave devices, you need both CE0 on pin 24 and CE1 on pin 26. To activate /dev/spidev0.0 and /dev/spidev0.1, run:
sudo ldto enable spi0-cs1 spi0-cs1-spidev
After you have tested your device(s) and confirmed that they are working, you can enable it permanently via:
sudo ldto merge spi0 spi0-spidev
#or
sudo ldto merge spi0-cs1 spi0-cs1-spidev
Reboot and it should appear those SPI devices should appear without having to run enable.
If you no longer need SPI devices after merging them, you can reset the system to default by:
sudo ldto reset
sudo reboot
Device trees are not reset to default until the machine reboots. Do not try to merge new overlays before rebooting.
How do I put data on the SPI line once it’s been enabled? I’m used to bit-banging microcontrollers, and I can’t find register names for this chip.
You can write data directly to those device files depending on which channel select you need.
Apologies for my ignorance, can you elaborate on which device files I need to write to?
/dev/spidev0.0 or /dev/spidev0.1 
1 Like
I did not realize that my armbien distro was not compatible with the library you initially referenced. I have since swapped to the recommended debian distro, installed the library to give me access to the ldto command, and ran:
sudo ldto enable spi0 spi0-spidev
However, once I navigate to the /dev
directory, I do not see the /dev/spidev0.X
files you speak of. What am I missing?
I guess I should explain my ultimate goal. I have a CPP program that will send commands over SPI to an STM32 chip, and receive status messages from the same chip (full duplex if possible). I would like to be able to use the CPP program to send and receive this data, but I don’t know how to interface with the hardware. I assume this tutorial is over interfacing with low level drivers, but I don’t know how to configure everything to my liking, or how to actually get data into or out of the SPI registers.
You don’t need to install the library. It’s already included on our images.
After the command, can you run sudo dmesg | tail -n 20
and paste the output?
Of course! I’ve run the command: sudo ldto enable spi0 spi0-spidev
and then the requested command, this is the output:
[ 57.799491] input: SIGMACHIP USB Keyboard Consumer Control as /devices/platform/ff600000.usb/xhci-hcd.0.auto/usb2/2-1/2-1:1.1/0003:1C4F:0002.0002/input/input3
[ 57.860223] input: SIGMACHIP USB Keyboard System Control as /devices/platform/ff600000.usb/xhci-hcd.0.auto/usb2/2-1/2-1:1.1/0003:1C4F:0002.0002/input/input4
[ 57.861943] hid-generic 0003:1C4F:0002.0002: input,hidraw1: USB HID v1.10 Device [SIGMACHIP USB Keyboard] on usb-xhci-hcd.0.auto-1/input1
[ 575.486259] usb 2-1: USB disconnect, device number 2
[ 1520.438535] usb 5-1: new low-speed USB device number 2 using ohci-platform
[ 1520.683749] usb 5-1: New USB device found, idVendor=1c4f, idProduct=0002, bcdDevice= 3.30
[ 1520.695092] usb 5-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 1520.706387] usb 5-1: Product: USB Keyboard
[ 1520.717622] usb 5-1: Manufacturer: SIGMACHIP
[ 1520.743902] input: SIGMACHIP USB Keyboard as /devices/platform/ff5d0000.usb/usb5/5-1/5-1:1.0/0003:1C4F:0002.0003/input/input5
[ 1520.816106] hid-generic 0003:1C4F:0002.0003: input,hidraw0: USB HID v1.10 Keyboard [SIGMACHIP USB Keyboard] on usb-ff5d0000.usb-1/input0
[ 1520.841221] input: SIGMACHIP USB Keyboard Consumer Control as /devices/platform/ff5d0000.usb/usb5/5-1/5-1:1.1/0003:1C4F:0002.0004/input/input6
[ 1520.911356] input: SIGMACHIP USB Keyboard System Control as /devices/platform/ff5d0000.usb/usb5/5-1/5-1:1.1/0003:1C4F:0002.0004/input/input7
[ 1520.932097] hid-generic 0003:1C4F:0002.0004: input,hidraw1: USB HID v1.10 Device [SIGMACHIP USB Keyboard] on usb-ff5d0000.usb-1/input1
[ 1618.412485] usb 5-1: USB disconnect, device number 2
[ 2081.722592] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /aliases/spi0
[ 2081.729125] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /spi@ff190000/status
[ 6538.550068] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /aliases/spi0
[ 6538.557601] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /spi@ff190000/status
[24332.833784] rc rc0: two consecutive events of type space
Thank you for the help!