You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
spidev transfer timeout on Pi 5 with transfers > 64. #6020
I am writing some code in c and am having spidev timeouts on the Pi 5. The same code runs fine on the Pi 4. The first spidev transfer is fine, but subsequent transfers result in timeout errors (despite it successfully transferring), which produces a much slower transfer.
Steps to reproduce the behaviour
Install Adafruit Snake Eyes Bonnet
Install Raspberry Pi OS 64-bit bookworm Desktop on the Pi 5
These message repeat in dmesg:
[ 1829.452018] spidev spi0.0: DMA transaction timed out
[ 1829.452018] spidev spi1.2: DMA transaction timed out
[ 1829.452022] spidev spi0.0: SPI transfer failed: -110
[ 1829.452024] spidev spi1.2: SPI transfer failed: -110
[ 1829.452035] spi_master spi0: failed to transfer one message from queue
[ 1829.452035] spi_master spi1: failed to transfer one message from queue
[ 1829.452037] spi_master spi1: noqueue transfer failed
[ 1829.452038] spi_master spi0: noqueue transfer failed
Additional context
Not 100% sure my code is not the issue, but kind of odd it works fine on Pi 4, but not Pi 5.
I think this is caused by a bug in the DMA driver that causes the interrupt-enable bit to be cleared. It is caused by a lack of atomicity, and triggered by having transfers submitted on multiple channels simultaneously.
#6044 should be a fix. By the time you read this (a.k.a. any time after 10:40 GMT on the 15th) you'll be able to install a 6.6 kernel with the fix by running sudo rpi-update pulls/6044.
Ok, after further testing, I think it's not quite working correctly. I am trying to use both spidev0.0 and spidev1.2 in my code. With the update, the clock signal from spidev1.2 doesn't seem to be working anymore. Like there's tons of activity on MOSI, but SCLK is barely pulsing.
The SPI controllers are clocked off clk_sys (200MHz), using an even divisor. This means that your request for 80MHz actually translates to 50MHz. You would have had more flexibility on Pi 4 where the clock is an even divisor of the VPU/core clock, but there the core clock is prone to changing with the ARM clock.
With some combinations of transmits and receives I get RX FIFO overflows:
$ dmesg -l err
[12461.687616] dma dma2chan3: dma2chan3 is non-idle!
[12461.889989] spidev spi1.2: DMA transaction timed out
[12461.889993] spidev spi1.2: SPI transfer failed: -110
[12461.890003] spi_master spi1: failed to transfer one message from queue
[12461.890006] spi_master spi1: noqueue transfer failed
Hmm, ok. I tried 50MHz and it didn't change anything.
Yes, because you've been running it at 50MHz all along. In fact, looking at logic analyser trace it's only driving SCLK half the time, so there's an effective rate of 25MHz.
No error messages at all. It just doesn't work.
At this point it might be best if you put together a cut-down test program that demonstrates the issue.
Thanks for that, Melissa. Running it on Pi 4 and Pi 5 the only differences I see are in the timing - Pi 4 runs the bus at 62.5MHz, Pi 5 at 50MHz - and that Pi 5 holds MOSI at the previous value between bytes while Pi 4 returns it to low. Other than that, the traces look the same, with SPI0.0 getting about 112KB of data first, followed by SPI1.2.
Here's Pi 4:
And Pi 5:
So it sounds like my Pi 5 is not showing the same behaviour as yours. Yes there is no hardware attached, but it's all transmit-only so it shouldn't matter unless some external load/pull is interfering.
Ok, I'll take another look. Starting from a fresh SD might fix it. Also, I could try a second Pi 5 I have to see if it's just one of my Pis misbehaving.
In case you find that things are still failing, another option is to run the SPI interfaces without DMA. If you replace the standard Pi 5 dtb file (in /boot/firmware) with this one (https://drive.google.com/file/d/1NGJsJoeFf_K8mVi0lNjO6FIPEOYj9lvf/view?usp=drive_link) you'll gain a new dtparam - nospidma, which does what you would expect.
Activity
makermelissa commentedon Mar 8, 2024
This may be a duplicate of #5858.
makermelissa commentedon Mar 8, 2024
Setting transfers to 64 bytes or less fixes the timeout issue, but still quite slow.
makermelissa commentedon Mar 8, 2024
Perhaps #5696 has popped back up or maybe it's not part of the regular release cycle yet.
[-]spidev transfer timeout on Pi 5[/-][+]spidev transfer timeout on Pi 5 with transfers > 64.[/+]pelwell commentedon Mar 15, 2024
I think this is caused by a bug in the DMA driver that causes the interrupt-enable bit to be cleared. It is caused by a lack of atomicity, and triggered by having transfers submitted on multiple channels simultaneously.
#6044 should be a fix. By the time you read this (a.k.a. any time after 10:40 GMT on the 15th) you'll be able to install a 6.6 kernel with the fix by running
sudo rpi-update pulls/6044.pelwell commentedon Mar 15, 2024
And yes, I think this is effectively a dup of #5858/#5865.
makermelissa commentedon Mar 15, 2024
Thanks. Yes, the fix worked.
makermelissa commentedon Mar 15, 2024
Ok, after further testing, I think it's not quite working correctly. I am trying to use both spidev0.0 and spidev1.2 in my code. With the update, the clock signal from spidev1.2 doesn't seem to be working anymore. Like there's tons of activity on MOSI, but SCLK is barely pulsing.
pelwell commentedon Mar 15, 2024
What clock rates are you using?
makermelissa commentedon Mar 18, 2024
80 MHz. I could try slower if you think that would help, but the same code runs fine on a Pi 4 at that clock rate.
pelwell commentedon Mar 18, 2024
And in which directions? Try and help me reproduce your setup.
makermelissa commentedon Mar 18, 2024
Pretty much all output. I'm writing to 2 ST7789 displays.
pelwell commentedon Mar 19, 2024
A few things:
makermelissa commentedon Mar 19, 2024
pelwell commentedon Mar 19, 2024
Yes, because you've been running it at 50MHz all along. In fact, looking at logic analyser trace it's only driving SCLK half the time, so there's an effective rate of 25MHz.
At this point it might be best if you put together a cut-down test program that demonstrates the issue.
makermelissa commentedon Mar 19, 2024
Yeah, probably.
makermelissa commentedon Mar 20, 2024
Ok, here's some pared down code below(from like 1000 lines).
You can save as screentest.c and compile with
cc -o screentest screentest.c -lgpiod -Wall -OfastYou will need to enable both spi ports in /boot/firmware/config.txt with:
Here's the code
pelwell commentedon Mar 21, 2024
Thanks for that, Melissa. Running it on Pi 4 and Pi 5 the only differences I see are in the timing - Pi 4 runs the bus at 62.5MHz, Pi 5 at 50MHz - and that Pi 5 holds MOSI at the previous value between bytes while Pi 4 returns it to low. Other than that, the traces look the same, with SPI0.0 getting about 112KB of data first, followed by SPI1.2.
Here's Pi 4:

And Pi 5:

So it sounds like my Pi 5 is not showing the same behaviour as yours. Yes there is no hardware attached, but it's all transmit-only so it shouldn't matter unless some external load/pull is interfering.
makermelissa commentedon Mar 21, 2024
Ok, I'll take another look. Starting from a fresh SD might fix it. Also, I could try a second Pi 5 I have to see if it's just one of my Pis misbehaving.
pelwell commentedon Mar 21, 2024
In case you find that things are still failing, another option is to run the SPI interfaces without DMA. If you replace the standard Pi 5 dtb file (in /boot/firmware) with this one (https://drive.google.com/file/d/1NGJsJoeFf_K8mVi0lNjO6FIPEOYj9lvf/view?usp=drive_link) you'll gain a new dtparam -
nospidma, which does what you would expect.