MCP2517FD Setup For Jetson Nano

Hello, I’m currently attempting to get the MCP2517FD CLICK board working with the Jetson Nano through SPI, but it’s been quite a struggle so far… and I don’t want to buy an USB-to-CAN device =)

There is this post on the ARMBIAN forum where the OP got it working on an OrangePi using an unofficial driver for RPi:
https://forum.armbian.com/topic/11651-spi-based-canfd-driver-overlay-mcp2517mcp2518/
https://github.com/msperl/linux-rpi/tree/upstream-v5.0-rc3-mcp25xxfd-v6.11/drivers/net/can/spi/mcp25xxfd

Following this guide written by Atrer, I’ve managed to compile the module and load it - I used the scripts from JetsonHacks to download vL4T32.1 (the current revision on my Nano):
https://devtalk.nvidia.com/default/topic/1057158/jetson-tx2/guide-to-enabling-mcp251x-mcp2515-on-the-tx2-spi-can
https://github.com/JetsonHacksNano/buildKernelAndModules/tree/vL4T32.1

I made only minor modifications to the driver to get it to compile, redefining the le32_to_cpu_array and cpu_to_le32_array functions inside mcp25xxfd_cmd.h.

I’ve previously enabled SPI1 (listed as spidev0.0) using the script from this GitHub repository:
https://github.com/rt-net/JetsonNano_DT_SPI

The MCP2517FD click board’s SPI pins are connected to J41 pins [19, 21, 23, 24] for SPI1, based on the Jetson Nano pinout diagram from JetsonHacks:
https://www.jetsonhacks.com/nvidia-jetson-nano-j41-header-pinout/

But now I am currently stuck trying modifying tegra210-p3448-0000-p3449-0000-a02.dts for the MCP2517FD device… If anyone can point me to the right direction, that will be greatly appreciated!

hello PenguEngineer,

please refer to https://github.com/gtjoseph/jetson-nano-support/tree/l4t_32.2.1 for Nano SPI.
you may also share detail messages (i.e. $ dmesg) about the failures.
thanks

Hello JerryChang,

My L4T version on the Nano is 32.1, and I’ve already enabled SPI0_0 using the script from the previously-mentioned GitHub repository. SPI0.0 is set up under spi@7000d400, as seen in the updated DTS file from that repository: https://github.com/rt-net/JetsonNano_DT_SPI/blob/master/tegra210-p3448-0000-p3449-0000-a02.dts

I am able to access SPI on the Jetson Nano under /dev/spidev0.0 after compiling and copying the updated DTB file before running the following scripts:

sudo ./apply_binaries.sh
sudo ./flash.sh --no-systemimg -k DTB jetson-nano-qspi-sd mmcblk0p1

My current goal is set up the MCP2517FD device by modifying the DTS file… except that I’m totally new to it, so I don’t quite know what are the right values to put in for the fields.

I’m trying to refer to this DTS for setting up the MCP2517FD driver on the OrangePi, from that ARMBIAN forum link:

/dts-v1/;
/plugin/;

//#include <dt-bindings/interrupt-controller/irq.h>

/ {
    compatible = "allwinner,sun8i-h3";

    fragment@0 {
        target-path = "/aliases";
        __overlay__ {
            spi1 = "/soc/spi@01c69000";
        };
    };

    /* the interrupt pin of the can-controller */
    fragment@1 {
        target = <&pio>;
        __overlay__ {
            can0_pin_irq: can0_pin_irq {
                allwinner,pins = "PA2";
                allwinner,function = "irq";
                allwinner,drive = <0x0>;
                allwinner,pull = <0x1>;
                linux,phandle = <0x1>;
                phandle = <0x1>;
            };
        };
    };

    /* the clock/oscillator of the can-controller */
    fragment@2 {
        target-path = "/";
        __overlay__ {
            /* external 20M oscillator of mcp2517fd on SPI0.0 */
            mcp2517fd_osc: mcp2517fd_osc {
                compatible = "fixed-clock";
                #clock-cells = <0>;
                clock-frequency = <40000000>;
                linux,phandle = <0x2>;
                phandle = <0x2>;
            };
        };
    };

    /* the spi config of the can-controller itself binding everything together */
    fragment@3 {
        //target = <0xffffffff>;
        target = <&spi1>;
        can_overlay:__overlay__ {
            status = "okay";
            /* needed to avoid dtc warning */
            #address-cells = <1>;
            #size-cells = <0>;
            mcp2517fd: mcp2517fd@0 {
                reg = <0>;
                compatible = "microchip,mcp2517fd";
                pinctrl-names = "default";
                pinctrl-0 = <&can0_pin_irq>;
                spi-max-frequency = <10000000>;
                interrupt-parent = <&pio>;
                interrupts = <0 2 8>; /* PA2 / IRQ_TYPE_LEVEL_LOW */
                clocks = <&mcp2517fd_osc>;
            };
        };
    };
};

This is my attempt at trying to modify it for tegra210-p3448-0000-p3449-0000-a02.dts, but I honestly have no idea if what I put in is correct for can@1, especially for the fields regarding interrupt and pin-ctrl. Would I also have to remove the entry for spi0_0 as well, if I insert can@1?

spi@7000d400 {
    compatible = "nvidia,tegra210-spi";
    reg = <0x0 0x7000d400 0x0 0x200>;
    interrupts = <0x0 0x3b 0x4>;
    iommus = <0x32 0xe>;
    #address-cells = <0x1>;
    #size-cells = <0x0>;
    dmas = <0x53 0xf 0x53 0xf>;
    dma-names = "rx", "tx";
    nvidia,clk-parents = "pll_p", "clk_m";
    clocks = <0x27 0x29 0x27 0xf3 0x27 0xe9>;
    clock-names = "spi", "pll_p", "clk_m";
    resets = <0x27 0x29>;
    reset-names = "spi";
    status = "okay";
    linux,phandle = <0xef>;
    phandle = <0xef>;

    prod-settings {
        #prod-cells = <0x3>;

        prod {
            prod = <0x4 0xfff 0x0>;
        };

        prod_c_flash {
            status = "disabled";
            prod = <0x4 0x3f 0x7>;
        };

        prod_c_loop {
            status = "disabled";
            prod = <0x4 0xfff 0x44b>;
        };
    };

    spi0_0 {
            #address-cells = <0x1>;
            #size-cells = <0x0>;
            compatible = "spidev";
            reg = <0x0>;
            spi-max-frequency = <40000000>;
            nvidia,enable-hw-based-cs;
            nvidia,cs-setup-clk-count = <0x1e>;
            nvidia,cs-hold-clk-count = <0x1e>;
            nvidia,rx-clk-tap-delay = <0x1f>;
            nvidia,tx-clk-tap-delay = <0x0>;
    };

    can@1 {
            compatible = "microchip,mcp2517fd";
            reg = <0x0>;
            spi-max-frequency = <10000000>;
            clocks {
                    mcp2517fd_osc: mcp2517fd_osc {
                            compatible = "fixed-clock";
                            clock-frequency = <40000000>;
                    };
            };
            interrupt-parent = <0x3b>;
            interrupts = <0x0 0x3b 0x4>;
            pinctrl-names = "default";
            pinctrl-0 = <0x3b>;
    };
};

Hi,

You can have two slaves under spi device node, you do not have to remove any but please change the reg field.
Reg indicates Chip Select. You cannot have CS0 selected for both spi0_0 and can@1. Use reg = <0x0> for one and reg = <0x1> for another. And connect Chip select line based on your reg field.

Thanks,
Shubhi Garg

I am using the CANFD module of Seeed (https://www.seeedstudio.com/2-Channel-CAN-BUS-FD-Shield-for-Raspberry-Pi-p-4072.html), which’s controller is mcp2518.
My problem is,
when I test on the vehicle, some frames may lost randomly, I am not sure which part has problem.

The driver of mcp2518fd used is same as @PenguEngineer, from the raspberry pi repo.

The HW setup is,

  • SPI0_MOSI <–> SPI0_MOSI
  • SPI0_MISO <–> SPI0_MISO
  • SPI0_SCK <–> SPI0_SCK
  • SPI0_CS0 <–> SPI0_CS
  • SPI0_CS1 <–> SPI0_INT

DTS is,

clock {
    /* external 40M oscillator of mcp2518fd on SPI0.0 */
    mcp2518fd_osc: mcp2518fd_osc {
        compatible = "fixed-clock";
        #clock-cells = <0>;
        clock-frequency  = <40000000>;
        clock-accuracy = <100>;
    };
};

spi@7000d400 {
    compatible = "nvidia,tegra210-spi";
    reg = <0x0 0x7000d400 0x0 0x200>;
    interrupts = <0x0 0x3b 0x4>;
    iommus = <0x2b 0xe>;
    #address-cells = <0x1>;
    #size-cells = <0x0>;
    dmas = <0x4c 0xf 0x4c 0xf>;
    dma-names = "rx", "tx";
    nvidia,clk-parents = "pll_p", "clk_m";
    clocks = <0x21 0x29 0x21 0xf3 0x21 0xe9>;
    clock-names = "spi", "pll_p", "clk_m";
    resets = <0x21 0x29>;
    reset-names = "spi";
    status = "okay";
    linux,phandle = <0x10c>;
    phandle = <0x10c>;
    num-cs = <1>;
    cs-gpios = <0x56 19 1>; /* <&gpio TEGRA_GPIO(C, 3) GPIO_ACTIVE_LOW> */

    prod-settings {
        #prod-cells = <0x3>;

        prod {
            prod = <0x4 0xfff 0x0>;
        };

        prod_c_flash {
            status = "disabled";
            prod = <0x4 0x3f 0x7>;
        };

        prod_c_loop {
            status = "disabled";
            prod = <0x4 0xfff 0x44b>;
        };
    };

    can0:can@0 {
        compatible = "microchip,mcp2518fd";
        reg = <0x0>;
        spi-max-frequency = <20000000>;
        interrupt-parent = <0x56>;
        interrupts = <0x14 8>; /*<0xC8 8>;*/ /* IRQ_TYPE_LEVEL_LOW */
        clocks = <&mcp2518fd_osc>;
        nvidia,rx-clk-tap-delay = <0x6>;
        nvidia,enable-hw-based-cs;
        controller-data {
            nvidia,cs-setup-clk-count = <0x1e>;
            nvidia,cs-hold-clk-count = <0x1e>;
            nvidia,rx-clk-tap-delay = <0x1f>;
            nvidia,tx-clk-tap-delay = <0x0>;
            nvidia,enable-hw-based-cs;
        };
    };
};

Hi vin,

Please open a new topic for your issue. Thanks

@vin did you open a new issue? I am trying to accomplish the exact same thing - using the seeed studio board.