Installation and Driver Startup
Folder Structure
| Folder/File Name | Details |
|---|---|
01_drv | Directory containing the SocketCAN driver itself. |
02_sample | Directory containing sample scripts. |
Readme.txt | Included description file. |
Installation Method
Build the Driver (First Time Only)
- Copy the
01_drvdirectory to the Linux PC. - Move to
01_drvin the terminal and run themakecommand (GCC required).
cd 01_drv
make
A binary for the currently running kernel is generated.
Starting the MicroPeckerX SocketCAN Driver
Driver Startup (Simple Version)
mpdrv_run is a script that summarizes the startup procedure for the MicroPeckerX SocketCAN driver.
For normal communication checks, start both can0 / can1 with start-all.
cd 01_drv
chmod +x mpdrv_run
./mpdrv_run load
./mpdrv_run start-all
You can check the startup status as follows.
./mpdrv_run status
With the simple startup above, if environment variables or module parameters are not specified, can0 / can1 are started with the following settings.
| Item | Default setting |
|---|---|
| Communication protocol | Classical CAN |
| MTU | 16 |
| Arbitration bitrate | 500000 |
| Data bitrate | Not used |
| CAN FD | Disabled (fd off) |
To start with CAN FD, specify MPX_CANFD, MPX_BITRATE, and MPX_DBITRATE, and then run start-all.
MPX_CANFD=1 MPX_BITRATE=500000 MPX_DBITRATE=2000000 ./mpdrv_run start-all
Due to the specifications of the MicroPeckerX firmware, start both can0 / can1 when performing communication. If only one side is started, it may appear as UP in SocketCAN but may not be able to send or receive.
Driver Startup (Step-by-Step Version)
This is the procedure for starting manually without using mpdrv_run.
- Start the SocketCAN kernel driver.
sudo modprobe can
- Load the device driver library.
sudo modprobe can_dev
- Load the MicroPeckerX driver.
sudo insmod ./MpxDrv.ko
- Start can0 / can1 as Classical CAN at 500 kbps.
sudo ip link set can0 mtu 16
sudo ip link set can0 up type can bitrate 500000 fd off
sudo ip link set can1 mtu 16
sudo ip link set can1 up type can bitrate 500000 fd off
To start as CAN FD, set the MTU to 72 and specify fd on and dbitrate.
sudo ip link set can0 mtu 72
sudo ip link set can0 up type can bitrate 500000 dbitrate 2000000 fd on
sudo ip link set can1 mtu 72
sudo ip link set can1 up type can bitrate 500000 dbitrate 2000000 fd on
The setting values are as follows.
| Protocol specification | Setting value |
|---|---|
| Classical CAN | mtu 16 |
| CAN FD | mtu 72 |
Main mpdrv_run Commands
| Command | Details |
|---|---|
./mpdrv_run load [params...] | Loads the driver. Module parameters can be specified. |
./mpdrv_run start-all | Starts can0 / can1 in sequence. Normally use this command. |
./mpdrv_run start can0 | Starts only can0. For communication use, normally use start-all. |
./mpdrv_run start can1 | Starts only can1. For communication use, normally use start-all. |
./mpdrv_run stop can0 | Stops can0. |
./mpdrv_run stop can1 | Stops can1. |
./mpdrv_run restart | Restarts the driver and carries over the previous settings as much as possible. |
./mpdrv_run remove | Unloads the driver. |
./mpdrv_run status | Displays the module status and detailed status of the CAN interfaces. |
Specifying Baud Rate and CAN FD
With mpdrv_run, you can specify the startup baud rate and CAN FD settings using environment variables.
| Environment variable | Details |
|---|---|
MPX_BITRATE | Specifies the arbitration bitrate. |
MPX_DBITRATE | Specifies the CAN FD data bitrate. |
MPX_CANFD | Starts as CAN FD when set to 1. If omitted or set to 0, Classical CAN is used. |
The supported communication baud rates and sample points are as follows. The sample points are fixed values.
| Communication protocol | MPX_CANFD | MPX_BITRATE | MPX_DBITRATE | Arbitration sample point | Data sample point |
|---|---|---|---|---|---|
| Classical CAN | 0 or omitted | 500000 | - | 80.0% | - |
| Classical CAN | 0 or omitted | 1000000 | - | 80.0% | - |
| CAN FD | 1 | 500000 | 2000000 | 80.0% | 80.0% |
| CAN FD | 1 | 500000 | 4000000 | 80.0% | 80.0% |
| CAN FD | 1 | 500000 | 5000000 | 80.0% | 75.0% |
Example of starting with Classical CAN 500 kbps:
MPX_BITRATE=500000 ./mpdrv_run start-all
Example of starting with Classical CAN 1 Mbps:
MPX_BITRATE=1000000 ./mpdrv_run start-all
Example of starting with CAN FD 500 kbps / 2 Mbps:
MPX_CANFD=1 MPX_BITRATE=500000 MPX_DBITRATE=2000000 ./mpdrv_run start-all
Example of starting with CAN FD 500 kbps / 4 Mbps:
MPX_CANFD=1 MPX_BITRATE=500000 MPX_DBITRATE=4000000 ./mpdrv_run start-all
Example of starting with CAN FD 500 kbps / 5 Mbps:
MPX_CANFD=1 MPX_BITRATE=500000 MPX_DBITRATE=5000000 ./mpdrv_run start-all
module parameter
The following module parameters can be specified during load.
| parameter | Details |
|---|---|
bitrate | The default arbitration bitrate used when no bitrate is specified on the SocketCAN side. |
dbitrate | The default data bitrate used when no data bitrate is specified for CAN FD. |
termination | Specifies device-side termination. 1 enables it, and 0 disables it. |
enable_hwts | Specifies receive hardware timestamp information. 1 enables it, and 0 disables it. |
Example:
./mpdrv_run load bitrate=500000 dbitrate=2000000 termination=1 enable_hwts=1
Please also refer to the following video (YouTube) for installation.
MicroPeckerX SocketCAN Driver Quick Start Guide (candump)
Note: The video is for an older version. In the latest version, normally start both can0 / can1 with start-all.