armbian: Banana Pi M2 Zero with Waveshare RS485 CAN HAT - matztam/signalk-autopilot-remote GitHub Wiki

Create file "spi-mcp251x.dts"

/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 = <2000000>;
				interrupt-parent = <&pio>;
				interrupts = <0 2 8>; /* PA2 IRQ_TYPE_LEVEL_LOW */
				clocks = <&can0_osc_fixed>;
				status = "okay";
			};
		};
	};
};

Add overlay

~# armbian-add-overlay spi-mcp251x.dts

Edit /etc/network/interfaces

allow-hotplug can0
iface can0 can static
        bitrate 250000
        down /sbin/ip link set $IFACE down
        up /sbin/ifconfig $IFACE txqueuelen 10000

Reboot and check state

~# ip addr ls dev can0
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP group default qlen 10000
    link/can 

~# ifconfig can0
can0: flags=193<UP,RUNNING,NOARP>  mtu 16
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10000  (UNSPEC)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
⚠️ **GitHub.com Fallback** ⚠️