DESK-MX8M-L/Pheripherals/CAN

From DAVE Developer's Wiki
Jump to: navigation, search
History
Version Issue Date Notes
1.0.0 Jan 2022 First DESK-MX8M release


Peripheral CAN[edit | edit source]

Device tree configuration[edit | edit source]

Here below an example of device tree configuration that can be used modifying DAVE's kit for the ORCA SOM:

From imx8mp-mito8mplus-cb1001.dts:

&flexcan1 {
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_flexcan1>;
    status = "okay";
};

&flexcan2 {
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_flexcan2>;
    status = "okay";
};

From imx8mp-mito8mplus.dtsi:

    pinctrl_flexcan1: flexcan1grp {
	fsl,pins = <
		MX8MP_IOMUXC_SAI2_TXC__CAN1_RX		0x154
		MX8MP_IOMUXC_SAI5_RXD1__CAN1_TX		0x154
	>;
    };

    pinctrl_flexcan2: flexcan2grp {
	fsl,pins = <
		MX8MP_IOMUXC_SAI2_MCLK__CAN2_RX		0x154
		MX8MP_IOMUXC_SAI2_TXD0__CAN2_TX		0x154
	>;
    };

Accessing the peripheral[edit | edit source]

Linux messages at boot time[edit | edit source]

...
...
[    0.857679] CAN device driver interface
[    0.862032] flexcan 308c0000.can: 308c0000.can supply xceiver not found, using dummy regulator
[    0.871290] flexcan 308d0000.can: 308d0000.can supply xceiver not found, using dummy regulator
...
...
[    1.841605] can: controller area network core (rev 20170425 abi 9)
[    1.852275] can: raw protocol (rev 20170425)
[    1.856550] can: broadcast manager protocol (rev 20170425 t)
[    1.862220] can: netlink gateway (rev 20190810) max_hops=1

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

root@desk-mx8mp:~# ip link set can0 type can bitrate 500000 triple-sampling on
root@desk-mx8mp:~# ip link set can1 type can bitrate 500000 triple-sampling on
root@desk-mx8mp:~# ifconfig can0 up
[   94.651224] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready
root@desk-mx8mp:~# ifconfig can1 up
[   96.465845] IPv6: ADDRCONF(NETDEV_CHANGE): can1: link becomes ready
root@desk-mx8mp:~# ifconfig can0
can0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          UP RUNNING 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 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:29

root@desk-mx8mp:~# ifconfig can1
can1      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          UP RUNNING 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 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:30

root@desk-mx8mp:~#

Usage with can-utils[edit | edit source]

root@desk-mx8mp:~# cansend can0 5A1#11.22.33.44.55.66.77.88
interface = can0, family = 29, ty[  151.329908] flexcan 308c0000.can can0: bus-off
pe = 3, proto = 1
root@desk-mx8mp:~#

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.txt