The NXP i.MX6 CPU has two FlexCAN controllers which operate at up to one Mbps. FlexCAN 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

The CAN bus driver for the i.MX6 is located at drivers/net/can/flexcan.c.

Device tree bindings and customization

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

The CAN interfaces are defined in the i.MX6 CPU, ConnectCore 6 Plus, and ConnectCore 6 Plus SBC device tree files.

Example: Can1

Definition of the device

i.MX6QP device tree
can1: flexcan@02090000 {
    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

i.MX6QP 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, for example:

ip link set canX up type can bitrate 125000

In this example, X is the index of the CAN node you want to configure.

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