DESK-RZ-L/Peripherals/CAN

From DAVE Developer's Wiki
Jump to: navigation, search
History
Issue Date Notes
2025/12/16 DESK-RZ-L-1.x.x release


Peripheral CAN[edit | edit source]

The two CAN buses have a transceiver that is enabled or disabled via a dedicated pin. This pin is controlled by the GPIO expander exp_1 and managed as a regulator, so no preliminary operations are required before using the CAN interfaces.

Configuration[edit | edit source]

These peripheral(s) can only be used with the following ConfigID(s) (see the associated BOM):

ConfigID Note
2002 -
2003 -

Device tree configuration[edit | edit source]

Below is an example of a device tree configuration used on ZERO Evaluation Kit.

From rzt2h-dsab.dts:

/ {
...
	stb_can_0: reg_stb_can_0 {
		compatible = "regulator-fixed";

		regulator-name = "reg_stb_can_0";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;

		gpio = <&exp_1 14 GPIO_ACTIVE_LOW>;

		regulator-boot-on;
		regulator-always-on;
	};

	stb_can_1: reg_stb_can_1 {
		compatible = "regulator-fixed";

		regulator-name = "reg_stb_can_1";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;

		gpio = <&exp_1 15 GPIO_ACTIVE_LOW>;

		regulator-boot-on;
		regulator-always-on;
	};
...
};
...
&canfd {
	pinctrl-0 = <&can0_pins &can1_pins>;
	pinctrl-names = "default";
	status = "okay";

	renesas,no-can-fd;

	canstb0-supply = <&stb_can_0>;
	canstb1-supply = <&stb_can_1>;

	channel0 {
		status = "okay";
	};

	channel1 {
		status = "okay";
	};
};
...
&pinctrl {
...
	can0_pins: can0 {
		pinmux =    <RZT2H_PORT_PINMUX(24, 3, 0x19)>,   /* P24_3 CANRX0 | B_AB17 B20 */
			        <RZT2H_PORT_PINMUX(24, 4, 0x19)>;   /* P24_4 CANTX0 | B_AC17 G22 */
	};

	can1_pins: can1 {
		pinmux =    <RZT2H_PORT_PINMUX(22, 5, 0x19)>,   /* P22_5 CANRX1 | B_AB19 E21 */
			        <RZT2H_PORT_PINMUX(22, 6, 0x19)>;   /* P22_6 CANTX1 | B_AC19 C22 */
	};
...
};

Accessing the peripheral[edit | edit source]

Linux[edit | edit source]

...
[   61.906321] rcar_canfd 80040000.can: can_clk rate is 125000000
[   61.912864] rcar_canfd 80040000.can: device registered (channel 0)
[   61.919132] rcar_canfd 80040000.can: can_clk rate is 125000000
[   61.925643] rcar_canfd 80040000.can: device registered (channel 1)
[   61.931884] rcar_canfd 80040000.can: global operational state (clk 0, fdmode 0)
[   62.656269] can: controller area network core
[   62.665208] can: raw protocol
[   62.668219] can: broadcast manager protocol
[   62.672459] can: netlink gateway - max_hops=1
...
root@desk-t2h-usd-devel:~# ip link set can0 type can bitrate 200000
root@desk-t2h-usd-devel:~# ip link set can0 up
root@desk-t2h-usd-devel:~# ifconfig can0
can0: flags=193<UP,RUNNING,NOARP>  mtu 16  metric 1
        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
root@desk-t2h-usd-devel:~# ifconfig can1
can1: flags=128<NOARP>  mtu 16  metric 1
        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
root@desk-t2h-usd-devel:~# ip link set can0 type can bitrate 200000
root@desk-t2h-usd-devel:~# ifconfig can0 up  
root@desk-t2h-usd-devel:~# candump can0   
  can0  123   [8]  01 01 02 03 04 05 06 07