-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.4.y] [arm64] spi cs seems to be broken #3355
Comments
Yes, it's definitely broken. Out with the logic analyser... |
The CS line is inverted on 5.4. An spi_set_cs(1) results in the GPIO driver being asked to set GPIO 8 to 0 (correct - it's active low) on 4.19 and 1 (incorrect) on 5.4. I'm pretty sure it's triggered by 3bd158c, but I haven't yet worked out whether the error is in the code or the device tree CS declarations. |
It turns out to indeed be a side effect of 3bd158c, but the fault actually lies in the SPI-Py library. See my PR (lthiery/SPI-Py#25) for an explanation of the problem. Download the patch (https://github.com/lthiery/SPI-Py/pull/25/commits/298c90d007ab740fbdbc6872d47b26011c25c554.patch), apply it to your tree ( |
Thanks but the library I use https://github.com/rm-hull/luma.core uses https://github.com/doceme/py-spidev under the hood. |
Try setting the |
Thanks, will do and report back once I get home so I can see the actual output on display =) |
Confirmed - with cs_high=True the display works OK. A stripped down example of how I initialize luma device for anyone with the same problem led here by google:
|
That's good news. One way forward would be to modify the library so that an absent cs_high value means "don't change it". I can also raise the question with the GPIO and SPI maintainers to see whether the current behaviour is expected. |
Not 100% sure if that's related but I noticed that on 5.4.1 GPIOs 7/8 are claimed according to pinmux-pins (with dtparam=spi=on on RPi4)
On 5.3.12 only the HW CS pins were configured, GPIOs were unclaimed
Did SPI switch to GPIO CS instead of HW CS? |
scratch my last comment, only difference in pinctrl between 5.4 and before is that the GPIOs are now properly claimed. function selection of the CS pins (gpio_out) is the same |
I see that this commit has landed into stable tree https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-5.4.y&id=39552e0e71c0109fd83284e28aaa5e8691a36fc9 From the looks of it this should fix the issue, will report back once I'm able to get to my pi and test it at runtime. |
It's odd that Mark Brown didn't mention that patch when I raised the issue upstream, but I'm happy the issue might have been fixed. I notice that somebody was complaining about a regression, and they were pointed to a followup patch (https://patchwork.kernel.org/patch/11209839/ - the link is down for me at the moment). |
Nope, works only with cs_high, sorry for the noise. |
The followup patch was merged too, so I already had it. |
Fixed in v5.6-rc5 with torvalds/linux@138c9c3, now also queued for v5.4-stable. |
@l1k thanks for letting us know, will test and report back once 5.6 is released, sadly I don't have time right now to play with -rc. |
@l1k I applied aforementioned commit on top of rpi-5.5.y, patch applied cleanly,
Setting cs_high to False or omitting it (default is False - low) did not make a difference. No errors in dmesg. |
maybe related to this: mcp2515 worked with this kernel:
but fails after an upgrade to
when downgrading to 4.19 with works fine again. |
You must be using an old or custom DTB file - these lines show that whatever you are using is requesting hardware/native CS lines, which doesn't work in 5.4. A request for hardware chip selects looks like:
whereas normal software-driven chip selects are:
|
I did add the following lines to /boot/config.txt to activate the mcp2515:
This is found in most guides on how to get CAN working with the RPi. Is there a way to fix this internally for 5.4 ? |
Try removing or commenting out the second line. |
worked, thanks a lot! |
No, thank you - it's a handy reminder to delete that overlay. |
It's deleted now. Although rpi-update won't delete the existing overlay (I'm not sure about |
See: raspberrypi/linux#3765 kernel: overlays: Delete spi0-hw-cs See: raspberrypi/linux#3355 kernel: backlight: gpio: Explicitly set the direction of the GPIO See: raspberrypi/linux#3767 kernel: overlays: Add maxtherm overlay for MAX6675/31855 See: raspberrypi/linux#3763 firmware: arm_loader: Knock 1.7 seconds off boot time See: #1375 firmware: Imx477 external sync signals
See: raspberrypi/linux#3765 kernel: overlays: Delete spi0-hw-cs See: raspberrypi/linux#3355 kernel: backlight: gpio: Explicitly set the direction of the GPIO See: raspberrypi/linux#3767 kernel: overlays: Add maxtherm overlay for MAX6675/31855 See: raspberrypi/linux#3763 firmware: arm_loader: Knock 1.7 seconds off boot time See: raspberrypi/firmware#1375 firmware: Imx477 external sync signals
This should be resolved in latest rpi-update kernel. |
The explanation given in #3745 pretty much makes this issue invalid, I forgot I had this one open. |
serial = spi(device=0, port=0, cs_high=True)#cs_high = True is a workaround to this isseu raspberrypi/linux#3355 This new option fixes an issues that was introduced in a update of the system
Describe the bug
SPI (possibly CS) is broken on 5.4.y
To reproduce
Attach an sh1106 or ssd1306 spi (4wire) display like in https://luma-oled.readthedocs.io/en/latest/hardware.html
Install luma.core and luma.oled python modules.
Try drawing something on the display the via a python script,
for example something from https://github.com/rm-hull/luma.examples/tree/master/examples
like this:
Expected behaviour
There should be image or text on the screen.
Actual behaviour
Screen is black.
Wire CS pin of the display to ground instead of CE0 (BCM8) pin - works.
System
Own OS
pi 4b
cat /etc/rpi-issue
)?Own pet project
vcgencmd version
)?uname -a
)?Linux rpi4 5.4.0-k6 #1 SMP Thu Nov 28 00:43:25 EET 2019 aarch64 GNU/Linux
dtparam=spi=on
in config.txtLogs
No mentions of spi or any other scary errors in dmesg, can provide additional info if requested.
Additional context
The clue may be that if I wire display CS pin to ground it starts working like a champ.
This setup (scripts, wiring) have been working like a champ since pi2 days.
Tried using spi 0 device 1 with CS pin swapped - same behavior.
Disconnected everything from the pi except the display - same behavior.
Checked and redid display wiring - same behavior.
Checked with a smaller ssd1306 spi display - same behavior.
Checked python-smbus, luma.oled and luma.core versions - nothing changed for months.
Tried reverting a bunch of bcm-spi2835.c related commits to the state said file was in 5.3.y - same ...
Tried playing with spi0-cs and spi0-hw-cs overlays - more of the same.
Sadly I don't own a scope so I can't properly peek at what's happening with CS.
My crappy multimeter shows constantly and quickly floating voltage on active CS pin in range 0.005v - 0.07v (this measurement is not to be trusted) , it's never 0, inactive CS pin is stable 3,3v
Kernel 5.3.y with same firmware version worked fine earlier today.
However I can't test with 5.3 ATM because I rebuilt the whole thing and glibc was foolishly built with --enable-kernel=5.4.0.
If needed I can rebuild for testing, takes a bit of time tho.
Edit: if needed I can easily and quickly rebuild the kernel to test any patches on the fly.
Edit2: all other peripherals I have (i2c rtc, temperature sensor, buttons, leds, etc) work properly, this was tested with everything but the display physically disconnected.
The text was updated successfully, but these errors were encountered: