How to use CAN#

Attention

sm2s-el requires CAN to be enabled in BIOS setup, see corresponding User Manual for SMARC module in question.

Enabling the CAN interface#

CAN interface must be configure properly and enabled before it can send and receive data.

Check if your CAN interface is available

$ ip link show CAN0
3: CAN0: <NOARP,ECHO> mtu 16 qdisc noop state DOWN mode DEFAULT group default qlen 10
link/can

Set interface type and bit-rate for the interface

$ ip link set CAN0 type can bitrate 500000

Now interface can be enabled

$ ip link set CAN0 up

You can check if interface is up and running

$ ip link show CAN0
3: CAN0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
link/can

Testing with can-utils#

Simple way to test if your CAN is working properly is to employ tools from can-utils package.

Use cansend to send data to a given interface

$ cansend CAN0 '1234#AABBCCDD'

If everything is working properly message with ID 123 with data AABBCCDD must appear on CAN.

Use candump in the same interface to listen to incoming messages in a given interface

$ candump CAN0
  CAN0  123   [4]  AA BB CC DD

Troubleshooting#

Q: There is no CAN0/CAN1 interface in output of ip link show

Check if all the necessary kernel modules are loaded

For all SMARC modules

  • can

  • can_raw

  • can_dev

For sm2s-el

  • m_can

  • m_can_pci

For sm2s-imx8plus

  • flexcan

e.g. lsmod m_can