How to get Pican2 Can Controller working?

Hi there,

I have an Pican2 Shield, which works well on an Raspberry Pi, but it doesn’t work on my Banana Pi M2 Berry. I get some mcp2515 dcp-Files, but they are all for orangePI. The only thing I get to work a little bit is this file: sunxi-DT-overlays/spi-mcp251x.dts at master · armbian/sunxi-DT-overlays · GitHub But it gives me some Errors after reboot like no valid map

Someone faces the same problem or better, get a solution for it?

My system is armbian buster lite version 21.02.1

regards Pascal

i am a little bit further, just to say.

I get following messages:

$ dmesg | grep spi || can
[    1.542959] sun6i-spi 1c05000.spi: Failed to request TX DMA channel
[    1.542978] sun6i-spi 1c05000.spi: Failed to request RX DMA channel
[    1.543860] sun6i-spi 1c05000.spi: chipselect 0 already in use
[    1.543881] spi_master spi0: spi_device register error /soc/spi@1c05000/spidev@0
[    1.543908] spi_master spi0: Failed to create SPI device for /soc/spi@1c05000/spidev@0
[    6.980799] mcp251x spi0.0: there is not valid maps for state default
[    8.037029] mcp251x spi0.0: MCP251x didn't enter in conf mode after reset
[    8.037237] mcp251x spi0.0: Probe failed, err=110
[    8.037263] mcp251x: probe of spi0.0 failed with error -110

This comes also:

[    7.098620] sun4i-pinctrl 1c20800.pinctrl: unsupported function irq on pin PD21

My armbianEnv.txt :

verbosity=1
bootlogo=false
console=both
disp_mode=1920x1080p60
overlay_prefix=sun8i-r40
rootdev=UUID=6418452f-6e30-4944-b4ef-dadc965d2ee5
rootfstype=ext4
overlays=spi-spidev0
user_overlays=spi-mcp2515
usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u

my user overlay:

/dts-v1/;
/plugin/;

/ {
    compatible = "allwinner,sun50i-h6";

    fragment@0 {
            target-path  = "/";
            __overlay__ {
                    can0_osc_fixed: can0_osc_fixed {
                            compatible = "fixed-clock";
                            #clock-cells = <0>;
                            clock-frequency  = <8000000>;
                    };
            };
    };

    fragment@1 {
            target = <&pio>;
            __overlay__ {
                    can0_pin_irq: can0_pin_irq {
                            pins = "PD21";
                            function = "irq";
                            bias-pull-up;
                    };
            };
    };

    fragment@2 {
            target = <&spi0>;
            __overlay__ {
                    status = "okay";
                    #address-cells = <1>;
                    #size-cells = <0>;
                    can0:mcp2515@0 {
                            reg = <0>;
                            compatible = "microchip,mcp2515";
                            pinctrl-names = "default";
                            pinctrl-0 = <&can0_pin_irq>;
                            spi-max-frequency = <10000000>;
                            interrupt-parent = <&pio>;
                            interrupts = <3 21 2>; /* PD21 -> 0 7 2 = PA7 IRQ_TYPE_EDGE_FALLING */
                            clocks = <&can0_osc_fixed>;
                            status = "okay";
                    };
            };
    };
};

I tried it also with irq pin PA7 and 0 7 2 as interrupts. Doesn’t work. Seems there are some problems with the pins. My knowledge is not deep enough here :frowning:

But maybe this helps someone to analyze that better. Would be nice if I can get some help here :slight_smile:

You’re close. I have this working on my bpi m2 zero.

I think your specific error is that the MCP2515 interrupt is level based (low = interrupt pending) not negative edge based (falling edge = interrupt pending). My Waveshare RS485 CAN HAT has its interrupt pin on PA2, and I had issues until I changed my interrupt line.

here is my mcp2515 dts file; you’ll have to edit to match your system. I also added the spi-spidev overlay and enabled spidev0 by adding param_spidev_spi_bus=0 to my armbianEnv.txt, but I don’t think that is necessary. In fact, I get an error message on boot about spidev0 not being able to start because there’s a pin conflict (spidev0 wants the chip select, but my MCP2515 fragment has stolen it).

/dts-v1/;
/plugin/;

/ {
        compatible = "allwinner,sun4i-a10", "allwinner,sun7i-a20", "allwinner,sun8i-h3", "allwinner,sun50i-a64", "allwinner,sun50i-h5";

        fragment@0 {
                target-path = "/clocks";
                __overlay__ {
                        #address-cells = <1>;
                        #size-cells = <1>;
                        can0_osc_fixed: can0_osc_fixed {
                                compatible = "fixed-clock";
                                #clock-cells = <0>;
                                clock-frequency  = <12000000>;
                        };
                };
        };

        fragment@1 {
                target = <&pio>;
                __overlay__ {
                        can0_pin_irq: can0_pin_irq {
                                pins = "PA2";
                                function = "irq";
                                bias-pull-up;
                        };
                };
        };

        fragment@2 {
                target = <&spi0>;
                __overlay__ {
                        #address-cells = <1>;
                        #size-cells = <0>;
                        status = "okay";
                        mcp2515 {
                                reg = <0>;
                                compatible = "microchip,mcp2515";
                                pinctrl-names = "default";
                                pinctrl-0 = <&can0_pin_irq>;
                                spi-max-frequency = <10000000>;
                                interrupt-parent = <&pio>;
                                //interrupts = <0 7 2>; /* PA7 IRQ_TYPE_EDGE_FALLING */
                                interrupts = <0 2 8>; /* PA2 IRQ_TYPE_LEVEL_LOW */
                                clocks = <&can0_osc_fixed>;
                                status = "okay";
                        };
                };
        };
};