GPIO pin configuration issue for UART communication

I found the issue: the interrupt pins defined in the overlay DTS were different at both locations. The correct DTS for the overlays is

/dts-v1/;
/plugin/;

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

&{/} {
    metadata {
        title ="Enable SPI2 MCP2515 (CAN) support on 40 Pin GPIO Header";
        compatible = "vicharak,rk3399-axon", "rockchip,rk3399";
        category = "misc";
        exclusive = "spi2", "GPIO2_B1", "GPIO2_B2", "GPIO2_B3", "GPIO2_B4",
				"GPIO4_D6";
        description = "Enable MCP2515 on SPI2 with 12 MHz Crystal Oscillator.
INT=22";
    };

	can_mcp2515_osc: can-mcp2515-osc {
		status = "okay";
		compatible = "fixed-clock";
		clock-frequency = <12000000>;
		#clock-cells = <0>;
	};
};

&pinctrl {
	mcp2515_int_pin {
		mcp2515_int_pin: mcp2515_int_pin {
			rockchip,pins = <4 RK_PD6 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};
};

&spi2 {
	status = "okay";
	#address-cells = <1>;
	#size-cells = <0>;

	can_mcp2515: can-mcp2515@0 {
		status = "okay";
		compatible = "microchip,mcp2515";
		reg = <0>;
		interrupt-parent = <&gpio4>;
		interrupts = <RK_PD6 IRQ_TYPE_EDGE_FALLING>;
		spi-max-frequency = <10000000>;
		clocks = <&can_mcp2515_osc>;
		vdd-supply = <&vcc3v3_sys>;
		xceiver-supply = <&vcc3v3_sys>;
		pinctrl-names = "default";
		pinctrl-0 = <&mcp2515_int_pin>;
	};
};

Another important point is that you must connect the pins correctly and provide the proper power supply as mentioned in the IC’s documentation. Any incorrect pin connection will cause errors when probing the MCP251x driver.

If you face any problems, please let me know.

For pin documentation, you can refer to this.
https://docs.vicharak.in/vicharak_sbcs/vaaman/vaaman-gpio-description/#vaaman-gpio-description

I have connected the MCP2525 IC pins to Vicharak GPIO as follows:

  1. CAN2_MOSI → GPIOT_RXN27
  2. CAN2_MISO → GPIOR_174
  3. CAN2_CS → GPIOT_RXP27
  4. CAN2_SCK → GPIOR_173
    Where should I connect CAN2_INT (to which GPIO)?

Hello @Avi_Shihora @vatsal any updates on this

You are testing the MCP2515 IC using the SoC GPIOs Header, so your pin connections should be as follows:

  • INT → GPIO4_D6 → Pin 37 on SoC
  • SCK → GPIO2_B3 → Pin 7 on SoC
  • MOSI → GPIO2_B2 → Pin 29 on SoC
  • MISO → GPIO2_B1 → Pin 31 on SoC
  • CS → GPIO2_B4 → Pin 33 on SoC

For your reference, all of these pins are already defined in the DTS overlays for SPI2 on the processor.

Please note that the pins GPIOT_RXN27, GPIOR_174, GPIOT_RXP27, and GPIOR_173 are FPGA pins. These are only useful when working with Periplex. They are not used when running applications directly on the SoC (processor).

For Soc pinout guide , Documentation references : Vaaman GPIO Description | Vicharak

For FPGA pinout guide , Documentation references : documentaion:Vaaman GPIO Description | Vicharak

Refer this pdf for more information : https://docs.vicharak.in/_static/files/Vaaman0.3_Pinout_Guide_Rev0.3.pdf

Thank you, I will use the SoC GPIO header pins and check.

  1. I used the following DTSO file:

/dts-v1/;
/plugin/;

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

&{/} {
metadata {
title =“Enable SPI2 MCP2515 (CAN) support on 40 Pin GPIO Header”;
compatible = “vicharak,rk3399-axon”, “rockchip,rk3399”;
category = “misc”;
exclusive = “spi2”, “GPIO2_B1”, “GPIO2_B2”, “GPIO2_B3”, “GPIO2_B4”,
“GPIO4_D6”;
description = “Enable MCP2515 on SPI2 with 12 MHz Crystal Oscillator. INT=22”;
};

can_mcp2515_osc: can-mcp2515-osc {
    status = "okay";
    compatible = "fixed-clock";
    clock-frequency = <12000000>;
    #clock-cells = <0>;
};

};

&pinctrl {
mcp2515_int_pin {
mcp2515_int_pin: mcp2515_int_pin {
rockchip,pins = <4 RK_PD6 RK_FUNC_GPIO &pcfg_pull_none>;
};
};
};

&spi2 {
status = “okay”;
#address-cells = <1>;
#size-cells = <0>;

can_mcp2515: can-mcp2515@0 {
    status = "okay";
    compatible = "microchip,mcp2515";
    reg = <0>;
    interrupt-parent = <&gpio4>;
    interrupts = <RK_PD6 IRQ_TYPE_EDGE_FALLING>;
    spi-max-frequency = <10000000>;
    clocks = <&can_mcp2515_osc>;
    vdd-supply = <&vcc3v3_sys>;
    xceiver-supply = <&vcc3v3_sys>;
    pinctrl-names = "default";
    pinctrl-0 = <&mcp2515_int_pin>;
};

};

  1. After that, I ran the following commands:

cpp -nostdinc -undef -x assembler-with-cpp -E
-I /usr/src/linux-headers-$(uname -r)/include
-I /usr/lib/modules/$(uname -r)/build/include
rk3399-vaaman-spi2-mcp2515.dtso -o rk3399-vaaman-spi2-mcp2515.dtsi

dtc -I dts -O dtb rk3399-vaaman-spi2-mcp2515.dtsi -o rk3399-vaaman-spi2-mcp2515.dtbo

sudo cp rk3399-vaaman-spi2-mcp2515.dtbo /boot/overlays-$(uname -r)/

sudo u-boot-update

sudo reboot

  1. After rebooting, I checked with the following commands, but can0 was not showing up:

dmesg | grep mcp2515

ls /dev/spidev*

Output:

/dev/spidev0.0 /dev/spidev2.0

ip link | grep can

What is the dmesg log when you insert the mcp251x.ko module? Please provide it as a file named dmesg.txt by running the following command:

sudo dmesg > dmesg.txt

dmesg.txt (45.7 KB)

Please check the dmesg file

First, insert the mcp251x.ko module the same way you did before. After that, I will check the dmesg log to identify the error you faced during insmod. You have done this step in the past, so please insert the module manually and then send me the dmesg log, because right now I don’t see any messages related to mcp251x in your dmesg

Okay I will check it again and let you know

demesg1.txt (45.5 KB)

vicharak@vicharak:~/mcp251x-driver$ ls
Makefile mcp251x.c.2 mcp251x.mod.c modules.order
mcp251x.c mcp251x.ko mcp251x.mod.o Module.symvers
mcp251x.c.1 mcp251x.mod mcp251x.o
vicharak@vicharak:~/mcp251x-driver$ sudo dmesg > demesg1.txt
vicharak@vicharak:~/mcp251x-driver$ ls -h mcp251x.ko
mcp251x.ko
vicharak@vicharak:~/mcp251x-driver$ sudo insmod mcp251x.ko
vicharak@vicharak:~/mcp251x-driver$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
link/ether fe:9c:03:59:66:57 brd ff:ff:ff:ff:ff:ff
3: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000
link/ether 22:08:29:9a:58:3d brd ff:ff:ff:ff:ff:ff
4: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000
link/ether f4:3c:3b:3c:82:e4 brd ff:ff:ff:ff:ff:ff
vicharak@vicharak:~/mcp251x-driver$ dmesg | grep spi
[ 12.075653] rockchip-spi ff1d0000.spi: no high_speed pinctrl state
[ 12.076279] rockchip-spi ff1d0000.spi: probed, poll=0, rsd=0, cs-inactive=0, ready=0
[ 12.076648] rockchip-spi ff1e0000.spi: no high_speed pinctrl state
[ 12.077405] rockchip-spi ff1e0000.spi: chipselect 0 already in use
[ 12.077429] spi_master spi1: spi_device register error /spi@ff1e0000/spi-flash@0
[ 12.077444] spi_master spi1: Failed to create SPI device for /spi@ff1e0000/spi-flash@0
[ 12.077452] rockchip-spi ff1e0000.spi: probed, poll=0, rsd=0, cs-inactive=0, ready=0
[ 12.303453] pca953x 7-0024: spi mode set properly
[ 1294.373376] mcp251x spi1.0: MCP251x didn’t enter in conf mode after reset
[ 1294.373541] mcp251x spi1.0: Probe failed, err=110
[ 1294.375460] mcp251x: probe of spi1.0 failed with error -110
vicharak@vicharak:~/mcp251x-driver$ dmesg | grep mcp2515
vicharak@vicharak:~/mcp251x-driver$ dmesg | grep mcp251
[ 1293.356004] mcp251x: loading out-of-tree module taints kernel.
[ 1294.373376] mcp251x spi1.0: MCP251x didn’t enter in conf mode after reset
[ 1294.373541] mcp251x spi1.0: Probe failed, err=110
[ 1294.375460] mcp251x: probe of spi1.0 failed with error -110
vicharak@vicharak:~/mcp251x-driver$ ls /d
data/ dev/
vicharak@vicharak:~/mcp251x-driver$ ls /dev/spidev*
/dev/spidev0.0 /dev/spidev2.0
vicharak@vicharak:~/mcp251x-driver$

I can see that your probe has failed. This could be due to an issue with the connections, the overlays, or even the hardware itself.

Please provide me with a screenshot of Manage Overlays from vicharak-config.

Steps:

  1. Run sudo vicharak-config
  2. Select Overlays
  3. Open Manage Overlays

Additionally, I need a photo of how you have connected the MCP2515 CAN module to the Vaaman board, so I can verify your hardware connections.




Turn off the “Enable SPI 2 Controller on 40-pin GPIO” overlay because the &spi2 node cannot be used twice in the device tree. Make sure not to disable the “Enable SPI 2 MCP2515 (CAN) support on 40-pin GPIO header” overlay. After these changes, it should work.

Now it is showing can0. I am connecting the MCP2515 module with 3.3V.

can_receive.zip (803 Bytes)

I am running this code to receive data from the USB-CAN-TOOL, but I am not receiving any data.

Simple send/receive CAN frames

To use cansend, candump, and other CAN utilities, you need to install the can-utils package. These tools provide user-space utilities for interacting with CAN interfaces via the Linux SocketCAN subsystem.

sudo apt install can-utils
  1. Identify CAN Interfaces:

    • You can list available CAN interfaces using:

      ip link show
      
  2. Bring Up a CAN Interface:

    • To bring up a CAN interface, use the following command:

      sudo ip link set <interface> type can bitrate <bitrate_value>
      
    • Example:

      • to bring up can0 with a bitrate of 500 kbps, you would run:
      sudo ip link set can0 up type can bitrate 500000
      
      • can0 is the name of the CAN interface,
      • 500000 is the bitrate in bits per second.
  3. Sending CAN Frames:

    • To send a CAN frame, use the cansend command:

      sudo cansend <interface> <arbitration_id>#<data_bytes>
      
    • <interface>: The CAN interface name (like can0).

    • <arbitration_id>: The CAN identifier (11-bit or 29-bit).

      • Standard Frame: 11-bit ID (range: 0x0000x7FF).
      • Extended Frame: 29-bit ID (range: 0x000000000x1FFFFFFF).
    • <data_bytes>: Up to 8 data bytes in hexadecimal format, concatenated without spaces.

    • Example:

      • Send a standard frame with ID 0x7E8 and 7 bytes of data:
      sudo cansend can0 7E8#11223344556677
      
      • Send an extended frame with ID 0x18DAF110 and 8 bytes of data:
      sudo cansend can0 18DAF110#1122334455667788
      
  4. Receiving CAN Frames:\

    • To receive CAN frames, use the candump command

      sudo candump <interface>
      
    • Example:

      • Listen on can0:
      sudo candump can0
      
      • To filter by a specific ID, use:
      sudo candump can0,7E8:7FF
      
      • 7E8:7FF means show only messages with ID 0x7E8