Sitara AM35x CAN (HECC) Linux Driver

From Texas Instruments Wiki
Jump to: navigation, search


Overview

This wiki page provides information on using TI's CAN (HECC) Linux driver module on Sitara AM3517 EVM. The ti_hecc driver is already part of linux since 2.6.32. This document concerns the updated support targeting the linux-2.6.37 tree.

Linux Driver Information

  • CAN device driver in Linux is provided as a networking driver that confirms to the socketCAN interface
  • The driver is currently build-into the kernel with the right configuration items enabled (details below)
  • CAN PHY on the extension application board is enabled via a i2c expander (using one of the TCA6416 IO expander chips) port. This needs to be enabled during kernel configuration.

How CAN driver fits into Linux architecture

  • TI HECC CAN driver is a can "networking" driver that fits into the Linux Networking framework
  • It is available as a configuration item in the linux kernel configuration as follows:
  Linux Kernel Configuration
     Networking support
        CAN bus subsystem support
           CAN device drivers
              Platform CAN drivers with Netlink support
                 CAN bit-timing calculation
                 TI High End CAN controller (HECC)

Detailed Kernel Configuration

To enable/disable CAN driver support, start the Linux Kernel Configuration tool:

$ make menuconfig ARCH=arm


Select Networking support from the main menu.

    ...
    ...
    Power management options --->
    [*] Networking support --->
    Device Drivers --->
    File systems --->
    Kernel hacking --->
    ...
    ...


Select CAN bus subsystem support as shown here:

    ...
    ...
    Networking options  --->
[ ] Amateur Radio support  --->
<*> CAN bus subsystem support  --->
    IrDA (infrared) subsystem support  --->
    ...


Select Raw CAN Protocol & Broadcast Manager CAN Protocol as shown here:

    ...
    --- CAN bus subsystem support
<*> Raw CAN Protocol (raw access with CAN-ID filtering)
<*> Broadcast Manager CAN Protocol (with content filtering)
    CAN Device Drivers  --->


Select CAN Device Drivers in the above menu and then select the following options:

<*> Virtual Local CAN Interface (vcan)
<*> Platform CAN drivers with Netlink support
[*]   CAN bit-timing calculation
<*>   TI High End CAN Controller 
< >   Microchip MCP251x SPI CAN controllers 
          ...


Note: -> "CAN bit-timing calculation" needs to be enabled to use "ip" utility to set CAN bitrate


To enable PHY control, go back to the main-menu and select Device Drivers  :

    ...
    ...
    Power management options --->
    [*] Networking support --->
    Device Drivers --->
    File systems --->
    Kernel hacking --->
    ...
    ...


Select GPIO Support as shown below:

    ...
     ...
-*-  I2C support  --->
     PPS support  --->
[*]  SPI support  --->
-*-  GPIO Support  --->
< >  Dallas's 1-wire support  --->


Select PCA953x, PCA955x, TCA64xx, and MAX7310 I/O ports as shown below:

    ...
     ...
*** I2C GPIO expanders: ***
< > Maxim MAX7300 GPIO expander
< > MAX7319, MAX7320-7327 I2C Port Expanders
<*> PCA953x, PCA955x, TCA64xx, and MAX7310 I/O ports
[ ]     Interrupt controller support for PCA953x 
     ...

CAN Utilities

  • Since CAN is a "networking" interface and uses the socket layer concepts, many utilities have been developed in open source for utilizing CAN interface.
  • A good source of these utilities is the Berlios SocketCAN website that offers these utilities via SVN ( & HTTP interface)
  • For testing CAN we commonly use the cansend /cangen and candump utilities to send and receive packets via CAN module.
  • To configure the CAN interface netlink standard utilities are used and this requires iproute2 utilities.

Note that if the kernel configuration for "CAN bit-timing calculation" is not enabled then each of the parameters: tq, PROP_SEG etc need to be set individually. When bit-timing calculation is enabled int he kernel then only setting the bitrate is sufficient as it calculates other parameters

ip (route2)

  • "ip" utility help - ensure you are using iproute2 utility as only that supports CAN interface.
Usage: ip link set DEVICE type can
       [ bitrate BITRATE [ sample-point SAMPLE-POINT] ] |
       [ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1
         phase-seg2 PHASE-SEG2 [ sjw SJW ] ]
       [ loopback { on | off } ]
       [ listen-only { on | off } ]
       [ triple-sampling { on | off } ]
       [ restart-ms TIME-MS ]
       [ restart ]
       Where: BITRATE       := { 1..1000000 }
              SAMPLE-POINT  := { 0.000..0.999 }
              TQ            := { NUMBER }
              PROP-SEG      := { 1..8 }
              PHASE-SEG1    := { 1..8 }
              PHASE-SEG2    := { 1..8 }
              SJW           := { 1..4 }
              RESTART-MS    := { 0 | NUMBER }
  • check the result of ip link help ;ensure that the TYPE field contains can
