Hi!
I’m trying to get mcp2515 to work. It is a can over spi chip and I can’t seem to get the device tree overlay right. I made a simple c driver using spidev to check if my hardware was right. Using that driver I can read/write to registers so I’m assuming my hardware is correct. The chip is connected to an external 20mhz oscillator. I’ve been stuck for this for a week now, and really need some help to get this to work.
What I have tried so far:
A lot of variations on the devicetree overlay posted below.
Hooked up an oscilloscope, and there is no data going in either direction.
Bought a sparkfun can breakoutboard, and some hex converters, but same problem (so hardware is probably right)
I think there is something worng with the way I define the clock or the interrupts, but honestly, I’ve never done anything this advanced in the device tree overlay, just the regular stuff where there are a lot of resources on the internet, like getting i2c,uart,spi etc. to work.
Devicetree documentation for this chip: http://lxr.free-electrons.com/source/Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt?v=4.4
Driver: https://github.com/beagleboard/linux/blob/698027482f34f2559d648a2994df98b6a98873ab/drivers/net/can/spi/mcp251x.c
After enabling the driver lsmod tells me can_dev is loaded and used by mcp251x.
cat /sys/bus/spi/devices/*/modalias returns spi:mcp2515.
ip a show no can devices.
This is my device tree overlay for the chip:
`
/dts-v1/;
/plugin/;
/ {
compatible = "ti,beaglebone", "ti,beaglebone-black";
/* identification */
part-number = "BB-MIKRO-01";
/* state the resources this cape uses */
exclusive-use =
/* the pin header uses */
"P9.25", /* spi irq: gpio3_21 */
"P9.31", /* spi: spi1_sclk */
"P9.29", /* spi: spi1_d0 */
"P9.30", /* spi: spi1_d1 */
"P9.28", /* spi: spi1_cs0 */
/* the hardware IP uses */
"gpio3_21",
"spi1";
clocks{
extclk: oscillator {
compatible="fixed-clock";
#clock-cells = <0>;
clock-frequency=<20000000>;
};
};
fragment@0 {
target = <&am33xx_pinmux>;
__overlay__ {
spi1_pins: pinmux_spi1_pins {
pinctrl-single,pins = <
0x190 0x33 /* mcasp0_aclkx.spi1_sclk, RX_ENABLED | PULLUP | MODE3 */
0x194 0x33 /* mcasp0_fsx.spi1_d0, RX_ENABLED | PULLUP | MODE3 */
0x198 0x13 /* mcasp0_axr0.spi1_d1, OUTPUT_PULLUP | MODE3 */
0x19c 0x13 /* mcasp0_ahclkr.spi1_cs0, OUTPUT_PULLUP | MODE3 */
0x1ac 0x37 /* mcasp0_ahclkx.gpio3_21, RX_ENABLED | PULLUP | MODE7 */
>;
};
};
};
fragment@2 {
target = <&spi1>;
__overlay__ {
#address-cells = <1>;
#size-cells = <0>;
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&spi1_pins>;
ti,pio-mode; /* disable dma when used as an overlay, dma gets stuck at 160 bits... */
can0: can@1 {
compatible = "microchip,mcp2515";
reg = <0>; /* cs0 */
mode = <0>;
spi-max-frequency = <10000000>;
clocks=<&extclk>;
interrupt-parent = <&gpio3>;
interrupts = <21 0x02>;
};
};
};
};
`
dmesg after enabling it on boot with uEnv.txt: