5

intro

i want to use multiple SPI busses at the same time.
but when i use to use SPI 4 and SPI 5 at the same time it crashes the whole system
it doesn't crash instantly sometimes it takes 10 seconds sometimes 10 minutes

it works fine if i use any other combination with spi 0,1,4,5
and it only crashes when 4 and 5 are used at the same time

the code

#! /usr/bin/env python3
import random
import spidev

spi = spidev.SpiDev() spi.open(5, 0) spi.max_speed_hz = 1500000 spi.mode = 0 data = [0]*120 while True: spi.writebytes(data) spi.close()

when looking for the source of the bug i reduced the code to its minimum
to produce the error i run it in 2 separate terminals
in one terminal i use spi.open(5, 0) and the other spi.open(4, 0) the rest of the code is the same

the error

https://pastebin.com/We8C0t0N
the raspberry pi is working headless, i run the code and receive the error through ssh
i think ssh crashes before the whole error is transmitted so sometimes the error is shorter, i put the longest version on pastebin
when i connect a monitor to the pi it shows the same message but its scrolling past very fast and i cant scroll back

i have tried

  1. using a different raspberry pi 4
  2. replacing the spidev with busio and similar code
  3. enabling spi using the command line dtoverlay spi5-1cs or by adding dtoverlay=spi5-1cs to /boot/config.txt
  4. using these functions to transfer the data spi.writebytes spi.writebytes2 spi.xfer spi.xfer2 spi.xfer3
  5. changing the data data = [0]*120 or data = random.choices(range(0,255), k=120)
  6. sending 10, 120 or 4096 bytes
  7. setting the CPU governor to performance
  8. setting max_speed_hz to 1500000 or not setting it at all
Ruben
  • 51
  • 2

1 Answers1

1

From what I've heard, Linux SPI drivers are quite sensitive to CPU frequency changes, and on some systems they are plain broken if you use them together with dynamic frequency scaling. Try setting the CPU governor to performance and see if that helps.

Dmitry Grigoryev
  • 28,277
  • 6
  • 54
  • 147