Usage: ip link add link DEV [ name ] NAME
                   [ txqueuelen PACKETS ]
                   [ address LLADDR ]
                   [ broadcast LLADDR ]
                   [ mtu MTU ]
                   type TYPE [ ARGS ]
       ip link delete DEV type TYPE [ ARGS ]
 
       ip link set DEVICE [ { up | down } ]
                          [ arp { on | off } ]
                          [ dynamic { on | off } ]
                          [ multicast { on | off } ]
                          [ allmulticast { on | off } ]
                          [ promisc { on | off } ]
                          [ trailers { on | off } ]
                          [ txqueuelen PACKETS ]
                          [ name NEWNAME ]
                          [ address LLADDR ]
                          [ broadcast LLADDR ]
                          [ mtu MTU ]
                          [ netns PID ]
                          [ alias NAME ]
       ip link show [ DEVICE ]


  TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | can }


  • Ensure you are using the right ip utility (from iproute2)
<prompt> ./ip -V
ip utility, iproute2-ss090324
  • Set the bit-rate to 125Kbits/sec with triple sampling using the following command (for device can0)
<prompt> ip link set can0 type can bitrate 125000 triple-sampling on
  • Bring up the device using the command:
<prompt> ip link set can0 up

cansend

  • Usage: cansend <device> <can_frame>.
  • Send a CAN packet
./cansend can0 111#1122334455667788 

candump

  • Usage: candump [options] <CAN interface>+ (use CTRL-C to terminate candump)
Options: -t <type>   (timestamp: (a)bsolute/(d)elta/(z)ero/(A)bsolute w date)
        -c          (increment color mode level)
        -i          (binary output - may exceed 80 chars/line)
        -a          (enable additional ASCII output)
        -S          (swap byte order in printed CAN data[] - marked with '`' )
        -s <level>  (silent mode - 0: off (default) 1: animation 2: silent)
        -b <can>    (bridge mode - send received frames to <can>)
        -B <can>    (bridge mode - like '-b' with disabled loopback)
        -l          (log CAN-frames into file. Sets '-s 2' by default)
        -L          (use log file format on stdout)
        -n <count>  (terminate after receiption of <count> CAN frames)
        -r <size>   (set socket receive buffer to <size>)
Up to 16 CAN interfaces with optional filter sets can be specified
on the commandline in the form: <ifname>[,filter]*
Comma separated filters can be specified for each given CAN interface:
 <can_id>:<can_mask> (matches when <received_can_id> & mask == can_id & mask)
 <can_id>~<can_mask> (matches when <received_can_id> & mask != can_id & mask)
 #<error_mask>       (set error frame filter, see include/linux/can/error.h)
CAN IDs, masks and data content are given and expected in hexadecimal values.
When can_id and can_mask are both 8 digits, they are assumed to be 29 bit EFF.
Without any given filter all data frames are received ('0:0' default filter).
Use interface name 'any' to receive from all CAN interfaces.
  • Examples:
candump -c -c -ta can0,123:7FF,400:700,#000000FF can2,400~7F0 can3 can8
candump -l any,0~0,#FFFFFFFF    (log only error frames but no(!) data frames)
candump -l any,0:0,#FFFFFFFF    (log error frames and also all data frames)
candump vcan2,92345678:DFFFFFFF (match only for extended CAN ID 12345678)
candump vcan2,123:7FF (matches CAN ID 123 - including EFF and RTR frames)
candump vcan2,123:C00007FF (matches CAN ID 123 - only SFF and non-RTR frames)

EVM Information

  • AM3517 EVM User's Guide
  • AM3517 EVM consists of two boards - Experimenter base board and Application board.
  • CAN interface is available on connectors J15 and J36 on the application board. The pin connections are as follows:
Pin 1 - CAN-H
Pin 2 - CAN-L
Pin 3 - Bus termination (do not connect a wire to this externally)
Pin 4 - Ground 
  • A Cable is needed to connect pins 1-1, 2-2 and 4-4 for connection between boards.
  • CAN bus termination - Short pins 2 & 3 on J15 to terminate the CAN bus
  • To connect two boards the following connections have to be made
Short pins 2 & 3 on J15 on each board
Board A J36 pins 1,2,4 connected to pins 1,2,4 of J36 on Board B respectively
No connection on pin 3 of J36 on any board
  • Note that at low speeds and short cable distances, it may be possible to use the CAN bus without termination installed, or with termination only at one end of the bus.
  • To connect two or more AM3517 boards using CAN the bus would look like this:
Board A J15 pins 2 & 3 shorted to terminate bus
Board A J36 pins 1,2,4 connect to Board B J36 pins 1,2,4 respectively
Board B J15 pins 1,2,4 connect to Board C J36 pins 1,2,4 respectively
Board C J15 pins 2 & 3 connected to terminate bus 
  • If you wanted to connect even more boards follow a similar pattern using J15 and J36 to connect any boards in the middle of the chain, and use J36 to connect and J15 to terminate boards at the end of the chain.