3.2.2.4. MCANΒΆ

Introduction

The Controller Area Network is a serial communications protocol which efficiently supports distributed real-time control with a high level of security. The MCAN module supports bitrates up to 5 Mbit/s and is compliant to the ISO 11898-1:2015. The core IP within M_CAN is provided by Bosch.

This wiki page provides usage information of M_CAN Linux driver.

Setup Details

TI board List

SoC Board Number of Instances Connection Type Enabled by default
Dra76x EVM 1 Header Yes
AM654x IDK 2 DB9 Yes
AM64x EVM 2 Header Yes
J721E EVM 4 Header Yes
J721S2 EVM 5 Header Yes
AM62x SK 3 Header No

Table: Boards M_CAN Driver is Validated on

Notice for AM62x:

The AM62x SK does not carry a transciever to experiment with. The SoC does support CAN-FD, but it is required to connect a CAN external transceiver to the AM62x SK to test the full CAN functionality. Go to the following guide: MCAN on AM62x for an example for connecting a CAN external transceiver to the AM62x SK.

CAN Utilities

There may be other userspace applications that can be used to interact with the CAN bus but the SDK supports using Canutils which is already included in the sdk filesystem.

Note

These instructions are for can0 (first and perhaps only CAN instance enabled). If the board has multiple CAN instances enabled then they can be referenced by incrementing the CAN instance number. For example 2 CAN instances will have can0 and can1.

Quick Steps

Initialize CAN Bus

  • Set bitrate
$ ip link set can0 type can bitrate 1000000
  • CAN-FD mode
$ ip link set can0 type can bitrate 1000000 fd on
  • CAN-FD mode with bitrate switching
$ ip link set can0 type can bitrate 1000000 dbitrate 4000000 fd on

Start CAN Bus

  • Device bring up

Bring up the device using the command:

$ ip link set can0 up

Transfer Packets

Cansend

Used to generate a specific can frame. The syntax for cansend is as follows:

<can_id>#{R|data}          for CAN 2.0 frames
<can_id>##<flags>{data}    for CAN FD frames

Some examples:

  1. Send CAN 2.0 frame
$ cansend can0 123#DEADBEEF
  1. Send CAN FD frame
$ cansend can0 113##2AAAAAAAA
  1. Send CAN FD frame with BRS
$ cansend can0 143##1AAAAAAAAA

Cangen

Used to generate frames at equal intervals. The syntax for cangen is as follows:

cangen [options] <CAN interface>

Some examples:

  1. Full load test with polling, 10 ms timeout
$ cangen can0 -g 0 -p 10 -x

b. fixed CAN ID and length, inc. data, canfd frames with bitrate switching

$ cangen vcan0 -g 4 -I 42A -L 1 -D i -v -v -f -b

Candump

Candump is used to display received frames.

candump [options] <CAN interface>

Example:

$ candump can0

Note: Use Ctrl-C to terminate candump

Further options for all canutils commands are available at https://git.pengutronix.de/cgit/tools/canutils

Stop CAN Bus

Stop the can bus by:

$ ip link set can0 down