Skip to main content

Installation and Driver Startup

Folder Structure​

Folder/File NameDetails
01_drvDirectory containing the SocketCAN driver itself.
02_sampleDirectory containing sample scripts.
Readme.txtIncluded description file.

Installation Method​

Build the Driver (First Time Only)​

  1. Copy the 01_drv directory to the Linux PC.
  2. Move to 01_drv in the terminal and run the make command (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.

ItemDefault setting
Communication protocolClassical CAN
MTU16
Arbitration bitrate500000
Data bitrateNot used
CAN FDDisabled (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
note

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.

  1. Start the SocketCAN kernel driver.
sudo modprobe can
  1. Load the device driver library.
sudo modprobe can_dev
  1. Load the MicroPeckerX driver.
sudo insmod ./MpxDrv.ko
  1. 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 specificationSetting value
Classical CANmtu 16
CAN FDmtu 72

Main mpdrv_run Commands​

CommandDetails
./mpdrv_run load [params...]Loads the driver. Module parameters can be specified.
./mpdrv_run start-allStarts can0 / can1 in sequence. Normally use this command.
./mpdrv_run start can0Starts only can0. For communication use, normally use start-all.
./mpdrv_run start can1Starts only can1. For communication use, normally use start-all.
./mpdrv_run stop can0Stops can0.
./mpdrv_run stop can1Stops can1.
./mpdrv_run restartRestarts the driver and carries over the previous settings as much as possible.
./mpdrv_run removeUnloads the driver.
./mpdrv_run statusDisplays 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 variableDetails
MPX_BITRATESpecifies the arbitration bitrate.
MPX_DBITRATESpecifies the CAN FD data bitrate.
MPX_CANFDStarts 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 protocolMPX_CANFDMPX_BITRATEMPX_DBITRATEArbitration sample pointData sample point
Classical CAN0 or omitted500000-80.0%-
Classical CAN0 or omitted1000000-80.0%-
CAN FD1500000200000080.0%80.0%
CAN FD1500000400000080.0%80.0%
CAN FD1500000500000080.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.

parameterDetails
bitrateThe default arbitration bitrate used when no bitrate is specified on the SocketCAN side.
dbitrateThe default data bitrate used when no data bitrate is specified for CAN FD.
terminationSpecifies device-side termination. 1 enables it, and 0 disables it.
enable_hwtsSpecifies receive hardware timestamp information. 1 enables it, and 0 disables it.

Example:

./mpdrv_run load bitrate=500000 dbitrate=2000000 termination=1 enable_hwts=1
tip

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.