How to configure mcp2515 CAN module on khadas edge v platfrom

How to configure mcp2515 CAN module on khadas edge v platfrom ?
i am working on rk3399-khadas-edge.dtsi for can module interface.
i was added related mcp2515
&spi3 {
status = “okay”;
cs-gpios = <&gpio1 17 GPIO_ACTIVE_LOW>, <&gpio1 16 GPIO_ACTIVE_LOW>;
max-freq = <48000000>;
#address-cells = <0x1>;
#size-cells = <1>;

can_mcp2515: can-mcp2515@0 {
status = “okay”;
compatible = “microchip,mcp2515”;
reg = <0>;
interrupt-parent = <&gpio3>;
interrupts = <25 2>;
spi-max-frequency = <48000000>;
clocks = <&can_mcp2515_osc>;
vdd-supply = <&vcc3v3_sys>;
xceiver-supply = <&vcc3v3_sys>;
pinctrl-names = “default”;
pinctrl-0 = <&mcp2515_int_pin>;

can_mcp2515_osc: can-mcp2515-osc {
compatible = “fixed-clock”;
clock-frequency = <8000000>; //8MHz
#clock-cells = <0>;
};

mcp2515_int_pin: mcp2515_int_pin {
rockchip,pins = <3 25 0 &pcfg_pull_none>;
};

};
};

and also i added this drivers in
kedge_defconfig

CONFIG_CAN=y
CONFIG_CAN_VCAN=y
CONFIG_CAN_MCP251X=y
CONFIG_CAN_DEBUG_DEVICES=y
CONFIG_SPI_DEBUG=y

**is this defconfig is correct or not.

after recompiling image was not booting into khadas edge v board.

please help me to solve this issue.

@ramesh hello,
Just a moment, I’m verifying.

@ramesh hi,
I have made changes according to your configuration, and can now enter the system normally. Please configure it according to the following patch:

diff --git a/arch/arm64/boot/dts/rockchip/rk3399-khadas-edge.dtsi b/arch/arm64/boot/dts/rockchip/rk3399-khadas-edge.dtsi
index 16c0ac7c5109..a621ab809f7c 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399-khadas-edge.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3399-khadas-edge.dtsi
@@ -317,6 +317,13 @@
                trig_temp_level1 = <60>;
                trig_temp_level2 = <70>;
        };
+       can_mcp2515_osc: can-mcp2515-osc {
+      compatible = "fixed-clock";
+      clock-frequency = <8000000>; //8MHz
+      clock-output-names = "can_mcp2515_osc";
+      #clock-cells = <0>;
+    };
+
 };

 &dmac_bus {
@@ -1153,14 +1160,42 @@
                        rockchip,pins = <1 RK_PC7 RK_FUNC_GPIO &pcfg_pull_up>; /* GPIO1_C7 */
                };
        };
+
+       mcp2515_int{
+               mcp2515_int_pin: mcp2515_int_pin {
+                       rockchip,pins = <3 25 0 &pcfg_pull_none>;
+               };
+       };
+
 };

 &spi3 {
-       status = "disabled";
+       status = "okay";

-       cs-gpios = <&gpio1 17 GPIO_ACTIVE_LOW>, <&gpio1 16 GPIO_ACTIVE_LOW>;
-       max-freq = <48000000>;
+//     cs-gpios = <&gpio1 18 GPIO_ACTIVE_LOW>;
+//
+//     max-freq = <48000000>;
+       max-freq = <50000000>;
+//     spi_test@00 {
+//             compatible = "rockchip,spidev";
+//             reg = <0>;
+//             spi-max-frequency = <5000000>;
+//             status = "okay";
+//     };
+       can_mcp2515: can-mcp2515@0 {
+               status = "okay";
+               compatible = "microchip,mcp2515";
+               reg = <0>;
+               interrupt-parent = <&gpio3>;
+               interrupts = <25 2>;
+               spi-max-frequency = <48000000>;
+               clocks = <&can_mcp2515_osc>;
+               vdd-supply = <&vcc3v3_sys>;
+               xceiver-supply = <&vcc3v3_sys>;
+               pinctrl-names = "default";
+               pinctrl-0 = <&mcp2515_int_pin>;
+       };

 };

