Repository navigation
Description
Describe the bug
mcp2515 on spi1 - candump can0 not generating output
Steps to reproduce the behaviour
waveshare 2-ch-can-hat connected to raspberry B3+
INT1 --- Pin 29 GPIO 5
INT0 --- Pin 31 GPIO 6
CS1 ---- Pin 11 GPIO 17 (SPI1 CE1)
CS2 ---- Pin 12 GPIO 18 (SPI1 CE0)
SCK ---- Pin 40 GPIO21 (SPI1 SCLK)
MOSI -- Pin 38 GPIO20 (SPI1 MOSI)
MISO -- Pin 35 GPIO19 (SPI1 MISO)
GND --- Pin 6 GND
5V ----- Pin 1 5V
/boot/config.txt:
dtoverlay=spi1-2cs,cs0_spidev=off,cs1_spidev=off
dtoverlay=t-sp1-can0,oscillator=16000000,interrupt=5
dtoverlay=t-sp1-can1,oscillator=16000000,interrupt=6
t-sp1-can0.dtbo compiles from:
/*
*Device tree overlay for mcp251x/can0 on spi1.0
*/
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";
/* disable spi-dev for spi1.0 */
fragment@0 {
target = <&spi1>;
__overlay__ {
status = "okay";
};
};
fragment@1 {
target = <&spidev0>;
__overlay__ {
status = "disabled";
};
};
/* the interrupt pin of the can-controller */
fragment@2 {
target = <&gpio>;
__overlay__ {
can0_pins: can0_pins {
brcm,pins = <25>;
brcm,function = <0>; /* input */
};
};
};
/* the clock/oscillator of the can-controller */
fragment@3 {
target-path = "/clocks";
__overlay__ {
/* external oscillator of mcp2515 on SPI0.0 */
can0_osc: can0_osc {
compatible = "fixed-clock";
#clock-cells = <0>;
clock-frequency = <16000000>;
};
};
};
/* the spi config of the can-controller itself binding everything together */
fragment@4 {
target = <&spi1>;
__overlay__ {
/* needed to avoid dtc warning */
#address-cells = <1>;
#size-cells = <0>;
can0: mcp2515@0 {
reg = <0>;
compatible = "microchip,mcp2515";
pinctrl-names = "default";
pinctrl-0 = <&can0_pins>;
spi-max-frequency = <10000000>;
interrupt-parent = <&gpio>;
interrupts = <25 0x2>;
clocks = <&can0_osc>;
};
};
};
__overrides__ {
oscillator = <&can0_osc>,"clock-frequency:0";
spimaxfrequency = <&can0>,"spi-max-frequency:0";
interrupt = <&can0_pins>,"brcm,pins:0",<&can0>,"interrupts:0";
};
};
t-sp1-can1.dtbo compiles from:
/*
* Device tree overlay for mcp251x/can1 on spi1.1 edited by petit_miner
*/
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";
/* disable spi-dev for spi1.1 */
fragment@0 {
target = <&spi1>;
__overlay__ {
status = "okay";
};
};
fragment@1 {
target = <&spidev1>;
__overlay__ {
status = "disabled";
};
};
/* the interrupt pin of the can-controller */
fragment@2 {
target = <&gpio>;
__overlay__ {
can1_pins: can1_pins {
brcm,pins = <25>;
brcm,function = <0>; /* input */
};
};
};
/* the clock/oscillator of the can-controller */
fragment@3 {
target-path = "/clocks";
__overlay__ {
/* external oscillator of mcp2515 on spi0.1 */
can1_osc: can1_osc {
compatible = "fixed-clock";
#clock-cells = <0>;
clock-frequency = <16000000>;
};
};
};
/* the spi config of the can-controller itself binding everything together */
fragment@4 {
target = <&spi1>;
__overlay__ {
/* needed to avoid dtc warning */
#address-cells = <1>;
#size-cells = <0>;
can1: mcp2515@1 {
reg = <1>;
compatible = "microchip,mcp2515";
pinctrl-names = "default";
pinctrl-0 = <&can1_pins>;
spi-max-frequency = <10000000>;
interrupt-parent = <&gpio>;
interrupts = <25 0x2>;
clocks = <&can1_osc>;
};
};
};
__overrides__ {
oscillator = <&can1_osc>,"clock-frequency:0";
spimaxfrequency = <&can1>,"spi-max-frequency:0";
interrupt = <&can1_pins>,"brcm,pins:0",<&can1>,"interrupts:0";
};
};
dmesg|grep spi
[ 8.232885] mcp251x spi1.1 can0: MCP2515 successfully initialized.
[ 8.245989] mcp251x spi1.0 can1: MCP2515 successfully initialized.
spi1.1 linked to can0 !
spi1.0 linked to can1 !
Device (s)
Raspberry Pi 1 Mod. B+
System
Raspberry Pi reference 2021-01-11
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, 21090519d85bdaa1615d5d5057d37b09368ea5d2, stage2
Oct 29 2021 10:49:08
Copyright (c) 2012 Broadcom
version b8a114e5a9877e91ca8f26d1a5ce904b2ad3cf13 (clean) (release) (start)
Linux raspberrypi 5.10.63-v7+ #1459 SMP Wed Oct 6 16:41:10 BST 2021 armv7l GNU/Linux
Logs
No response
Additional context
No response
Activity
pelwell commentedon Feb 6, 2023
Is that your bug report? Please explain clearly what is not working.
martburg commentedon Feb 6, 2023
The Bug:
candump can0 is not producing any output.
and of course a can signal is applied to can0
I'm not sure about the linking of spi1.1 to can 0 and spi1.0 to can1 it's an observation maybe a clue to find the bug
pelwell commentedon Feb 6, 2023
dmesg -l err,warnshow anything relevant?Without this board and some CAN hardware my support is going to be limited.
martburg commentedon Feb 6, 2023
will check tomorow
thx
pelwell commentedon Feb 6, 2023
martburg commentedon Feb 6, 2023
Yes, the bus is terminated
when I connect the same CAN lines to CAN1 --candump can1-- is OK
martburg commentedon Feb 7, 2023
@pelwell
ad 1. dtoverlay=t-sp1-can0,oscillator=16000000,interrupt=5
with both overlays can1 is OK and can0 not OK
ad 2. dtoverlay=t-sp1-can0,oscillator=16000000,interrupt=5
ad 2. dtoverlay=t-sp1-can1,oscillator=16000000,interrupt=6
ad 2. with both overlays:
Strange isnt it?
More playing around with the overlays (maybe this information helps)
but can0 and can1 not OK
pelwell commentedon Feb 7, 2023
I haven't had a chance to digest all of that information yet, but are those results repeatable?
martburg commentedon Feb 7, 2023
Yes they are
pelwell commentedon Feb 7, 2023
https://www.waveshare.com/wiki/2-CH_CAN_HAT appears to be designed for SPI0. How have you changed it to use SPI1? Are you sure all the signals are connected correctly?
I think these results are significant:
For some reason, spi1.1 is not getting any interrupts. Does this change if you momentarily ground GPIO6/pin 29?
raspi-gpio get 5,6)By the way, the overlay fragments disabling
spidev0andspidev1are misguided - they are actually disablingspidev0.0andspidev0.1, and by enabling SPI1 withdtoverlay=spi1-2cs,cs0_spidev=off,cs1_spidev=offyou have already disabled the spidevs.martburg commentedon Feb 8, 2023
ad 5. using J9 on the Board
rechecked the umptiest time
there is another detail to add
up until now I feed the same signal to both can chanels by connecting can0 hi to can1 hi can0 lo to can1 lo using the
jumpers on the board
cutting those connetctions I realised ------ wait for it ----
physically feeding the can0 jumper with the signal candump can1 shows the input
ad 6-7. Time to get the osziloscope: int5 (asociated with can0) gets the interupt
verrified by running raspi-gpio get 5,6 in a loop confirms that GPIO 5 is toggeling
wheras GPIO 6 is LOW
I suspected that the fragments were misguided but my understanding of the dt was/is not good enough to know what I'm doing
just for the record 1:
candump can1 out printed
can1 49D [6] 70 16 00 00 00 00
can1 000 [8] FD 02 FD FF FF 7E 57 6F
can1 12D [7] remote request
can1 1EF9FE66 [8] remote request
just for the record2:
this is the dmesg|grep spi output if the spi-2s overlay is not loaded:
[ 6.899760] spi-bcm2835aux 3f215080.spi: cs1 >= max 1
[ 6.899805] spi_master spi1: spi_device register error /soc/spi@7e215080/mcp2515@1
[ 6.899836] spi_master spi1: Failed to create SPI device for /soc/spi@7e215080/mcp2515@1
[ 6.899904] spi spi1.0: Native CS is not supported - please configure cs-gpio in device-tree
[ 8.133857] mcp251x spi1.0: Native CS is not supported - please configure cs-gpio in device-tree
[ 9.159534] mcp251x spi1.0: MCP251x didn't enter in conf mode after reset
[ 9.159724] mcp251x spi1.0: Probe failed, err=110
[ 9.159808] mcp251x: probe of spi1.0 failed with error -110
pelwell commentedon Feb 8, 2023
It's important to distinguish between the bus numbers on the board and the labels that Linux gives the network interfaces. To make sure I've understood you correctly, please do the following:
martburg commentedon Feb 8, 2023
ad 8. CAN on CAN0 connector
candump can0 no output
candump can1 output ok
dmesg|grep spi
[ 7.951712] mcp251x spi1.1 can0: MCP2515 successfully initialized.
[ 7.964464] mcp251x spi1.0 can1: MCP2515 successfully initialized.
grep spi1 /proc/interrupts
199: 0 0 0 0 pinctrl-bcm2835 6 Edge spi1.1
200: 121014 0 0 0 pinctrl-bcm2835 5 Edge spi1.0
ad 9. CAN on CAN1 connector
candump can0 no output
candump can1 no output
dmesg|grep spi
[ 8.040167] mcp251x spi1.1 can0: MCP2515 successfully initialized.
[ 8.054469] mcp251x spi1.0 can1: MCP2515 successfully initialized.
grep spi1 /proc/interrupts
199: 0 0 0 0 pinctrl-bcm2835 6 Edge spi1.1
200: 16 0 0 0 pinctrl-bcm2835 5 Edge spi1.0
pelwell commentedon Feb 9, 2023
In both cases the driver can communicate with both instances of the MCP2515. If one of them was responding on both chip selects then the results would have been the same for 8 & 9, but they weren't. From that I conclude that the SPI communication is working.
There's still a slight question mark over the status of the sp1.1 interrupt on GPIO 6. Do you ever see it high? Could a stuck interrupt line appear to show a working controller but with no devices?
Whether the interrupt line is the cause of the problem, or whether it's just a symptom of fault on the CAN side of the MCP2515, it definitely smells like a hardware problem on the CAN board. Have you tried using it on SPI0 (with J9 moved)?
martburg commentedon Feb 9, 2023
I repeated the whole procedure with an identical board. Same results
I have shipped an other rpi where the mcp2515 was connected to spi0 but I'm not shure if it was the identical board but that could have been an other version.
I'll try to move J9 to SPI0 or should I try to move int6 to another pin?
pelwell commentedon Feb 9, 2023
Either, or both - the aim is to try different combinations to help to pinpoint the problem.
martburg commentedon Feb 9, 2023
I put our converation on stackoverflow
https://raspberrypi.stackexchange.com/questions/141017/2-ch-can-hat-mcp2515-on-spi1-rpi-3-b
and opened a ticket on the waveshare support
Now I'll will head over to the lab and try some combinations.
@pelwell : Thank you for the support!! I hope we can corner this bug.
martburg commentedon Feb 9, 2023
connected the 2-ch-can-hat to SPI0
INT1 --- Pin 22 GPIO 25
INT0 --- Pin 18 GPIO 23
CS1 ---- Pin 26 GPIO 7 (SPI0 CE1)
CS0 ---- Pin 24 GPIO 8 (SPI0 CE0)
SCK ---- Pin 23 GPIO 11 (SPI0 SCLK)
MOSI -- Pin 19 GPIO 10 (SPI0 MOSI)
MISO -- Pin 21 GPIO 9 (SPI0 MISO)
GND --- Pin 6 GND
5V ----- Pin 1 5V
/boot/config.txt:
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=23
dtoverlay=mcp2515-can1,oscillator=16000000,interrupt=25
mcp2515-can0.dtbo compiles from:
mcp2515-can1.dtbo compiles from
dmesg | grep spi
[ 8.132198] mcp251x spi0.1: prop pinctrl-0 index 0 invalid phandle
[ 8.132254] mcp251x: probe of spi0.1 failed with error -22
[ 8.132359] mcp251x spi0.0: prop pinctrl-0 index 0 invalid phandle
[ 8.132384] mcp251x: probe of spi0.0 failed with error -22
So I got a fresh copy of
mcp2515-can0.dtbo and mcp2515-can1.dtbo
from https://github.com/raspberrypi/firmware/tree/master/boot/overlays
and got the same
[ 7.856228] mcp251x spi0.1: prop pinctrl-0 index 0 invalid phandle
[ 7.856278] mcp251x: probe of spi0.1 failed with error -22
[ 7.856354] mcp251x spi0.0: prop pinctrl-0 index 0 invalid phandle
[ 7.856379] mcp251x: probe of spi0.0 failed with error -22
pelwell commentedon Feb 9, 2023
How old is your firmware (
vcgencmd version)?martburg commentedon Feb 9, 2023
System
Raspberry Pi reference 2021-01-11
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, 21090519d85bdaa1615d5d5057d37b09368ea5d2, stage2
Oct 29 2021 10:49:08
Copyright (c) 2012 Broadcom
version b8a114e5a9877e91ca8f26d1a5ce904b2ad3cf13 (clean) (release) (start)
Linux raspberrypi 5.10.63-v7+ #1459 SMP Wed Oct 6 16:41:10 BST 2021 armv7l GNU/Linux
pelwell commentedon Feb 9, 2023
Don't worry, I've found it -
Oct 29 2021 10:49:08. I've just tried those overlays here, and although the mcp2515 driver can't find any hardware (obviously), there is no problem with the overlay application:Try grabbing the overlays from the same release as the firmware: https://github.com/raspberrypi/rpi-firmware/tree/d5edc6af1ef48f97b525da88ff6c510c2d4231c3/overlays
martburg commentedon Feb 9, 2023
Grabed it loaded it ---
pi@raspberrypi:~ $ dmesg|grep spi
[ 7.927692] mcp251x spi0.1: prop pinctrl-0 index 0 invalid phandle
[ 7.927738] mcp251x: probe of spi0.1 failed with error -22
[ 7.927815] mcp251x spi0.0: prop pinctrl-0 index 0 invalid phandle
[ 7.927837] mcp251x: probe of spi0.0 failed with error -22
pi@raspberrypi:~ $ dmesg|grep mcp
[ 5.271546] mcp25xxfd: loading out-of-tree module taints kernel.
[ 7.927692] mcp251x spi0.1: prop pinctrl-0 index 0 invalid phandle
[ 7.927738] mcp251x: probe of spi0.1 failed with error -22
[ 7.927815] mcp251x spi0.0: prop pinctrl-0 index 0 invalid phandle
[ 7.927837] mcp251x: probe of spi0.0 failed with error -22
pi@raspberrypi:~ $
martburg commentedon Feb 10, 2023
New System
Raspberry Pi reference 2022-09-22
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, 005a8c73b05a2cab394073150208bf4f069e861a, stage2
Copyright (c) 2012 Broadcom
version 102f1e848393c2112206fadffaaf86db04e98326 (clean) (release) (start)
Linux raspberrypi 5.15.61-v8+ #1579 SMP PREEMPT Fri Aug 26 11:16:44 BST 2022 aarch64 GNU/Linux
/boot/config.txt:
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=23
dtoverlay=mcp2515-can1,oscillator=16000000,interrupt=25
no Board attached -->
[ 11.540216] mcp251x spi0.1: MCP251x didn't enter in conf mode after reset
[ 11.541770] mcp251x spi0.1: Probe failed, err=110
[ 11.541833] mcp251x: probe of spi0.1 failed with error -110
[ 12.566084] mcp251x spi0.0: MCP251x didn't enter in conf mode after reset
[ 12.566333] mcp251x spi0.0: Probe failed, err=110
[ 12.566350] mcp251x: probe of spi0.0 failed with error -110
Board attached to spi0 -->
[ 10.532899] mcp251x spi0.1 can0: MCP2515 successfully initialized.
[ 10.551022] mcp251x spi0.0 can1: MCP2515 successfully initialized.
Still the mixup CAN0 and CAN1 but both channels working on SPI0
Next Step ---> move to SPI1
I'll keep you posted
martburg commentedon Feb 10, 2023
one Overlay:
dt-overlay=t-spi1-can0,oscillator=16000000,interrupt=5
[ 11.608247] mcp251x spi1.0: Cannot initialize MCP2515. Wrong wiring?
[ 11.608751] mcp251x spi1.0: Probe failed, err=19
dt-overlay=t-spi1-can1,oscillator=16000000,interrupt=6
[ 10.718563] mcp251x spi1.1: Cannot initialize MCP2515. Wrong wiring?
[ 10.728394] mcp251x spi1.1: Probe failed, err=19
both Overlays
dt-overlay=t-spi1-can0,oscillator=16000000,interrupt=5
dt-overlay=t-spi1-can1,oscillator=16000000,interrupt=6
[ 10.797097] mcp251x spi1.1 can0: MCP2515 successfully initialized.
[ 10.873963] mcp251x spi1.0 can1: MCP2515 successfully initialized.
candump can0 (asociated with spi1.1) not OK
candump can1 (asociated with spi 1.0) OK
cat /proc/interrupts
184: 0 0 0 0 pinctrl-bcm2835 6 Edge spi1.1
185: 68932 76684 71270 76552 pinctrl-bcm2835 5 Edge spi1.0
GPIO 5 (int0) HIGH and gets Interrupts
GPIO 6 (int1) is LOW
looks like we are back on square one - but we verrified the board is working on spi0 (with crosover between can0 and can1)
and the new system makes a more stable impression
martburg commentedon Feb 10, 2023
changing the order of the loading of the overlays took care of the crosover
both of the board beeing on spi0 or spi1
on spi0 both channels ar working
on spi1 only one is working
so we could change the issue to
mcp2515 on spi1 only one can channel working
pelwell commentedon Feb 10, 2023
I think this is a hardware problem, one that few people have encountered because most would use it on SPI0.
martburg commentedon Feb 10, 2023
Shure?
As I was using J9 on the waveshare board both for the connection to spi0 and spi1 for me the board looks OK.
but as I need only can0 on spi1 for this project --- I vote for closing this issue, if somebody else or I at a later time need both channels working we already have the title for that issue.
One last thing tomorow I'll try to change from GPIO 6 maybe this is the issue
martburg commentedon Feb 11, 2023
Moving the interrupt vrom pin 31 (GPIO 6) to pin 33 (GPIO 13) solved the problem.
So either it is just my rpi where GPIO 6 in this combination is faulty or ....
Any way -- hardware