The NXP {cpu-family} CPU has two FLEXCAN controllers which operate at up to 1MbpsThe NXP i.MX6FlexCAN is a communications controller implementing the CAN protocol according to the CAN 2.0B protocol specification. It supports standard and extended message frames. The maximum message buffer is 64. The driver is a network device driver of the PF_CAN protocol family.

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, setting the bit-timing parameters, via the netlink interface using the program ip from the iproute2 utility suite.

The FlexCAN module includes these distinctive legacy features:

  • Version 2.0B

  • Standard data and remote frames

  • Extended data and remote frames

  • Zero to eight bytes data length

  • Programmable bit rate up to one Mbps

  • Content-related addressing

  • Flexible mailboxes of eight bytes data length

Kernel configuration

The MMC support can be added through the following kernel configuration options:

  • Networking > CAN bus (CONFIG_CAN)

  • Networking > CAN bus subsystem support > CAN Device Driver > NXP FlexCAN (CONFIG_CAN_FLEXCAN)

CAN bus support is enabled as built-in on the ConnectCore 6 Plus SBC kernel configuration file.

Kernel driver

File Description

drivers/net/can/flexcan.c

FlexCAN driver

The CAN support 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 {cpu-family} CAN interface device tree binding is documented at Documentation/devicetree/bindings/net/can/fsl-flexcan.txt

Example: CAN1 on the ConnectCore 6 Plus SBC

Definition of the device

{cpu-family} device tree
can1: flexcan@2090000 {
	compatible = "fsl,imx6q-flexcan";
	reg = <0x02090000 0x4000>;
	interrupts = <0 110 IRQ_TYPE_LEVEL_HIGH>;
	clocks = <&clks IMX6QDL_CLK_CAN1_IPG>,
	         <&clks IMX6QDL_CLK_CAN1_SERIAL>;
	clock-names = "ipg", "per";
	stop-mode = <&gpr 0x34 28 0x10 17>;
	status = "disabled";
};

IOMUX configuration

ConnectCore 6 Plus device tree
can1 {
	pinctrl_flexcan1: can1 {
		fsl,pins = <
			MX6QDL_PAD_GPIO_7__FLEXCAN1_TX 0x1b0b0
			MX6QDL_PAD_GPIO_8__FLEXCAN1_RX 0x1b0b0
			MX6QDL_PAD_GPIO_2__GPIO1_IO02  0x1b0b0
		>;
	};
};

Bus enabling

{cpu-family} device tree
&can1 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_flexcan1>;
	stby-gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>;
	status = "okay";
};

CAN user space usage examples

CAN device interface

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 by setting the bit-timing parameters via the netlink interface using the program ip from the iproute2 utility suite.

Setting the bitrate

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