kedge_defconfig:
CONFIG_CAN=y
CONFIG_CAN_VCAN=y
CONFIG_CAN_MCP251X=y
CONFIG_CAN_DEBUG_DEVICES=y
CONFIG_SPI_DEBUG=y

Because I don’t have MCP2515 peripheral module, I can’t test the function ! ! !

added code in rk3399-khadas-edge.dtsi
drivers also added in kedge_defconfig.
after recompiling , image booted into board
when i am doing ifconfig -a
can0 is not showing…
i am facing issue with mcp251x.c driver
root@Khadas:~# dmesg | grep “spi3”
[ 2.440928] rockchip-spi ff350000.spi: registered master spi32766 (dynamic)
[ 2.441058] spi spi32766.0: setup mode 0, 8 bits/w, 48000000 Hz max → 0
[ 2.441268] rockchip-spi ff350000.spi: registered child spi32766.0
****[ 2.442817] mcp251x: probe of spi32766.0 failed with error -2

please consider this issue and prove the solution

@ramesh hi,
Just a moment, I’m verifying.

@ramesh hi,
I found a peripheral module MCP2515. It has been tested that can0 nodes have been generated:

khadas@Khadas:~$ ifconfig -a
can0: flags=128<NOARP>  mtu 16
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (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

dummy0: flags=130<BROADCAST,NOARP>  mtu 1500
        ether 7a:db:bc:83:91:e3  txqueuelen 1000  (Ethernet)
        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

eth0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 98:76:54:32:1c:77  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4  bytes 584 (584.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 24  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        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

wlan0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether cc:4b:73:85:3b:68  txqueuelen 1000  (Ethernet)
        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

The configuration is the same as the patch I sent.
I didn’t find the mistake you gave me

suggest:
1、Check whether the device tree configuration is the same.
2、Check whether the wiring is loose
3、number 22 of the 40gpios pin is connected to the data input pin of the module MCP2515;
number 23 of the 40gpios pin is connected to the data output pin of the module MCP2515

still i am facing the same issues
[ 2.428796] mcp251x: probe of spi32766.0 failed with error -2

what is voltage of yours spi pins?
can you please share your rk3399-khadas-edge.dtsi file…

@ramesh


The voltage indicated by the arrow is 3.3V.

rk3399-khadas-edge.dtsi sharing link:
https://dl.khadas.com/.test/rk3399-khadas-edge.dtsi

@ramesh
Interrupt pin connected to i2s0_ LRCK_ RX

@ramesh

diff --git a/arch/arm64/configs/kedge_defconfig b/arch/arm64/configs/kedge_defconfig
index 960319635eff..ba3a85310c1b 100644
--- a/arch/arm64/configs/kedge_defconfig
+++ b/arch/arm64/configs/kedge_defconfig
@@ -124,6 +124,9 @@ CONFIG_BRIDGE=y
 CONFIG_NET_SCHED=y
 CONFIG_NET_CLS_CGROUP=y
 CONFIG_CGROUP_NET_PRIO=y
+CONFIG_CAN=y
+CONFIG_CAN_VCAN=y
+CONFIG_CAN_MCP251X=y
 CONFIG_BT=y
 CONFIG_BT_RFCOMM=y
 CONFIG_BT_HIDP=y
(END)

@ramesh
Be sure to pay attention to whether the wiring is unstable

i am tried same thing as you mention in the patches but still we are not getting can0 .
can you please tell the khadas edge v board SPI pin voltages of RXD ,TXD and chip select pins ?

connections between mcp2515 module and board is proper.wiring is correct.

Hi @ramesh
Are you a peripheral module connected by DuPont cable?

@ramesh hi,
The following is my newly modified configuration, which is more stable:
具体节点配置信息

    clk16m: clk16m {
      compatible = "fixed-clock";
      clock-frequency = <16000000>; //8MHz
      clock-output-names = "clk16m";
      #clock-cells = <0>;
    };


 
    can0 {
        can0_pins: can-pins {
            rockchip,pins = <3 25 RK_FUNC_GPIO &pcfg_pull_none>;
        };
    };

&spi3 {
    status = "okay";

//  cs-gpios = <&gpio1 18 GPIO_ACTIVE_LOW>;
//
//  max-freq = <48000000>;
    max-freq = <50000000>;
//  spi_test@00 {
//      compatible = "rockchip,spidev";
//      reg = <0>;
//      spi-max-frequency = <5000000>;
//      status = "okay";
//  };
    can0: can@0 {
        status = "okay";
        compatible = "microchip,mcp2515";
        reg = <0>;
        interrupt-parent = <&gpio3>;
        interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
        spi-max-frequency = <10000000>;
        clocks = <&clk16m>;
    //  vdd-supply = <&vcc3v3_sys>;
    //  xceiver-supply = <&vcc3v3_sys>;
        pinctrl-names = "default";
        pinctrl-0 = <&can0_pins>;
    };

};

+++ b/arch/arm64/configs/kedge_defconfig
@@ -124,6 +124,9 @@ CONFIG_BRIDGE=y
 CONFIG_NET_SCHED=y
 CONFIG_NET_CLS_CGROUP=y
 CONFIG_CGROUP_NET_PRIO=y
+CONFIG_CAN=y
+CONFIG_CAN_VCAN=y

patch文件:

diff --git a/arch/arm64/boot/dts/rockchip/rk3399-khadas-edge.dtsi b/arch/arm64/boot/dts/rockchip/rk3399-khadas-edge.dtsi
index 16c0ac7c5109..cd972d9a3bf8 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399-khadas-edge.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3399-khadas-edge.dtsi
@@ -317,6 +317,13 @@
        trig_temp_level1 = <60>;
        trig_temp_level2 = <70>;
    };
+   clk16m: clk16m {
+      compatible = "fixed-clock";
+      clock-frequency = <16000000>; //8MHz
+      clock-output-names = "clk16m";
+      #clock-cells = <0>;
+    };
+
 };

 &dmac_bus {
@@ -1153,14 +1160,42 @@
            rockchip,pins = <1 RK_PC7 RK_FUNC_GPIO &pcfg_pull_up>; /* GPIO1_C7 */
        };
    };
