How to enable CAN Bus on Rock5B

Hello, I am trying to enable the CAN bus on the Rock 5B, but I am new to embedded Linux and device-trees so I’m having a bit of trouble.

The documentation[1] shows that CAN1 is exposed on the 40 pin header on two sets of pins via two different modes m0, and m1.

Inspecting the device tree shows that can1 (i.e. /can@fea60000) has status disabled and defaults to using the m0 pins, so I tried adding a device tree overlay[2] to enable it and use the m1 pins.

After rebooting, the changes do seem to have taken effect (as reported by /proc/device-tree/), but lsmod does not show any CAN related modules, nor does ip link show any CAN interfaces, nor is there any sort of /dev/can.

What more needs to be done to enable CAN, or am I even on the right track?

Thanks.

[1] https://wiki.radxa.com/Rock5/hardware/5b/gpio

[2]

/dts-v1/;
/plugin/;

&can1 {
    pinctrl-0 = <&can1m1_pins>;
    status = "okay";
};

Actually one thing I just noticed is that based on the rockchip-linux kernel source [1] it seems that rockchip_canfd.ko is the driver I need. Furthermore /proc/config shows both CONFIG_CAN_ROCKCHIP and CONFIG_CANFD_ROCKCHIP as being unset, which perhaps explains why nothing is working.

[1] https://github.com/radxa/kernel/blob/stable-5.10-rock5/drivers/net/can/rockchip/rockchip_canfd.c#L861

After compiling and installing the previously referenced kernel module, the CAN interface appears as desired. It remains to be seen whether or not it works but that is a problem for another day.

How did you compile modules? Can you provide more details how to replicate your results?

This was roughly my procedure, forgive me if I’ve missed a step or forgotten a dependency while reconstructing these steps. I’m not even sure if this is the proper way to go about this.

## Building CAN Kernel Module

# First install kernel build dependencies. See https://wiki.debian.org/BuildADebianKernelPackage
sudo apt install build-essential flex bison libssl-dev bc kmod cpio libelf-dev dwarves libncurses5-dev

# Grab kernel sources
git clone https://github.com/radxa/kernel.git radxa-kernel && cd radxa-kernel

# Checkout the specific commit of the currently running kernel.
# Radxa kernel releases are of the form <kernel_version>-rockchip-g<commit_sha>
# e.g. 5.10.110-37-rockchip-g74457be0716d
git checkout $(uname -r | sed 's/.*g\([0-9a-f]\+\)$/\1/')

# Copy symbol version dump from system (otherwise there will be some scary warnings).
cp /lib/modules/$(uname -r)/build/Module.symvers .

# Some kernel build preparations
make oldconfig

# Update .config with `CONFIG_CAN*_ROCKCHIP=m`
sed -i 's/# \(CONFIG_CAN\(FD\)\?_ROCKCHIP\) is not set/\1=m/' .config

# Continue kernel build preparations
make prepare
make modules_prepare

# Finally build the modules. They will be found at drivers/net/can/rockchip/rockchip_can*.ko
make M=drivers/net/can/rockchip
1 Like