Supporting CAN in i.MX RT uClinux BSP

1. Overview

This project develops Linux CAN device driver in the Linux BSP for the i.MX RT processor.

2. Requirements

2.1. Detailed Requirements

The following are the requirements for this project:

  1. Provide a Linux demo project combining all the requirements in this project.

  2. Develop Linux CAN device driver for the i.MX RT CAN controller.

  3. Port CANSocket to the Linux i.MX RT BSP.

  4. Validate successful execution of the test suite from the SocketCAN package.

2.2. Detailed Non-Requirements

The following are the non-requirements for this project that may otherwise not be obvious:

  1. None

3. Design

3.1. Detailed Design

3.1.1. Design: Demo project

This project will enable the required CAN functionality in Linux configuration ("embedded project") called rootfs, which resides in a projects/rootfs directory, relative to the top of the Linux i.MX RT installation.

3.1.2. Design: Linux CAN Device Driver

The internal i.MX clocks necessary for the CAN interface will be enabled in the kernel. The i.MX RT flexcan interface network driver linux/drivers/net/can/flexcan.c will be enabled, and the respective changes will be added to the kernel .dts file.

The flexcan functionality will be enabled in the Linux kernel configuration as follows:

  • Go to Networking support -> CAN bus subsystem support -> CAN Device Drivers

  • Enable Platform CAN drivers with Netlink support (CONFIG_CAN_DEV) and Support for Freescale FLEXCAN based chips (CONFIG_CAN_FLEXCAN)

3.1.3. Design: CANSocket

The CAN socket API, described in details in linux/Documentation/networking/can.txt, will be enabled using the Raw CAN Protocol (raw access with CAN-ID filtering) and Broadcast Manager CAN Protocol (with content filtering) configuration options in the Networking support -> CAN bus subsystem support configuration menu.

3.1.4. Design: CANSocket Test Suite

The can-utils and can-tests packages will be used for verification of the functionality implemented in this project.

3.2. Effect on Related Products

This project makes the following updates in the related products:

  • None

3.3. Changes to User Documentation

This project updates the following user documents:

  • None

3.4. Alternative Design

The following alternative design approaches were considered by this project but then discarded for some reason:

  • None

4. Test Plan

4.1. Secure Download Area

The downloadable materials developed by this project are available from a secure Web page on the Emcraft Systems web site. Specifically, proceed to the following URL to download the software materials:

  • For the i.MX RT1024 BSP release:

The page is protected as follows:

Login: CONTACT EMCRAFT

Password: CONTACT EMCRAFT

  • For the i.MX RT1050 BSP (release 3.0.4):

The page is protected as follows:

Login: CONTACT EMCRAFT

Password: CONTACT EMCRAFT

  • For the i.MX RT1050 BSP (release 3.1.0):

The page is protected as follows:

Login: CONTACT EMCRAFT

Password: CONTACT EMCRAFT

  • For the i.MX RT1060 BSP (release 3.1.0):

The page is protected as follows:

Login: CONTACT EMCRAFT

Password: CONTACT EMCRAFT

  • For the i.MX RT1170 BSP release:

The page is protected as follows:

Login: CONTACT EMCRAFT

Password: CONTACT EMCRAFT

4.2. Downloadable Files

The following files are available from the secure download area:

  • linux-flexcan.patch - patch to the Linux kernel sources;

  • projects-flexcan.patch - patch to the rootfs project;

  • rootfs.uImage - prebuilt bootable Linux image;

Refer to the below sections for the instructions on how to install and use these files.

4.3. Test Set-Up

4.3.1. Hardware Setup

The following hardware setup is required for the i.MX RT1024 boards:

for the i.MX RT1050 boards:

for the i.MX RT1060 boards:

  • The i.MX RT1060 EVKB board, with the serial console attached as per Connecting Serial Console to the NXP i.MX RT10XX EVK Board .

  • A Linux PC with the VSCOM USB-CAN USB to CAN Adapter http://www.vscom.de/vscom-usb-can.html plugged into a USB port on the PC, and the following connections to the i.MX RT1060 EVKB board:

    • DB9.2 of USB-CAN connected to CANL J42.3 on the i.MX RT EVK board.

    • DB9.7 of USB-CAN connected to CANH J42.1 on the i.MX RT EVK board.

    • DB9.3 of USB-CAN connected to GND J42.2 on the i.MX RT EVK board.