+
+   can0 {
+       can0_pins: can-pins {
+           rockchip,pins = <3 25 RK_FUNC_GPIO &pcfg_pull_none>;
+       };
+   };
+
 };


 &spi3 {
-   status = "disabled";
+   status = "okay";

-   cs-gpios = <&gpio1 17 GPIO_ACTIVE_LOW>, <&gpio1 16 GPIO_ACTIVE_LOW>;
-   max-freq = <48000000>;
+// cs-gpios = <&gpio1 18 GPIO_ACTIVE_LOW>;
+//
+// max-freq = <48000000>;
+   max-freq = <50000000>;
+// spi_test@00 {
+//     compatible = "rockchip,spidev";
+//     reg = <0>;
+//     spi-max-frequency = <5000000>;
+//     status = "okay";
+// };
+   can0: can@0 {
+       status = "okay";
+       compatible = "microchip,mcp2515";
+       reg = <0>;
+       interrupt-parent = <&gpio3>;
+       interrupts = <25 IRQ_TYPE_EDGE_FALLING>;
+       spi-max-frequency = <10000000>;
+       clocks = <&clk16m>;
+   //  vdd-supply = <&vcc3v3_sys>;
+   //  xceiver-supply = <&vcc3v3_sys>;
+       pinctrl-names = "default";
+       pinctrl-0 = <&can0_pins>;
+   };

 };

diff --git a/arch/arm64/configs/kedge_defconfig b/arch/arm64/configs/kedge_defconfig
index 960319635eff..ba3a85310c1b 100644
--- a/arch/arm64/configs/kedge_defconfig
+++ b/arch/arm64/configs/kedge_defconfig
@@ -124,6 +124,9 @@ CONFIG_BRIDGE=y
 CONFIG_NET_SCHED=y
 CONFIG_NET_CLS_CGROUP=y
 CONFIG_CGROUP_NET_PRIO=y
+CONFIG_CAN=y
+CONFIG_CAN_VCAN=y

@ramesh
Now,I test can0 here. It is very stable.



@ramesh
You can also compare this Make the latest changes to the rk3399-khadas-edge.dtsi file or replace rk3399 khadas edge dtsi
link:
https://dl.khadas.com/.test/rk3399-khadas-edge.dtsi

@ramesh
According to my latest configuration changes today, how is the situation? :smile:

i was replced my rk3399-khadas-edge.dtsi file with your dtsi
++arch/arm64/configs/kedge_defconfig
CONFIG_NET_SCHED=y
CONFIG_NET_CLS_CGROUP=y
CONFIG_CGROUP_NET_PRIO=y
CONFIG_CAN=y
CONFIG_CAN_VCAN=y
all this drivers are present.
after recompilation of source code.image booted into board.
Starting kernel …

[ 2.403495] rockchip-pcie f8000000.pcie: PCIe link training gen1 timeout!
[ 2.404117] rockchip-pcie f8000000.pcie: deferred probe failed
[ 2.407381] rk-vcodec ff650000.vpu_service: could not find power_model node
[ 2.409344] rk-vcodec ff660000.rkvdec: could not find power_model node
[ 2.422803] mali ff9a0000.gpu: Failed to get regulator
[ 2.423264] mali ff9a0000.gpu: Power control initialization failed
[ 2.444853] rk_gmac-dwmac fe300000.ethernet: cannot get clock clk_mac_speed
[ 2.591528] rockchip-dwc3 usb0: failed to get drvdata dwc3
[ 2.597367] rockchip-dwc3 usb1: fail to get drvdata hcd
[ 2.689838] rockchip-pinctrl pinctrl: pin gpio1-18 already requested by ff350000.spi; cannot claim for 4-001b
[ 2.690713] rockchip-pinctrl pinctrl: pin-50 (4-001b) status -22
[ 2.691255] rockchip-pinctrl pinctrl: could not request pin 50 (gpio1-18) from group pmic-dvs2 on device rockchip-pinctrl
[ 2.692260] rk808 4-001b: Error applying setting, reverse things back
[ 4.271609] cw201x 8-0062: design_capacity missing!
[ 4.272230] cw_bat_probe cw_init error
[ 4.274273] bq25700-charger 8-006b: Cannot read chip ID.
[ 4.279286] rk_tsadcv2_temp_to_code: Invalid conversion table: code=1023, temperature=2147483647
[ 4.312303] cpu cpu0: failed to find power_model node
[ 4.316175] cpu cpu4: failed to find power_model node
[ 4.321499] vccio_sd: unsupportable voltage range: 3300000-3000000uV
[ 4.384550] rockchip-dmc dmc: unable to get devfreq-event device : dfi
[ 4.403363] Error: Driver ‘ov4689’ is already registered, aborting…
[ 4.404001] Error: Driver ‘ov7750’ is already registered, aborting…
[ 4.404611] Error: Driver ‘ov13850’ is already registered, aborting…
[ 4.405392] Error: Driver ‘sc031gs’ is already registered, aborting…
[ 4.412419] zswap: default zpool zbud not available
[ 4.412855] zswap: pool creation failed
[ 4.424364] rockchip-vop ff900000.vop: missing rockchip,grf property
[ 4.425402] rockchip-vop ff8f0000.vop: missing rockchip,grf property
[ 4.426931] i2c i2c-9: of_i2c: modalias failure on /hdmi@ff940000/ports
[ 4.430219] i2c i2c-10: of_i2c: modalias failure on /dp@fec00000/ports
[ 4.625583] rockchip-dmc dmc: Failed to get leakage
[ 4.626265] rockchip-dmc dmc: Failed to get pvtm
[ 4.627381] rockchip-dmc dmc: failed to get vop pn to msch rl
[ 4.628797] rockchip-dmc dmc: could not find power_model node
[ 4.639112] rk-hdmi-dp-sound hdmi-dp-sound: control 3:0:0:ELD:0 is already present
[ 4.639844] hdmi-audio-codec hdmi-audio-codec.7.auto: ASoC: Failed to add ELD: -16
[ 6.423741] cgroup: cgroup2: unknown option “nsdelegate”
[ 12.549555] CONFIG-ERROR) dhd_conf_set_intiovar: txbf setting failed -23
[ 12.720591] [drm:dw_hdmi_rockchip_set_property] ERROR failed to set rockchip hdmi connector property
[ 12.721428] [drm:dw_hdmi_rockchip_set_property] ERROR failed to set rockchip hdmi connector property
[ 12.722264] [drm:dw_hdmi_rockchip_set_property] ERROR failed to set rockchip hdmi connector property
[ 12.723090] [drm:dw_hdmi_rockchip_set_property] ERROR failed to set rockchip hdmi connector property
[ 12.724232] [drm:dw_hdmi_rockchip_set_property] ERROR failed to set rockchip hdmi connector property
[ 12.725069] [drm:dw_hdmi_rockchip_set_property] ERROR failed to set rockchip hdmi connector property
[ 19.302820] rc.local[995]: SSH configure keys
[ 21.484199] rc.local[995]: Creating SSH2 RSA key; this may take some time …
[ 21.495371] rc.local[995]: 2048 SHA256:UNxsCkynGyboT+07O+U4wjBLxZzJVOLs8Jw6TDb0J+k root@Khadas (RSA)
[ 21.510357] rc.local[995]: Creating SSH2 ECDSA key; this may take some time …
[ 21.521498] rc.local[995]: 256 SHA256:jci+YVOv5pQSY0l3Z36FxvTGuFR55XeJ4yj5sBDh+uY root@Khadas (ECDSA)
[ 21.537012] rc.local[995]: Creating SSH2 ED25519 key; this may take some time …
[ 21.543459] rc.local[995]: 256 SHA256:mZeKGxjSXOelyh9fYFxQHxpKw+Qs3TT4h2YUrD23Epo root@Khadas (ED25519)
[ 23.889171] rc.local[995]: SSH configure keys DONE

