1

Waveshare makes a great CAN HAT for the Raspberry Pi (see here), but the instructions only work for Raspberry Pi OS, not for Armbian. The Banana Pi BPI-M2 Zero has the same pin header layout as the Raspberry Pi, but runs Armbian. How do you setup the Waveshare CAN HAT using Armbian's overlay system?

johnnyb
  • 71
  • 7

1 Answers1

0

Overlays work slightly differently on Armbian than on Raspberry Pi OS. For this, there are two things you need. First, you need to enable SPI bus zero. This can be done by editing the file /boot/armbianEnv.txt. Add the following two lines to the file:

overlays=spi-spidev
param_spidev_spi_bus=0

If there is already a line that says overlays= you will need to add spi-spidev to the same line, as all of the system overlays have to be specified in the same command.

Next, you need a DTS file, which essentially maps various driver parameters to their specific implementation on the board you are working with. I used this file (copied below) which seemed to match the specific board that Waveshare ships. The file should be named spi-mcp251x.dts. The file can be compiled and installed with the command armbian-add-overlay spi-mcp251x.dts, which will also add it to /boot/armbianEnv.txt. Then, on reboot, you should have a working CAN driver!

The contents of the spi-mcp251x.dts file are below:

/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";
            };
        };
    };
};
Murray Jensen
  • 2,672
  • 2
  • 11
  • 9
johnnyb
  • 71
  • 7