for the i.MX RT1170 boards:

4.3.2. Software Setup

The following software setup is required:

  1. Download the files listed in Section: "Downloadable Files" to the top of the Linux i.MX RT installation.

  2. Install the BSP, as per the respective "Installing and activating cross development environment" document in the "Software" section on the Emcraft site.

  3. From the top of the Linux installation, activate the Linux cross-compile environment by running:

    $ . ./ACTIVATE.sh
  4. Install U-Boot to the target board.

  5. From the top of the BSP installation, go to the Linux kernel tree and install the kernel patch, eg:

    $ cd linux/ $ patch -p1 < ../../linux-flexcan.patch
  6. From the top of the Linux installation, go to the projects sub-directory, and patch the rootfs project:

    $ cd projects/ $ patch -p1 < ../../projects-flexcan.patch
  7. On the Linux PC intended for execution of the CANsocket test suite, ensure that the following software is installed (Emcraft used Linux PC running the Fedora 16 (3.1.0-7.fc16.i686.PAE) installation; the other Linux distributives should work too, but may require some additional steps like compilation and installation of the CAN framework kernel modules):

    1. Install can-utils package on the Linux PC (commands below are for a Fedora host):

    2. Install and build can-tests on the Linux PC:

    3. Load the CAN kernel modules on the Linux PC:

  8. Connect the VSCOM USB-CAN adapter to the Linux PC and configure it as follows:

    1. Get the VSCOM USB-CAN serial device name (in the example below it is ttyUSB0):

    2. Configure the VSCOM USB-CAN adapter to run with a 1Mbps CAN-bus speed (the -s8 parameter in slcan_attach), enable the corresponding network interface:

    3. If you have disconnected the VSCOM USB-CAN adapter from the Linux PC, before reconnecting it back run the following command:

4.4. Detailed Test Plan

4.4.1. Test Plan: Demo Project

Perform the following step-wise test procedure:

  1. Go to the projects/rootfs directory, build the loadable Linux image (rootfs.uImage) and copy it to the TFTP directory on the host:

  2. Boot the loadable Linux image (rootfs.uImage) to the target via TFTP and validate that it boots to the Linux shell:

4.4.2. Test Plan: Linux CAN Driver

Perform the following step-wise test procedure:

  1. In the kernel bootstrap messages, validate that the CAN driver has been successfully installed and activated:

4.4.3. Test Plan: CANSocket

Perform the following step-wise test procedure:

  1. On the target, configure the CAN network:

  2. Test target to Linux PC transfers:

    • Run the capture utility on the Linux PC:

    • Send packets from the target to the host:

    • Validate that the packets have been captured on the Linux PC:

    • On the host, stop the capture utility by pressing Ctrl-C:

  3. Test Linux PC to target transfers:

    • Run the capture utility on the target:

    • Send packets from the Linux PC to the target:

    • Validate that the packets have been captured on the target:

    • On the target, stop the capture utility by pressing Ctrl-C:

4.4.4. Test Plan: CANSocket Test Suite

Perform the following step-wise test procedure:

  1. Run the tst-raw Linux PC to target test:

    • On the target:

    • On the Linux PC:

    • Observe the test data on the target, then press Ctrl-C and complete the test:

  2. Run the tst-raw target to Linux PC test:

    • On the Linux PC:

    • On the target:

    • Observe test data on the Linux PC, then press Ctrl-C and complete the test:

  3. Run the tst-packet Linux PC to target test:

    • On the target:

    • On the Linux PC send a packet, then press Ctrl-C and complete the test:

    • Observe the test packet on the target, then press Ctrl-C and complete the test:

  4. Run the tst-packet target to Linux PC test:

    • On the Linux PC:

    • On the target, send a packet, then press Ctrl-C and complete the test:

    • Observe the test packet on the Linux PC, then press Ctrl-C and complete the test:

  5. Run the tst-filter test on the target:

  6. Run the tst-rcv-own-msgs test on the target: