toun
Posts: 3
Joined: Wed May 29, 2019 10:21 am

[Solved] mcp2515-can0 fails to setup interrupt pin

Thu Sep 23, 2021 6:18 pm

I'm trying to get a MCP2515 working with the RPI 3A+ on spi0.0. This worked in the past with kernel versions 4.x, but it broke when updating to 5.10.

My config.txt is as follows :

Code: Select all

dtparam=spi=on
dtoverlay=spi0-1cs
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25
I replaced dtoverlay=spi0-hw-cs with dtoverlay=spi0-1cs when updating to 5.10, but that's about it.

After boot, I get the usual "mcp251x spi0.0 can0: MCP2515 successfully initialized", and the network device is correctly brought up at 250kbps. However the device never receives any messages. Probing the SPI lines with an oscilloscope shows that after the initial hardware reset frame and status reading, no further transfer happens on the bus.

I found the following command to show GPIO pins assignments:

Code: Select all

$ cat /sys/kernel/debug/gpio
gpio-8 (|spi0 CS0) out hi ACTIVE LOW
gpio-29 (|led0) out lo
My (uneducated) guess is that the interrupt line (GPIO 25) should appear in this list, and that the mcp2515-can0 overlay is not working correctly with the latest kernels. I honestly have a hard time understanding the DTS syntax, so cannot determine what's wrong with it. Any help appreciated.
Last edited by toun on Fri Sep 24, 2021 5:08 pm, edited 1 time in total.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4123
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: mcp2515-can0 fails to setup interrupt pin

Fri Sep 24, 2021 12:21 pm

As root(*) (unless /sys/kernel/debug is accessible to user pi), run:

Code: Select all

# cat /sys/kernel/debug/pinctrl/*/pins
# cat /proc/interrupts
# vcdbg log msg
Report the output.

(*) sudo cat... won't work because the shell expansion runs before the sudo - use "sudo su" or "sudo -i" to get an interactive root shell.

toun
Posts: 3
Joined: Wed May 29, 2019 10:21 am

Re: mcp2515-can0 fails to setup interrupt pin

Fri Sep 24, 2021 5:07 pm

Well, problem fixed. Some 62 ohm resistors got mixed in the 10K bag apparently, and the interrupt pull up was way too strong. Obviously the 2 boards I picked when updating the kernel were the only ones with this defect, AND the logic analyzer I used at first when probing the SPI bus had a threshold high enough to consider the interrupt signal as low ...

Anyway here's the output of those commands in case anyone wants to check against their setup (or at least the parts that seem important, had to copy that by hand ..):

Code: Select all

$ cat /sys/kernel/debug/pinctrl/*/pins
registered pins: 54
[...]
pin 8 (gpio8) 8:pinctrl-bcm2835 function gpio_out in hi; irq 0 (none)
pin 9 (gpio9) 9:pinctrl-bcm2835 function alt0 in lo; irq 0 (none)
pin 10 (gpio10) 10:pinctrl-bcm2835 function alt0 in lo; irq 0 (none)
pin 11 (gpio11) 11:pinctrl-bcm2835 function alt0 in lo; irq 0 (none)
[...]
pin 25 (gpio 25) 25:pinctrl-bcm2835 function gpio_in in hi; irq 202 (level-low)
[...]

Code: Select all

$ cat /proc/interrupts
[...]
202: 0 0 0 0 pinctrl-bcm2835 25 Level spi0.0
[...]
And the VCDBG package on buildroot conflicts with mesa so I didn't bother.

Sidenote: I find it interesting that pin 8 is muxed on the GPIO instead of ALT0, wouldn't using hardware CS be more efficient?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4123
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: [Solved] mcp2515-can0 fails to setup interrupt pin

Fri Sep 24, 2021 6:13 pm

Hardware controlled chip select lines would be more efficient, but there are bugs and limitations in the BCM283x implementation that make it easier, safer and more flexible to use software driven GPIOs.

Return to “Device Tree”