Ubuntu 18.04.6 LTS Khadas ttyFIQ0

Khadas login: khadas
Password:
Last login: Mon Jun 13 12:16:16 IST 2022 on ttyFIQ0

Welcome to Fenix 1.0.11 Ubuntu 18.04.6 LTS Linux 4.4.194


| |/ / |__ __ _ | | __ _ ___ | ____|| | __ _ ___ \ \ / /
| ’ /| '_ \ / |/ _ |/ / __| | _| / _ |/ ` |/ _ _\ \ / /
| . | | | | (| | (| | (| _ \ | || (| | (| | /\ V /
||__| ||_,|_,|_,|
/ |_,|__, |_| _/
|
__/

To run a command as administrator (user “root”), use "sudo ".
See “man sudo_root” for details.

khadas@Khadas:~$ uname -a
Linux Khadas 4.4.194 #43 SMP Mon Jun 13 12:13:40 IST 2022 aarch64 aarch64 aarch64 GNU/Linux
khadas@Khadas:~$ ifconfig -a
dummy0: flags=130<BROADCAST,NOARP> mtu 1500
ether c6:35:24:00:ee:c2 txqueuelen 1000 (Ethernet)
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

eth0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether c8:63:14:71:19:b3 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2 bytes 432 (432.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 24

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1 (Local Loopback)
RX packets 10 bytes 1570 (1.5 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10 bytes 1570 (1.5 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

wlan0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether d4:9c:dd:36:0c:ec txqueuelen 1000 (Ethernet)
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

khadas@Khadas:~$ dmesg | grep “mcp”
[ 2.433606] mcp251x spi32766.0: setup mode 0, 8 bits/w, 10000000 Hz max → 0
[ 2.433620] mcp251x spi32766.0: Looking up vdd-supply from device tree
[ 2.433632] mcp251x spi32766.0: Looking up vdd-supply property in node /spi@ff350000/can@0 failed
[ 2.433653] mcp251x spi32766.0: Looking up xceiver-supply from device tree
[ 2.433664] mcp251x spi32766.0: Looking up xceiver-supply property in node /spi@ff350000/can@0 failed
khadas@Khadas:~$

can0 was not showing.

@ramesh ,
Have you directly replaced your original device tree file with the one I gave you?