CAN interface

Example available on GitHub. Check liteboard CAN example.

CAN interface is a message-oriented multi-master serial communications protocol which efficiently supports distributed realtime control.

liteSOM contains two CAN modules compatible with CAN 2.0B protocol specification. CAN Physical layer is defined by ISO 11898 therefore to connect liteSOM to CAN bus it is required to use external CAN Bus Transceiver like SN65HVD230 used on on RS485/CAN extension board.

can1: flexcan@02090000 {
    compatible = "fsl,imx6ul-flexcan", "fsl,imx6q-flexcan";
    reg = <0x02090000 0x4000>;
    interrupts = <GIC_SPI 110 IRQ_TYPE_LEVEL_HIGH>;
    clocks = <&clks IMX6UL_CLK_CAN1_IPG>,
             <&clks IMX6UL_CLK_CAN1_SERIAL>;
    clock-names = "ipg", "per";
    status = "disabled";

can2: flexcan@02094000 {
    compatible = "fsl,imx6ul-flexcan", "fsl,imx6q-flexcan";
    reg = <0x02094000 0x4000>;
    interrupts = <GIC_SPI 111 IRQ_TYPE_LEVEL_HIGH>;
    clocks = <&clks IMX6UL_CLK_CAN2_IPG>,
             <&clks IMX6UL_CLK_CAN2_SERIAL>;
    clock-names = "ipg", "per";
    status = "disabled";

Generic configuration for both FLEXCAN modules is defined by imx6ul.dtsi file.

To enable linux CAN driver please build your kernel with CONFIG_CAN_FLEXCAN enabled.

-> Networking support
  -> CAN bus subsystem support
    -> CAN Device Drivers
      -> Platform CAN drivers with Netlink support
        -> Support for Freescale FLEXCAN based chips

This option will activate FLEXCAN driver.

Documentation for this driver you can find in fsl-flexcan.txt file.

&iomuxc {
    pinctrl-names = "default";
    pinctrl_flexcan1: flexcan1grp{
        fsl,pins = <
            MX6UL_PAD_UART3_RTS_B__FLEXCAN1_RX  0x1b020
            MX6UL_PAD_UART3_CTS_B__FLEXCAN1_TX  0x1b020

&can1 {
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_flexcan1>;
    status = "okay";

i.MX6UL IOMUX Controller configuration required to connect liteboard with RS485/CAN extension board is defined by can1 node in imx6ul-can.dts file.

Linux supports CAN interface via SocketCAN.

A […] protocol family […] implemented which provides a socket interface to user space applications and which builds upon the Linux network layer, enabling use all of the provided queueing functionality. A device driver for CAN controller hardware registers itself with the Linux network layer as a network device, so that CAN frames from the controller can be passed up to the network layer and on to the CAN protocol family module and also vice-versa. Also, the protocol family module provides an API for transport protocol modules to register, so that any number of transport protocols can be loaded or unloaded dynamically. In fact, the can core module alone does not provide any protocol and cannot be used without loading at least one additional protocol module. Multiple sockets can be opened at the same time, on different or the same protocol module and they can listen/send frames on different or the same CAN IDs. Several sockets listening on the same interface for frames with the same CAN ID are all passed the same received matching CAN frames. An application wishing to communicate using a specific transport protocol, e.g. ISO-TP, just selects that protocol when opening the socket, and then can read and write application data byte streams, without having to deal with CAN-IDs, frames, etc.


  • litesom/devicetree/can.txt
  • Last modified: 2021/05/12 10:08
  • by kateryna.kozakova