Skip to content

CAN

CAN (Controller Area Network) bus, namely Controller Area Network bus, is a serial communication network for effective distributed control or real-time control.

Warning

The CAN on the expansion pins is the chip's native interface and does not go through a CAN transceiver. An external CAN transceiver module is required for use.

The expansion pin CAN information for Rockchip platforms is as follows:

Board SoC Expansion Pins
K1 RK3568 CAN X2
K1B RK3568 None
K3 RK3562 None
K7 RK3576 CAN X1
K7C RK3576 CAN X1
K8 RK3588 CAN X1

DTS Node Configuration

The following is an example configuration for CAN device 0 node on Rockchip platforms:

&can0 {
      pinctrl-names = "default";
      pinctrl-0 = <&can0m2_pins>;
      status = "okay";
};

Driver Files

The CAN bus driver path for RK3568/RK3588 platforms is as follows:

drivers/net/can/rockchip/rockchip_canfd.c

The CAN bus driver path for RK3562 platform is as follows:

drivers/net/can/rockchip/rk3562_canfd.c

The CAN bus driver path for RK3576 platform is as follows:

drivers/net/can/rockchip/rk3576_canfd.c

Query Current CAN Devices

Query current network devices:

ifconfig -a

Operation Example:

console$ ifconfig -a
...
can0      Link encap:UNSPEC    Driver rk3576_canfd
          NOARP  MTU:16  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:10 
          RX bytes:0 TX bytes:0 
          Interrupt:63 
...

CAN Configuration

Disable CAN:

ip link set can0 down

Set can0 to a bitrate of 500Kbps and disable CAN FD mode:

ip link set can0 type can bitrate 500000 fd off

Set can0 arbitration segment to 1M baud rate, data segment to 3M baud rate, and enable CAN FD mode:

ip link set can0 type can bitrate 1000000 dbitrate 3000000 fd on

View can0 configuration information:

ip -details link show can0

Enable CAN:

ip link set can0 up

CAN Send

Send (Standard frame, Data frame, ID:123, data:DEADBEEF):

cansend can0 123#DEADBEEF

Send (Standard frame, Remote frame, ID:123):

cansend can0 123#R

Send (Extended frame, Data frame, ID:00000123, data:DEADBEEF):

cansend can0 00000123#12345678

Send (Extended frame, Remote frame, ID:00000123):

cansend can0 00000123#R

CAN Receive

Enable printing and wait for reception:

candump can0