The FlexCAN controller implements the CAN protocol according to the ISO11898-1 standard, the CAN with Flexible Data rate (CAN FD) protocol, and the the CAN 2.0 version B protocol specification.

FlexCAN includes the following features:

  • Standard data and remote frames

  • Extended data and remote frames

  • Mixed controller mode (CAN FD and CAN 2.0B)

    • Arbitration bitrate up to 1 Mbps

    • Data bitrate up to 8 Mbps

The FlexCAN driver is a network device driver.

Available CAN interfaces

On the ConnectCore 95 SMT SOM:

  • CAN1 is available at the castellated and LGA pads, multiplexed with other functionality.

  • CAN2 is available at the castellated and LGA pads, multiplexed with other functionality.

  • CAN3 is available at the LGA pads, multiplexed with other functionality.

  • CAN4 is available at the castellated and LGA pads, multiplexed with other functionality.

  • CAN5 is available at the castellated and LGA pads, multiplexed with other functionality.

On the ConnectCore 95 SMARC SOM:

  • CAN2 is routed to CAN1 bus of the SMARC connector.

  • CAN3 is routed to CAN0 bus of the SMARC connector.

On the ConnectCore 95 Development Kit:

  • CAN2 (CAN1 port of the SMARC connector) is available through a transceiver at connector J10. Optional termination line resistor can be connected by placing a jumper on connector J9.

  • CAN3 (CAN0 port of the SMARC connector) is available through a transceiver at connector J12. Optional termination line resistor can be connected by placing a jumper on connector J11.

Kernel configuration

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

  • CAN Bus support (CONFIG_CAN)

  • Support for Freescale FLEXCAN based chips (CONFIG_CAN_FLEXCAN)

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

Kernel driver

File Description

drivers/net/can/flexcan

Freescale FLEXCAN driver

CAN support on the ConnectCore 95 Development Kit 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 Freescale FLEXCAN controller device tree binding is documented at Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml

Both CAN ports are enabled on the default ConnectCore 95 Development Kit device tree.

Example: CAN2 on the ConnectCore 95 Development Kit

ConnectCore 95 Development Kit device tree
&flexcan2 {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&pinctrl_flexcan2>;
	pinctrl-1 = <&pinctrl_flexcan2_sleep>;
	xceiver-supply = <&reg_can2_stby>;
	status = "okay";
};

[...]


	pinctrl_flexcan2: flexcan2grp {
		fsl,pins = <
			IMX95_PAD_GPIO_IO25__CAN2_TX			0x39e
			IMX95_PAD_GPIO_IO27__CAN2_RX			0x39e
		>;
	};

	pinctrl_flexcan2_sleep: flexcan2grpsleep {
		fsl,pins = <
			IMX95_PAD_GPIO_IO25__GPIO2_IO_BIT25		0x200
			IMX95_PAD_GPIO_IO27__GPIO2_IO_BIT27		0x200
		>;
	};
FlexCAN1 (flexcan1) belongs to the Always-ON (AON) domain and is probed last, after the rest of ports. Therefore, the kernel names the other ports starting at can0, and FlexCAN1 last as canN, which may be confusing.

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 CAN entries are found in the device tree.

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

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 the meta-digi layer. These applications show how to send and receive packets through the CAN ports using Digi APIx library on the ConnectCore 95 platform.

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

First bring the interface down in case it’s already configured and up:

# ifconfig canX down

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.