SR NO | Chapter | Page Num |
---|---|---|
1 | Hardware selection and connection | This covers the basics of choosing the right hardware components and ensuring proper connections to ensure optimal performance. |
2 | Linux Driver & Userspace Program and CLE | In this, you’ll learn about Linux drivers, the communication between user space and the kernel, and how to utilize the Command Line Environment (CLE). |
3 | Rough | This section may be under development or covers an initial overview of the topic. |
For this tutorial, we will be using the MYIR Tech Development Board. Specifically, the following:
The following CAN modules are recommended. You can choose one of them:
To enable CAN bus support on Linux boards, the following two ICs are required to establish communication between the system and the physical CAN bus network:
Function:
Interface:
Most common: MCP2515
Function:
Interface:
Most common: TJA1050, MCP2551
Best Transceiver: MCP2561
Note: MCP2551 is not recommended for new designs; use MCP2561 instead.
Many modules are available. Make sure they match the required configuration.
Before proceeding, set up a serial console. For more details, refer to this link: {Insert Link}
Note: Be careful about power pins (VCC, GND). Incorrect connections can easily damage the board.
Find the SPI pins on the development board (on MYIR Tech board, pin names are written on the back of the c8mmx board).
Also, split the supply voltage for both ICs.
If using this board, some small adjustments may be required, which might need soldering skills. Otherwise, you're good to go.
For more details, check out this forum thread:
To connect the module, use the SPI pin and one more pin for GPIO interrupt. Ensure that this GPIO pin is not allocated to other features.
SN | MYD-C8MMX (ECSPI2, See back of the board) | ((bank - 1) * 32) + pin | MCP2515 |
---|---|---|---|
NA | J23-1: 3V3 | NA | VCC |
gpio5.IO[13] | J23-2: ECSPI2_SS0 | 141 | CS |
gpio5.IO[11] | J23-3: ECSPI2_MOSI | 139 | SI |
gpio5.IO[12] | J23-4: ECSPI2_MISO | 140 | SO |
gpio5.IO[10] | J23-5: ECSPI2_SCLK | 138 | SCLK |
NA | J23-6: GND | NA | GND |
gpio4.IO[10] | J16-14: SAI1_TXFS | 106 | INT |
So here hardware is done, now moving to software part
To get the system working, you need to understand two key aspects:
In Linux, there are two types of drivers for CAN:
I’ve used and preferred SocketCAN, which is the network socket-based driver. Specifically, I
worked with SAE J1939 and used hardware from Microchip: MCP251x
.
I recompiled the Linux image and booted from the SD card. The new DTS changes and drivers are reflected in the boot process.
You can download the modified DTS file from the following link:
For the Linux config file, refer to the following directory:
Alternatively, check the source on GitHub:
To launch the kernel menuconfig, use the following command:
After making your changes, rebuild the kernel using:
This is my configuration for Linux/arm64 4.9.170 Kernel.
Menuconfig changesLinux Kernel Configuration. [*] Networking support ---> <*> CAN bus subsystem support ---> <*> Raw CAN Protocol (raw access with CAN-ID filtering) <*> Broadcast Manager CAN Protocol (with content filtering) <*> CAN Gateway/Router (with netlink configuration) CAN device drivers <M> Virtual Local CAN Interface (vcan) <*> Platform CAN drivers with Netlink support [*] CAN bit-timing calculation CAN SPI interfaces ---> <M> Microchip MCP251x SPI CAN controllers [*] CAN devices debugging messages
After these changes, recompile Linux, and load it into your hardware.
We were using MYIR Tech development board (specifically MYC-C8MMX-V2)
root@myd-imx8mm:~# modprobe can
[ 25.901538] can: controller area network core (rev 20170425 abi 9)
[ 25.907887] NET: Registered protocol family 29
root@myd-imx8mm:~# modprobe can-dev
root@myd-imx8mm:~# modprobe can-raw
[ 25.948100] can: raw protocol (rev 20170425)
root@myd-imx8mm:~# rmmod mcp251x
root@myd-imx8mm:~# modprobe mcp251x
[ 26.274264] mcp251x spi1.0: Cannot initialize MCP2515. Wrong wiring?
[ 26.280681] mcp251x spi1.0: Probe failed, err=19
root@myd-imx8mm:~# echo "8 4 1 7" > /proc/sys/kernel/printk
root@myd-imx8mm:~# rmmod mcp251x
root@myd-imx8mm:~# modprobe mcp251x
[ 94.513452] mcp251x spi1.0: MCP251x didn't enter in conf mode after reset
[ 94.520300] mcp251x spi1.0: Probe failed, err=16
[ 94.525162] mcp251x: probe of spi1.0 failed with error -16
root@myd-imx8mm:~# ip link set can0 type can bitrate 125000
Cannot find device "can0"
root@myd-imx8mm:~# ip link set up can0
Cannot find device "can0"
root@myd-imx8mm:~# ip link show can0
Device "can0" does not exist.
root@myd-imx8mm:~# ifconfig can0
can0: error fetching interface information: Device not found
The best way to troubleshoot this is to use a USB Logic Analyzer. Simply connect your SPI pins to the analyzer and check according to the CAN protocol if it is sending and receiving data.
----
Follow the steps below for installing can-utils
. More details can be found at
elinux.org/Can-utils:
git clone https://github.com/linux-can/can-utils.git
cd can-utils
./autogen.sh
./configure
make
make install (with root privileges)
sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0
sudo ip link set can0 type can bitrate 125000
sudo ip link set up can0
ifconfig vcan0
A detailed explanation on J1939 can be found at: