Jump to content

MCP2518FD not working with OrangePI


garinus

Recommended Posts

Hi,

we are trying to make our Orange PI zero with custom shield working with an MCP2518FD on board with SN65HVD23 tranceiver.
We started from the normal kernel already built, but according to this thread we found that it must be activated at compile time.

 

So we downloaded the repo and built the Armbian image with this CAN configuration:

 

CONFIG_CAN=y
CONFIG_CAN_RAW=y
CONFIG_CAN_BCM=y
CONFIG_CAN_GW=y
CONFIG_CAN_J1939=y

#
# CAN Device Drivers
#
CONFIG_CAN_VCAN=y
CONFIG_CAN_VXCAN=y
CONFIG_CAN_SLCAN=y
CONFIG_CAN_DEV=y
CONFIG_CAN_CALC_BITTIMING=y
CONFIG_CAN_FLEXCAN=y
CONFIG_CAN_GRCAN=y
CONFIG_CAN_SUN4I=y
CONFIG_CAN_TI_HECC=y
CONFIG_CAN_C_CAN=y
CONFIG_CAN_C_CAN_PLATFORM=m
CONFIG_CAN_CC770=y
CONFIG_CAN_CC770_ISA=m
CONFIG_CAN_CC770_PLATFORM=m
CONFIG_CAN_IFI_CANFD=y
CONFIG_CAN_M_CAN=y
CONFIG_CAN_M_CAN_PLATFORM=y
CONFIG_CAN_M_CAN_TCAN4X5X=y
CONFIG_CAN_RCAR=y
CONFIG_CAN_RCAR_CANFD=y
CONFIG_CAN_SJA1000=y
CONFIG_CAN_SJA1000_ISA=m
CONFIG_CAN_SJA1000_PLATFORM=m
CONFIG_CAN_SOFTING=y

#
# CAN SPI interfaces
#
CONFIG_CAN_HI311X=y
CONFIG_CAN_MCP251X=y
# end of CAN SPI interfaces

#
# CAN USB interfaces
#
CONFIG_CAN_8DEV_USB=y
CONFIG_CAN_EMS_USB=y
CONFIG_CAN_ESD_USB2=y
CONFIG_CAN_GS_USB=y
CONFIG_CAN_KVASER_USB=y
CONFIG_CAN_MCBA_USB=y
CONFIG_CAN_PEAK_USB=y
CONFIG_CAN_UCAN=y
# end of CAN USB interfaces

CONFIG_CAN_DEBUG_DEVICES=y
# end of CAN Device Drivers

 

we currently have two problems:

1. At the physical interface level, the driver in this kernel version works only with MCP2515, but not with our MCP2518FD.

 

After reading the following tread we found the original repository from which we copied the folder with the MCP2518FD drivers, but we can't compile them and include them in our kernel (because we don't know how to do it).

 

2. We cannot activate the CanBus interface with these commands (we get Cannot find device "can0"):

ip link set can0 type can bitrate 2000000 fd off
ip link can0 set can0 up

 

 

Is there a guide on how to build and include the drivers we need?

Once the driver has been loaded we could test the .dtbo and see if the MCP initializes correctly.

 

Link to comment
Share on other sites

Hi,
after having performed some tests I managed to have the mcp2518fd working with Armbian and Orange PI zero.

In attachment there is a patch that works with the current version.

 

The driver is the same as in the main kernel version:
https://github.com/torvalds/linux/tree/master/drivers/net/can/spi/mcp251xfd

 

after compiling the kernel it is necessary to add the following custom overlay in /boot/overlay-user

/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  = <20000000>;
                        };
                };
        };

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

        fragment@2 {
                target = <&spi1>;
                overlay {
                        #address-cells = <1>;
                        #size-cells = <0>;
                        status = "okay";
                        mcp2515 {
                                reg = <0>;
                                compatible = "microchip,mcp2518fd";
                                pinctrl-names = "default";
                                pinctrl-0 = <&can0_pin_irq>;
                                spi-max-frequency = <10000000>;
                                interrupt-parent = <&pio>;
                                interrupts = <0 10 2>; /* PA10 IRQ_TYPE_EDGE_FALLING */
                                clocks = <&can0_osc_fixed>;
                                status = "okay";
                        };
                };
        };
};

In my case the interrupt pin is on PA10 and the crystal on mcp is 20MHz, change them if necessary.


copile it with armbian-add-overlay, then after the reboot launch the following commands:
 ip link set can0 type can bitrate 500000
 ip link up can0
 
where 500000 is the bitrate of your canBus.
 
It is possible to test the connection with:
 cansend can0 123#1122334455667788
or
 candump can0

mcp2518fd.patch

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines