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
  • 3
    Get rid of the pastebin which serves no purpose other than to irritate readers. Put the text in your question. Other than that niggle this is a good question. – joan Sep 27 '21 at 15:20
  • @joan thank you for the feedback putting the whole error code here would be a bit much i think unless there is a way to fold / hide it, but i want able to find how – Ruben Sep 27 '21 at 15:48
  • So are you using AdaFruit software which is not not 100% compatible to Rpi OS? – tlfong01 Sep 28 '21 at 00:58
  • 1
    @tlfong01 no, i would prefer if it was 100% "normal" python and not circuitpython, i just noticed i typed busio wrong, trying busio was just to rule out a bug in the spidev library and i wasn't able to find an other spi library – Ruben Sep 28 '21 at 07:40
  • Well, Rpi4B buster "normal" python has SPI "built in". If you are using third party SPI libraries, AdaFruit or otherwise, you are asking for trouble. I learnt my lesson after wasting some one hundred hours trying to fix compatibility. – tlfong01 Sep 28 '21 at 08:11
  • I did once try to be greedy and use 5 spi ports at the same time, but found unreliable results. And my lesson learnt is try to be humble and stick to 2 or at more 3 spi ports, and avoid spi 3, 4, 5 if possible. My answer to the following outdated question might help: https://raspberrypi.stackexchange.com/questions/100237/fluctuating-sclk-voltage-with-increase-in-frequency. – tlfong01 Sep 28 '21 at 08:21

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
  • 27,928
  • 6
  • 53
  • 144