Problem using MCP2515

Hi

I’m using Colibri iMX6 Solo 256MB module in combination with the Colibri Evaluation Carrier Board. I have build kernel and rootfs using Yocto and “bitbake -k console-tdx-image” and repository toradex-bsp-platform and branch LinuxImageV2.7. The HW is up and running and now I try to use CAN using MCP2515 (will later switch to the build-in CAN module). I think that I’m unable to get it up and running correctly.

I have tried to follow the guide here without success: https://developer.toradex.com/knowledge-base/can-(linux)

At boot I can’t see the MCP2515 driver getting loaded like “mcp251x spi3.0: probed”. Some other CAN and SPI related things are still there:

[    1.164641] spi_imx 2014000.ecspi: probed
[    1.171547] vcan: Virtual CAN interface driver
[    1.178032] CAN device driver interface
[    1.183944] spi3.0 supply vdd not found, using dummy regulator
[    1.191762] spi3.0 supply xceiver not found, using dummy regulator
...
[    2.184205] can: controller area network core (rev 20120528 abi 9)
[    2.192296] NET: Registered protocol family 29
[    2.198696] can: raw protocol (rev 20120528)
[    2.204898] can: broadcast manager protocol (rev 20120528 t)
[    2.212469] can: netlink gateway (rev 20130117) max_hops=1

The driver might be there?

root@colibri-imx6:~# zcat /proc/config.gz | grep CONFIG_CAN_MCP251X
CONFIG_CAN_MCP251X=y

Try to start can0, the second command gives no reply

root@colibri-imx6:~# ip link set can0 type can bitrate 250000
root@colibri-imx6:~# ifconfig can0 up


root@colibri-imx6:~# ip -details link show can0
2: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10
    link/can  promiscuity 0
    can state ERROR-ACTIVE restart-ms 0
    bitrate 250000 sample-point 0.875
    tq 250 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
    mcp251x: tseg1 3..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
    clock 8000000numtxqueues 1 numrxqueues 1

root@colibri-imx6:~# cat /proc/interrupts | grep mcp251x
130:          0  gpio-mxc  27 Edge      mcp251x

root@colibri-imx6:~# ip addr
2: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN group default qlen 10
    link/can

I looked at the device tree file, ./tmp-glibc/work-shared/colibri-imx6/kernel-source/arch/arm/boot/dts/imx6dl-colibri-eval-v3.dts, and found this.

&ecspi4 {
	status = "okay";

	mcp258x0: mcp258x@1 {
		compatible = "microchip,mcp2515";
		reg = <0>;
		clocks = <&clk16m>;
		interrupt-parent = <&gpio3>;
		interrupts = <27 0x2>;
		spi-max-frequency = <10000000>;
		status = "okay";
	};
	spidev0: spidev@1 {
		compatible = "toradex,evalspi";
		reg = <0>;
		spi-max-frequency = <23000000>;
		status = "disabled";
	};
};

According to the link above it should be can0:can@1, so I changed that, rebuild kernel and images (“bitbake -f -c compile virtual/kernel” and “bitbake -k console-tdx-image”) and used the new uImage, dtb-file and rootfs. No change.

  1. What is “mcp258x0: mcp258x@1” stand for? Is this right?
  2. What is wrong with my setup?

What exact hardware and software versions of things are you talking about?

Colibri iMX6 Solo 256MB v1.1A and Colibri Evaluation Carrier Board v3.2B.

According to https://developer.toradex.com/knowledge-base/can-(linux) MCP251x should be enabled from v2.6 and I’m using v2.7.

The SW is from the Yocto build described above. More details:

repo init -u http://git.toradex.com/toradex-bsp-platform.git -b LinuxImageV2.7
repo sync
. export

Edit conf/local.conf

MACHINE ?= "colibri-imx6"

Added to the end:

ACCEPT_FSL_EULA = "1"
DISTRO_FEATURES_remove = "x11 wayland"
IMAGE_INSTALL_remove = "eglinfo-x11"
IMAGE_INSTALL_append = " imx-gpu-viv kernel-module-imx-gpu-viv fsl-gpu-sdk packagegroup-fsl-tools-gpu mtdev tslib gstreamer gst-plugins-base gdb nano"

Build:

bitbake -k console-tdx-image

Have you tried it with any of our off-the-shelf images at all?

I have in a way “solved” the problem. I started using the “cansend” command (cansend can0 1F334455#1122334455667788) to send CAN data and it didn’t work, wrong identifier and data was the result.

Then I tried a c-code example (SocketCAN example | lnguin) instead and that worked. I also enabled the FlexCAN1 and tried cansend and my own application, same result, only my application transfered the correct data.

I have tried cansend both in Toradex v2.7 image (Colibri-iMX6_LXDE-Image 2.7b4 20171004) and my own Yocto build, same result.

The “ifconfig can0 up” command does not allways give a response, I have only seen it ones och twice. But the “ifconfig can1 up” does allways give you a responce.

Hi

Have you tried if you have cansend in the Pengutronix format? i.e.

cansend -e -i 0x1F334455   0x11 0x22 0x33 0x44 0x55 0x55 0x77 0x88

What is “mcp258x0: mcp258x@1” stand for? Is this right?

The mcp258x@1 is just a string naming that node. For a SPI bus one usually ends the string with ‘@X’ to denote which device it is. If that should start with ‘@0’ or ‘@1’ is debatable. The numbering of the CAN network interfaces have nothing to do with this.

Max