Repository navigation
Description
Describe the bug
The HAT has a dual channel mcp251xfd can chip, running on spi0.0 and spi1.0. While the driver loads and looks like it is working a number of issues are occurring,. A dmesg | grep can shows
[ 7.661604] mcp251xfd spi0.0 can0: MCP2518FD rev0.0 (-RX_INT -MAB_NO_WARN +CRC_REG +CRC_RX +CRC_TX +ECC -HD c:40.00MHz m:20.00MHz r:17.00MHz e:16.66MHz) successfully initialized.
[ 7.724663] mcp251xfd spi1.0 can1: MCP2518FD rev0.0 (-RX_INT -MAB_NO_WARN +CRC_REG +CRC_RX +CRC_TX +ECC -HD c:40.00MHz m:20.00MHz r:17.00MHz e:16.66MHz) successfully initialized.
When trying to send and receive can messages on can0 the following dmesg messages are received for a few seconds and then stops, but traffic is sent and received on can0
[ 23.398211] NOHZ tick-stop error: Non-RCU local softirq work is pending, handler #8!!!
[ 23.501499] NOHZ tick-stop error: Non-RCU local softirq work is pending, handler #8!!!
[ 23.581290] NOHZ tick-stop error: Non-RCU local softirq work is pending, handler #8!!!
[ 23.607407] NOHZ tick-stop error: Non-RCU local softirq work is pending, handler #8!!!
[ 23.619993] NOHZ tick-stop error: Non-RCU local softirq work is pending, handler #8!!!
[ 23.629911] NOHZ tick-stop error: Non-RCU local softirq work is pending, handler #8!!!
[ 23.653014] NOHZ tick-stop error: Non-RCU local softirq work is pending, handler #8!!!
[ 23.662845] NOHZ tick-stop error: Non-RCU local softirq work is pending, handler #8!!!
[ 23.673721] NOHZ tick-stop error: Non-RCU local softirq work is pending, handler #8!!!
However I can not get can1 running at all.
ifconfig can1 up
ifconfig: SIOCSIFFLAGS: Invalid argument
dmesg has these messages
[ 394.045735] mcp251xfd spi1.0 can1: Failed to detect MCP2518FD (osc=0x00000000).
[ 394.053266] mcp251xfd spi1.0 can1: CRC read error at address 0x0e0c (length=4, data=00 00 00 00, CRC=0x0000) retrying.
[ 394.064157] mcp251xfd spi1.0 can1: CRC read error at address 0x0e0c (length=4, data=00 00 00 00, CRC=0x0000) retrying.
[ 394.075031] mcp251xfd spi1.0 can1: CRC read error at address 0x0e0c (length=4, data=00 00 00 00, CRC=0x0000) retrying.
[ 394.085798] mcp251xfd spi1.0 can1: CRC read error at address 0x0e0c (length=4, data=00 00 00 00, CRC=0x0000).
[ 394.096366] mcp251xfd spi1.0 can1: CRC read error at address 0x0000 (length=4, data=00 00 00 00, CRC=0x0000) retrying.
[ 394.107287] mcp251xfd spi1.0 can1: CRC read error at address 0x0000 (length=4, data=00 00 00 00, CRC=0x0000) retrying.
[ 394.118507] mcp251xfd spi1.0 can1: CRC read error at address 0x0000 (length=4, data=00 00 00 00, CRC=0x0000) retrying.
[ 394.129372] mcp251xfd spi1.0 can1: CRC read error at address 0x0000 (length=4, data=00 00 00 00, CRC=0x0000).
[ 394.139661] mcp251xfd spi1.0 can1: CRC read error at address 0x0e0c (length=4, data=00 00 00 00, CRC=0x0000) retrying.
[ 394.150838] mcp251xfd spi1.0 can1: CRC read error at address 0x0e0c (length=4, data=00 00 00 00, CRC=0x0000) retrying.
[ 394.161713] mcp251xfd spi1.0 can1: CRC read error at address 0x0e0c (length=4, data=00 00 00 00, CRC=0x0000) retrying.
[ 394.172492] mcp251xfd spi1.0 can1: CRC read error at address 0x0e0c (length=4, data=00 00 00 00, CRC=0x0000).
[ 394.182735] mcp251xfd spi1.0 can1: CRC read error at address 0x0000 (length=4, data=00 00 00 00, CRC=0x0000) retrying.
[ 394.193606] mcp251xfd spi1.0 can1: CRC read error at address 0x0000 (length=4, data=00 00 00 00, CRC=0x0000) retrying.
[ 394.204483] mcp251xfd spi1.0 can1: CRC read error at address 0x0000 (length=4, data=00 00 00 00, CRC=0x0000) retrying.
[ 394.215283] mcp251xfd spi1.0 can1: CRC read error at address 0x0000 (length=4, data=00 00 00 00, CRC=0x0000).
I have installed various fixes and patches as baed on https://github.com/marckleinebudde/linux-rpi/commits/v5.10-rpi/backport-performance-improvements
Steps to reproduce the behaviour
Stock 5.10.95 pulled from https://github.com/raspberrypi/linux/tree/rpi-5.10.y and the can0 interface presented some crc error, which after installing this patch 0ecb42a can: mcp251xfd: mcp251xfd_regmap_crc_read(): work around broken CRC on TBC register, stopped giving them.
Device (s)
Raspberry Pi 3 Mod. B
System
Linux raspberrypi2 5.10.95-v7 #1 SMP Fri Feb 18 07:45:17 UTC 2022 armv7l GNU/Linux
[ 0.080092] raspberrypi-firmware soc:firmware: Attached to firmware from 2022-01-20T13:58:22, variant start
[ 0.090104] raspberrypi-firmware soc:firmware: Firmware hash is bd88f66f8952d34e4e0613a85c7a6d3da49e13e2
Logs
No response
Additional context
I have a similar system using a basic mcp251x, this is also a dual can HAT. I have noticed that the mcp251xfd is also consuming far more CPU resources than the basic mcp251x, over double the resources ..
mcp251xfd:
1368 2 root SW 0 0% 10% [irq/199-spi0.0]
165 2 root RW 0 0% 6% [spi0]
compared to the mcp251x
29533 2 root SW 0 0% 4% [irq/166-mcp251x]
219 2 root SW 0 0% 2% [spi0]
Activity
pelwell commentedon Feb 21, 2022
I'm going to leave this open for others to contribute to, but without a dual mcp251xfd HAT and some CAN hardware it's not going to get any attention from me. Have you tried asking @marckleinebudde, whose repo you linked to?
marckleinebudde commentedon Feb 21, 2022
Hey @nmbath,
the
mcp251xfddriver in linux-v5.10 should work with your hardware, my branch is only performance improvements. If you use a newer raspi kernel, the improvements are already included.BTW the problem:
is fixed with v5.15.
Coming back to your problem:
The driver only reads
0x0, i.e. none of the bits set when reading fromspi1.0. Your analysis that the chip select might not be working looks good to me. Do you have a scope to check that? Can you post here you DT overlay configuration?The
mcp251xfddriver uses more resources, as the chip is more complex, it needs more SPI transfers per received CAN message, than themcp251xdriver.nmbath commentedon Feb 21, 2022
Hi @marckleinebudde, Thank you for your response. The HAT is a waveshare dual mcp251xfd and understand that it uses BCM pin 7 for CS. I have used their default 2xMCP2517FD.dtbo
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";
/* disable spi-dev for spi0.0 */
};
Looking at this file they seem to be using GPIO26 for CS on the 2nd unit. I am now in an area I have not done much work on, and I do not have a scope to look at what is going on. GPIO26 is on pin 37, but reading their material CS_1 is physical pin 26, or BCM 7.
I tried changing the CS from 26 to 7, but then I got
[ 6.118410] pinctrl-bcm2835 3f200000.gpio: pin gpio7 already requested by 3f204000.spi; cannot claim for spi1.0
[ 6.128614] pinctrl-bcm2835 3f200000.gpio: pin-7 (spi1.0) status -22
[ 6.128647] mcp251xfd spi1.0: Error applying setting, reverse things back
[ 6.129724] mcp251xfd: probe of spi1.0 failed with error -22
It is probably something very simple, I just cant see it and don't have enough experience with GPIO's!
marckleinebudde commentedon Feb 21, 2022
Ahhh waveshare - adding @pdp7 to the loop.
Drew, long time no see, but do have you got a working Raspi DT Overlay for the waveshare mcp251xfd board?
pelwell commentedon Feb 21, 2022
You can release GPIO 7 by adding
dtoverlay=spi0-1csto config.txt.pelwell commentedon Feb 21, 2022
Once you have something that works I can help you tidy it up and get it into the standard kernel builds.
marckleinebudde commentedon Feb 21, 2022
Once it's working generate a "compiled" overlay with something like this (parameters have to be adjusted to the waveshare board):
See header of this file:
https://github.com/raspberrypi/linux/blob/rpi-5.15.y/arch/arm/boot/dts/overlays/seeed-can-fd-hat-v1-overlay.dts
pelwell commentedon Feb 21, 2022
Except with
,cs0_pin=7andinterrupt=16, i.e.marckleinebudde commentedon Feb 21, 2022
ACK, that was a copy/paste from the
seeed-can-fd-hat-v1-overlay.dtsoverlay, that needs to be adjusted. (Updated my comment for clarification).pelwell commentedon Feb 21, 2022
And you can include the
spi0-1csin the same ovmerge command if you want.nmbath commentedon Feb 21, 2022
I have tried adding spi0-1cs, but didn't seem to do anything and still have the error. Will try again in the morning.
nmbath commentedon Feb 22, 2022
I have just tried this configuration:
And had this..
Digging through Waveshares details, that is correct. Reading the wiki site again, they have two modes, both sharing spi0 and one on spi0 and the other on spi1. The default mode is apparently separate SPI's. They have a different table on the wiki and that looks like when sharing an SPI the CS for can1 is 7 and when separate SPI's is 26. So changed the configuration too
and got this..
ip link set can1 type can bitrate 250000
ifconfig can1 up
ifconfig: SIOCSIFFLAGS: No such device
and
So maybe it's not the overlay but something else.
Just to double check, I tried this to make sure it was not on the other mode!
and got
Thoughts?
marckleinebudde commentedon Feb 22, 2022
This mean both mcp251xfd are properly detected. But later, during ifup you got this error messages?
Strange. The driver only reads
0x0from the device. Seems the mcp2518fd is not sending anymore. Can you attach a full kernel log.nmbath commentedon Feb 22, 2022
full dmesg:
Logged in at roughly 33.x
Issued the following command, which triggered the log messages at 62.x
marckleinebudde commentedon Feb 22, 2022
Which overlays are you using in this bootlog? This looks like the waveshare overlays? Which chips are on your waveshare hat? mcp2517fd or mcp2518fd?
The driver says the firmware (the device tree + overlays) are specifying a mcp2517fd, but the driver has detected the mcp2518fd.
What's your
config.txt?Can you past the output of:
Later in the boot log we see these error messages:
This indicates that one driver instance is sending CAN messages to the Linux networking stack:
The question is, what happens between the interface is properly detected:
and
After the driver detects the chip, the chip is shut down again. When you issue a
ip link set upthe chip is reset the driver is polling theOSCregister to show the reset defaults, but register only shows0x0. The question is why.54 remaining items
pelwell commentedon Jul 5, 2022
Is there anything in
/proc/device-tree/chosen/user-warnings(dtoverlay errors will appear there)?dav2dg commentedon Jul 5, 2022
Note I have added the "-marc" suffix
Error found...
pelwell commentedon Jul 5, 2022
That's a really long filename, and until very recently there was a severe file path length limitation in the firmware overlay code. Try giving it a shorter name...
dav2dg commentedon Jul 5, 2022
Name length was the problem. This works:
dtoverlay=ws-short-nameDo you have a preferred name.
BTW Thanks both Can0 and Can1 work. I will test the faulty boards tomorrow. too late now!
marckleinebudde commentedon Jul 5, 2022
Does
waveshare-can-fd-hat-rev2.1-mode-awork?dav2dg commentedon Jul 5, 2022
Hmmm ... new overlay allows the 2 "faulty" boards to work!!!
Name is too long, the other drivers are 7 chars shorter
marckleinebudde commentedon Jul 7, 2022
Can you figure out what length still works?
dav2dg commentedon Jul 7, 2022
Sorry I had a message prepared seems I did not press "Send"
I Originally tried
waveshare-canfdhat-v2.1-a.dtbobut seemed to run into a problem with the dot in 2.1 so I changed towaveshare-canfdhat-v2-1-a.dtboHere are my test stats ... THANKYOU it seems to work now on good hardware.
marckleinebudde commentedon Jul 7, 2022
Ok. I think I'll change the filename to
waveshare-canfdhat-v21-a.dtbothen.Do you get a
Failed to detect MCP251xFD (osc=0x00000000).for all "N" in you table? Socan1of your CAN board number 2. is broken?dav2dg commentedon Jul 18, 2022
@marckleinebudde sorry for delay I have some production deadlines.
I have not checked for
Failed to detect MCP251xFD (osc=0x00000000)but my recolection is that this message was generated.Here is a log from when I was actively testing...
I just did a test on the previous Waveshare version prior to 2.1 (maybe 2.0) using latest overlay
The result is can0 OK and can1 not present on ifconfig
marckleinebudde commentedon Jul 18, 2022
The old wareshare hat without a revision number on the back only works with the
waveshare-can-fd-hat-mode-aoverlay. The new waveshare hatrev2.1should work with the overlay I send youwaveshare-canfdhat-v21-a.It makes no sense to test the old card with the new overlay or vice versa.
dav2dg commentedon Jul 18, 2022
OK Thanks, I thought the mainline might be better for the pre 2.1 version.
What is required to get the pre 2.1 onto the mainline overlay?
Thx
marckleinebudde commentedon Jul 18, 2022
I just bought a rev2.1 board, it should arrive this week. In the meantime you can test if your your rev2.1 board works with my rev2.1 overlay. Both CAN interfaces should be detected.
dav2dg commentedon Jul 18, 2022
I have tested the compiled overlay you sent me
https://github.com/raspberrypi/linux/issues/4902#issuecomment-1175047279The results are above
https://github.com/raspberrypi/linux/issues/4902#issuecomment-1177712230Is there another overlay I should test
nmbath commentedon Jul 18, 2022
I have had a rev 2.1 board for several months. I attach the overlay I have been using on that. Only issues is occasionally on boot can0 and can1 get swapped
mcp251xfd-combined.dtbo.zip
.