Skip to content

CAN

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

The CAN pin expansion information on Rockchip platform is as follows:

Warning

The CAN on Rockchip expansion pins is the chip's native interface and requires an external CAN transceiver module for operation.

Motherboard SOC Expansion Pins CAN Transceiver
K1 RK3568 CAN x2 N
K1B RK3568 N N
K1Mini RK3568 CAN x2 N
K3 RK3562 N N
K3B RK3562 N N
K7 RK3576 CAN x1 N
K7C RK3576 CAN x1 N
K7S/F RK3576 N N
K8 RK3588 CAN x1 N
K8D RK3588S2 CAN x1 N
K11C RK3566 N N

The CAN pin expansion information on the AllWinner platform is as follows:

Motherboard SOC Expansion Pins CAN Transceiver
K2B H618 N N
K2C H618 N N
K4B T113 N N
K5C A133 N N
K9 T527 CAN x2 Y
K10B A733 N N

DTS Node Configuration

Rockchip

Below is an example configuration for CAN device 0 on the Rockchip platform:

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

Allwinner

Note

On the AllWinner T527 platform, the CAN device node in the device tree source (DTS) file is named "awlink". Note that "awlink" is just the naming identifier for this CAN device node. Its actual functionality and hardware properties are identical to a CAN device; only the name differs, with no functional distinction.

Below is an example configuration for the T527 platform CAN_0 device node:

awlink0: awlink@0x0{
          #address-cells = <1>;
          #size-cells = <0>;
          compatible = "allwinner,t527-awlink";
          device_type = "awlink0";
          awlink-pin = <1>;
          id = <0>;
          status = "okay";
};

Below is an example configuration for the T527 platform CAN_1 device node:

awlink1: awlink@0x1{
          #address-cells = <1>;
          #size-cells = <0>;
          compatible = "allwinner,t527-awlink";
          device_type = "awlink1";
          awlink-pin = <0>;
          id = <1>;
          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 the RK3562 platform is as follows:

drivers/net/can/rockchip/rk3562_canfd.c

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

drivers/net/can/rockchip/rk3576_canfd.c

The CAN bus driver path for the AllWinner T527 platform is as follows:

// Android
longan/bsp/drivers/awlink/sunxi_awlink.c
// Debian 11
bsp/drivers/awlink/sunxi_awlink.c

Querying Current CAN Devices

Query current network devices:

ifconfig -a

Rockchip Platform 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 
...

Allwinner Platform Operation Example:

console$ ifconfig -a
...
awlink0: flags=128<NOARP>  mtu 16
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 27

awlink1: flags=128<NOARP>  mtu 16
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 28 
...

CAN Configuration

Rockchip

Bring CAN down:

ip link set can0 down

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

ip link set can0 type can bitrate 500000 fd off

Set can0 arbitration phase to 1M baud and data phase to 3M baud, 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

Bring CAN up:

ip link set can0 up

Allwinner

Tip

The following uses the CAN_0 node as an example. This node corresponds to the awlink0 node in the DTS file (the device tree node for CAN_0 is named awlink0).

Bring CAN down:

ip link set awlink0 down

Set awlink0 to restart after 10ms on error:

ip link set awlink0 type can restart-ms 10

Set awlink0 bitrate to 1 Mbps/s and enable loopback:

ip link set awlink0 type can bitrate 1000000 loopback on

Set queue depth:

ip link set awlink0 qlen 300

View can0 configuration information:

ip -d -s link show awlink0

Bring CAN up:

ip link set awlink0 up

CAN Transmission

Using node can0 as an example:

Transmit (standard frame, data frame, ID:123, data:DEADBEEF):

cansend can0 123#DEADBEEF

Transmit (standard frame, remote frame, ID:123):

cansend can0 123#R

Transmit (extended frame, data frame, ID:00000123, data:DEADBEEF):

cansend can0 00000123#12345678

Transmit (extended frame, remote frame, ID:00000123):

cansend can0 00000123#R

CAN Reception

Using node can0 as an example:

Enable printing and wait for reception:

candump can0