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:
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:
The CAN bus driver path for the RK3562 platform is as follows:
The CAN bus driver path for the RK3576 platform is as follows:
The CAN bus driver path for the AllWinner T527 platform is as follows:
Querying Current CAN Devices
Query current network devices:
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:
Set can0 bitrate to 500Kbps and disable CAN FD mode:
Set can0 arbitration phase to 1M baud and data phase to 3M baud, enable CAN FD mode:
View can0 configuration information:
Bring CAN 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:
Set awlink0 to restart after 10ms on error:
Set awlink0 bitrate to 1 Mbps/s and enable loopback:
Set queue depth:
View can0 configuration information:
Bring CAN up:
CAN Transmission
Using node can0 as an example:
Transmit (standard frame, data frame, ID:123, data:DEADBEEF):
Transmit (standard frame, remote frame, ID:123):
Transmit (extended frame, data frame, ID:00000123, data:DEADBEEF):
Transmit (extended frame, remote frame, ID:00000123):
CAN Reception
Using node can0 as an example:
Enable printing and wait for reception: