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 bitrates 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 bitrate up to 1 Mbps

  • Content-related addressing

  • Flexible mailboxes of eight bytes data length

The CAN driver is a network device driver.

Available CAN 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

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

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 use 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.

Configuring the interface

Before you can start the CAN network device, you must configure the bitrate 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

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

Sample application

Example applications called apix-can-send-example and apix-can-recv-example are included in the dey-examples-digiapix recipe (part of dey-examples package) of meta-digi layer. These applications show how to send and receive packets through the CAN ports using Digi APIx library on the ConnectCore 8X platform.

Go to GitHub to see the applications instructions and source code.

For example, to send an 8-bit CAN message to node can0 with ID 0x12 at a baudrate of 500 Kbit/s:

~# apix-can-send-example -i can0 -I 0x12 -b 500000

To receive a similar message:

~# apix-can-recv-example -i can0 -b 500000

See CAN API for more information about the CAN APIx.