The ConnectCore 8X system-on-module has three CAN ports, controlled by independent NXP i.MX8QXP FlexCAN controllers, available for peripheral use. FlexCAN is a communications controller implementing the CAN protocol according to the CAN-FD 3.0 protocol specification. It also supports legacy CAN 2.0B protocol specification. The controller can operate on both CAN-FD (flexible data rate) and legacy CAN modes.

CAN-FD protocol supports two different bit rates for the arbitration phase and the payload phase and up to 64 Bytes of payload, achieving higher throughput than classical CAN protocol.

The CAN port includes the following legacy features:

  • Version 2.0B

  • Standard data and remote frames

  • Extended data and remote frames

  • Zero to eight bytes payload length

  • Programmable bit rate up to 1 Mbps

  • Content-related addressing

  • Flexible mailboxes of eight bytes data length

CAN ports configured as CAN-FD capable have been validated to function as regular CAN with a maximum data rate of 1 Mbps.

Digi has not yet tested higher data rates between CAN-FD capable devices. CAN-FD specifications are yet to be documented.

The CAN driver is a network device driver.

Available CAN interfaces

  • CAN0 port lines are available on the XBEE socket (multiplexed with LPUART0 CTS/RTS).

  • CAN1 port lines are available on the expansion header.

  • CAN2 port lines are available on the expansion header.

All CAN port lines are available at TTL level; an external CAN transceiver is required.
Every CAN interface is disabled in the default device tree due to conflicts with other interfaces.
  • CAN0:

    • Port lines are available at TTL level on the expansion header (multiplexed with LPUART0 CTS/RTS). An external CAN transceiver is required.

    • Interface is disabled in the default device tree due to conflicts with another interface.

  • CAN1:

    • Interface is enabled in the default device tree.

    • Port lines are available on the expansion header.

    • Port incorporates a CAN transceiver.

    • The transceiver 'standby' pin is handled automatically through CAN1_MODE signal. This is defined through the stby-gpios device tree entry:

      ConnectCore 8X SBC Pro device tree
      /* CAN1 on expansion header */
      &flexcan2 {
      	pinctrl-names = "default";
      	pinctrl-0 = <&pinctrl_flexcan2>;
      	xceiver-supply = <&reg_5v_display>;
      	stby-gpios = <&gpio1 0 GPIO_ACTIVE_HIGH>;
      	status = "okay";
      };
  • CAN2:

    • Interface is enabled in the default device tree.

    • Port is multiplexed with LPUART3 and requires CAN/RS485# signal to select between the CAN and RS485 transceivers.

    • CAN lines are available on the expansion header.

    • The transceiver 'standby' pin is handled automatically through CAN2_MODE signal. This is defined through the stby-gpios entry in the device tree.

    • To select the CAN transceiver, CAN/RS485# signal needs to be driven high. This is handled automatically through the pinctrl-assert-gpios device tree entry:

      ConnectCore 8X SBC Pro device tree
      /*
       * CAN2 on expansion header.
       * Conflicts with LPUART3 RX/TX lines.
       * Requires signal CAN/RS485# (GPIO3_IO23) to be driven high
       */
      &flexcan3 {
      	pinctrl-names = "default";
      	pinctrl-0 = <&pinctrl_flexcan3>,
      		    <&pinctrl_flexcan3_lpuart3_gpios>;
      	xceiver-supply = <&reg_5v_display>;
      	stby-gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>;
      	pinctrl-assert-gpios = <&gpio3 23 GPIO_ACTIVE_HIGH>;
      	status = "okay";
      };

Kernel configuration

You can manage the CAN support through the kernel configuration options:

  • CAN Bus support (CONFIG_CAN)

  • NXP FlexCAN support (CONFIG_CAN_FLEXCAN)

These options are enabled as built-in on the default ConnectCore 8X kernel configuration file.

Kernel driver

File Description

drivers/net/can/flexcan.c

FlexCAN driver

Device tree bindings and customization

The i.MX8QXP CAN interface device tree binding is documented at Documentation/devicetree/bindings/net/can/fsl-flexcan.txt

