DESK-MX9-L/Peripherals/CAN

From DAVE Developer's Wiki
Jump to: navigation, search
History
Issue Date Notes
2024/01/30 DESK-MX9-L-5.x.x release


Peripheral CAN[edit | edit source]

Device tree configuration[edit | edit source]

Here below is an example of device tree configuration used on standard DAVE's kit for the AURA SOM:

From imx93-aura.dtsi:

...
&flexcan2 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_flexcan2>;
	status = "okay";
};
...
&iomuxc {
...
    pinctrl_flexcan2: flexcan2grp {
		fsl,pins = <
			MX93_PAD_GPIO_IO25__CAN2_TX	0x139e
			MX93_PAD_GPIO_IO27__CAN2_RX	0x139e
		>;
	};
...
};

Accessing the peripheral[edit | edit source]

Linux messages at boot time[edit | edit source]

...
[    1.527184] can: controller area network core
[    1.536411] can: raw protocol
[    1.539420] can: broadcast manager protocol
[    1.543646] can: netlink gateway - max_hops=1
...

Enable the interface and check status[edit | edit source]

root@desk-mx93:~# ip link set can0 type can bitrate 500000
root@desk-mx93:~# ifconfig can0 up
[  487.839975] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready
root@desk-mx93:~# ifconfig can0
can0: flags=193<UP,RUNNING,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 24  

root@desk-mx93:~#

Usage with can-utils[edit | edit source]

root@desk-mx93:~# ip link set can0 type can bitrate 500000 triple-sampling on loopback on 
RTNETLINK answers: Device or resource busy
root@desk-mx93:~# ifconfig can0 up  
root@desk-mx93:~# candump can0 & 
[2] 734
interface = can0, family = 29, type = 3, proto = 1
root@desk-mx93:~# cansend can0 -i 0x255 0x0f 0x1e 0x2d 0x3c 0x4b 0x5a 0x69 0x78
interface = can0, family = 29, type = 3, proto = 1
<0x255> [8] 0f 1e 2d 3c 4b 5a 69 78 
<0x000> [8] f0 e1 d2 c3 b4 a5 96 87 

Additional information[edit | edit source]

Each CAN port appears like a networking interface in the form canX where X is the port number.

Information about programming the CAN socket interface is given in the kernel tree under Documentation/networking/can.rst