Skip to content

Installation Guide ​

This section describes KH-UCANFD_Linux_SDK installation process, as well as cross-compilation, channel binding, and other operation instructions.

System Environment Requirements ​

  1. Linux system running 32-bit or 64-bit kernel
  2. make, gcc compilation tools
  3. Linux system kernel header files (or Linux header file packages), or cross-compiling kernel source tree
  4. g++ compiler and libstdc++ library
  5. libpopt-dev package

Dependency Installation Commands ​

Before installing driver, please confirm that system environment meets above requirements, and execute the following commands to install dependencies:

bash
# 1. Install compilation basic tools
sudo apt update && sudo apt install -y build-essential g++

# 2. Install kernel headers (must match current kernel version)
sudo apt install -y linux-headers-$(uname -r)

# 3. Install libpopt dependency
sudo apt install -y libpopt-dev

# 4. Verify gcc version (must match kernel compilation version, query method as follows)
cat /boot/config-$(uname -r) | grep -i "gcc_version"
# Example output: CONFIG_GCC_VERSION=120300 (indicates need to install gcc-12)
# If version does not match, install corresponding gcc: sudo apt install -y gcc-12

SDK Download ​

You can manually download from releases, or use wget.

bash
# Install wget (if not installed)
sudo apt install -y wget

# Download SDK (latest version)
wget https://gitee.com/ChengDu-KunHong/KH-UCANFD_Linux_SDK/releases/download/latest/KH-UCANFD_Linux_SDK.zip

# Unzip SDK
unzip KH-UCANFD_Linux_SDK.zip

# Enter SDK directory (replace x.y.z with actual version number)
cd KH-UCANFD_Linux_SDK_x.y.z/

Compilation and Installation ​

Script Automatic Installation ​

After entering SDK directory, execute the following commands to complete one-click installation:

bash
# Execute compilation script
./build.sh

build.sh Script Usage:

bash
Usage:
  ./build.sh                    Install driver
  ./build.sh -c                 Cross-compile driver
  ./build.sh -rules             Install driver and load udev naming rules
  ./build.sh -u                 Uninstall driver
  ./build.sh -uninstall         Uninstall driver
  ./build.sh -h                 Display help information

Manual Installation ​

Execute the following commands to complete driver compilation and installation:

bash
# Clean historical compilation files
sudo make clean

# Compile driver (if errors, check if dependencies are complete, if gcc version matches)
sudo make netdev

# Install driver (no errors means successful installation)
sudo make install

Driver Loading Verification ​

Load driver:

bash
# Load kcan driver module
sudo modprobe kcan

# Verify if driver is loaded successfully (output containing "kcan" means normal)
lsmod | grep kcan

List Information Demo

After unplugging and replugging CAN FD device, execute the following commands to confirm device is recognized:

bash
# View CAN interface information (output containing "can0", "can1", etc. means normal)
ip -d link show

ipdlinkshow

bash
# View USB device driver binding (output containing "Driver=kcan" means normal)
lsusb -t

ipdlinkshow

Cross-Compilation ​

The automatic compilation script can help you complete cross-compilation more easily. Operation steps are as follows:

  • Prepare cross-compilation environment: install cross-compilation toolchain, kernel source code, etc.
  • Open cross_compile_config.sh in SDK directory, modify corresponding paths.
bash
export ARCH=arm64  # Set target architecture to ARM64
export CROSS_COMPILE=/path/to/your/toolchain/bin/aarch64-linux-gnu-  # Set cross-compilation toolchain path
export KERNEL_LOCATION=/path/to/your/kernel-source/  # Set kernel source code path
  • Execute compilation script:
bash
./build.sh -c

cross_compile

Uninstall Driver ​

Uninstall driver:

bash
# Use script to uninstall
sudo ./build.sh -u

# make uninstall
sudo make uninstall

Channel Binding ​

SDK provides three channel binding methods: driver binding, USB binding, and ID binding.

Driver Binding ​

Through build.sh script, corresponding udev rules are automatically configured and loaded, using kcan as the driver device name for all devices.

Operation Steps ​

  1. Execute build script and automatically load udev rules:
bash
sudo ./build.sh -rules
  1. After compilation is complete, unplug and replug device.

Effect Verification ​

The effect after successful binding is shown in the figure below:

driver bind

USB Binding ​

Overview ​

By manually setting udev rules, specific channel names are bound according to USB port information.

Operation Steps ​

1. Get Device Port Information ​

Use the following command to get device USB port information:

bash
udevadm info -a /sys/class/net/can0

Output example is shown in figure below:

udevadm

2. Create udev Rules File ​

Create rules file:

bash
sudo vi /etc/udev/rules.d/99_kcan_usb.rules

Add the following content to the file (modify KERNELS, NAME parameters according to actual situation):

bash
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="kcan", KERNELS=="5-1.3:1.0", NAME="kcan0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="kcan", KERNELS=="5-1.4:1.0", NAME="kcan1"
3. Reload udev Rules ​
bash
sudo udevadm control --reload-rules
sudo udevadm trigger
4. Verify Binding Effect ​

Unplug and replug device. The binding effect is shown in the figure below:

usb bind

ID Binding ​

Overview ​

By setting device ID and configuring driver parameters, channel binding is achieved.

Operation Steps ​

1. Modify CAN Device ID ​

Use kcan-settings tool to set device ID for each channel:

bash
# Set can0 channel ID to 66
kcan-settings -f=/dev/kcanusbfd32 -d 66

# Set can1 channel ID to 67
kcan-settings -f=/dev/kcanusbfd33 -d 67

# Continue setting other channels...
2. Confirm ID Setting Success ​

View device ID:

bash
kcan-settings -f=/dev/kcanusbfd32 -d
3. Modify Driver Configuration File ​

Edit kcan driver configuration file:

bash
sudo vi /etc/modprobe.d/kcan.conf

Add the following configuration parameters to the file:

bash
# Enable assignment based on device ID
options kcan assign=devid
4. Reload Driver Module ​
bash
sudo rmmod kcan
sudo modprobe kcan
5. Verify Binding Effect ​

Unplug and replug device. The ID binding effect is shown in the figure below:

id bind

Driving Intelligent Connections, Empowering the Future
蜀ICP备2023000218号-2