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.
You can access the CAN1 port through the expansion connector on the ConnectCore 6UL SBC Express.
On the ConnectCore 6UL SBC Pro:
-
CAN1 port lines are multiplexed with UART3 CTS/RTS.
-
CAN2 port lines are multiplexed with UART2 CTS/RTS.
-
Both CAN ports are accessible through a connector.
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 6UL kernel configuration file.
Kernel driver
File | Description |
---|---|
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 6UL SBC Pro
Definition of the device
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";
stop-mode = <&gpr 0x10 1 0x10 17>;
status = "disabled";
};
IOMUX configuration
pinctrl_flexcan1: flexcan1grp{
fsl,pins = <
MX6UL_PAD_UART3_CTS_B__FLEXCAN1_TX 0x1b020
MX6UL_PAD_UART3_RTS_B__FLEXCAN1_RX 0x1b020
>;
};
Bus enabling
/* CAN1 (multiplexed with UART3 RTS/CTS) */
&can1 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_flexcan1>;
xceiver-supply = <&ext_3v3>;
status = "okay";
};
CAN user space usage 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 6UL SBC Pro has:
Setting can1 status as "okay" in the device tree sets CAN1 as |
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.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 6UL 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.