Example: CAN1 on the ConnectCore 8X SBC Pro

Definition of the device

i.MX8QXP device tree
flexcan2: can@5a8e0000 {
	compatible = "fsl,imx8qxp-flexcan", "fsl,imx8qm-flexcan";
	reg = <0x0 0x5a8e0000 0x0 0x10000>;
	interrupts = <GIC_SPI 236 IRQ_TYPE_LEVEL_HIGH>;
	interrupt-parent = <&wu>;
	/* CAN0 clock and PD is shared among all CAN instances */
	clocks = <&clk IMX8QXP_CAN0_IPG_CLK>,
		 <&clk IMX8QXP_CAN0_CLK>;
	clock-names = "ipg", "per";
	assigned-clocks = <&clk IMX8QXP_CAN0_CLK>;
	assigned-clock-rates = <40000000>;
	power-domains = <&pd_dma_flexcan0>;
	status = "disabled";
};

IOMUX configuration

ConnectCore 8X SBC Pro device tree
pinctrl_flexcan2: flexcan1grp {
	fsl,pins = <
		SC_P_FLEXCAN1_TX_ADMA_FLEXCAN1_TX		0x21
		SC_P_FLEXCAN1_RX_ADMA_FLEXCAN1_RX		0x21
		/* CAN1 MODE */
		SC_P_SPI2_CS0_LSIO_GPIO1_IO00                   0x06000020
	>;
};

Bus enabling

ConnectCore 8X SBC Pro device tree
/* CAN1 on expansion header */
&flexcan2 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_flexcan2>;
	xceiver-supply = <&reg_5v_display>;
	stby-gpios = <&gpio1 0 GPIO_ACTIVE_HIGH>;
	status = "okay";
};

CAN user space usage examples

CAN device interface

The CAN driver is a network device driver from the PF_CAN protocol family. It exposes device data through the sysfs at /sys/class/net/canX/, where X is the port index, starting at zero.

Linux creates port indexes sequentially as enabled flexcan entries are found in the device tree.

For example, the default device tree configuration for ConnectCore 8X SBC Pro has:

  • CAN0 disabled

  • CAN1 enabled (set as can0 in Linux)

  • CAN2 enabled (set as can1 in Linux)

Setting flexcan1 status as "okay" in the device tree sets CAN0 as can0.

The CAN network device driver interface provides a generic interface to set up, configure, and monitor CAN network devices. For example, you can configure the CAN device via the netlink interface using the program ip from the iproute2 utility suite.

FD mode should always be enabled for the driver to function. To operate in 2.0B legacy mode, it is only required that arbitration bit rate (bitrate) and payload bit rate (dbitrate) have the same value, and it is not higher than 1Mbps. It will also be required that CAN frames to be sent don’t have a payload higher than 8 bytes.

Configuring the interface

Before you can start the CAN network device, you must enable the FD mode and configure the bitrates at which it will communicate. In the following example, X is the index of the CAN node you want to configure:

~# ip link set canX up type can bitrate 125000 dbitrate 125000 fd on

Starting and stopping the CAN network device

Similar to other network interfaces, you can start or stop a CAN network device with the ifconfig command. In the following example, X is the index of the CAN node you want to bring up or down.

To start:

~# ifconfig canX up

To stop:

~# ifconfig canX down

For more information, see the Linux kernel documentation: Documentation/networking/can.txt

CAN device test application

The CAN support is based on the SocketCAN stack. For more information and source code about this project, refer to http://elinux.org/CAN_Bus and https://github.com/linux-can/.

Build the package dey-examples-can in your Yocto project to install the test application can_test.

Syntax

To display the application syntax:

~# can_test --help

Examples

To send an 8-bit CAN message to node can0 with ID 0x12 and the data pattern 0x65:

~# can_test -l 1 -b 8 -d can0 -i 0x12 -p 0x65 -m

To receive a similar message:

~# can_test -l 1 -b 8 -d can0 -i 0x12 -p 0x65