How to modify CANBUS clock frequency on Xavier?

Hi
I followed below sources and succeeded in setting up canbus on xavier.

https://elinux.org/Jetson/AGX_Xavier_CAN
and

Rest of my hardware system works on clock frequency 8Mhz. But xavier is working on 50Mhz.
How can I modify xavier frequency? (Below is CAN statistics)


Why I need to modify? Because When I try to write canmsg through xavier, It gets disconnected with CANBUS network after sending some msgs. Anyways reading works fine.

Just for reference (Working PCAN output on another computer)

Hi,
To update CAN clock, you have to modify kernel mttcan driver in our kernel source code:
static const struct tegra_mttcan_soc_info t194_mttcan_sinfo = {
.set_can_core_clk = true,
.can_core_clk_rate = 50000000, /// 8000000
.can_clk_rate = 200000000, /// 32000000
.use_external_timer = true,
};

Thanks,
Shubhi

1 Like

I have downloaded and modified the
‘Jetson_L4T_31.1.0/kernel_src/kernel/nvidia/drivers/net/can/mttcan/native/m_ttcan_linux.c’

to static const struct tegra_mttcan_soc_info t194_mttcan_sinfo = {
	.set_can_core_clk = true,
        .can_core_clk_rate = 8000000, /// 50000000	
        .can_clk_rate = 32000000, /// 200000000		
	.use_external_timer = true,
};

How to build and install this driver?
Sorry for this naive question.
Thank you

Hi,
Please follow:
https://docs.nvidia.com/jetson/l4t/index.html#page/Tegra%20Linux%20Driver%20Package%20Development%20Guide/kernel_custom.html

After it is built, you can replace mttcan.ko in target:
/lib/modules/4.x.xxx-tegra/kernel/drivers/net/can/mttcan/native/mttcan.ko
and reboot device.

Thanks,
Shubhi

sudo apt install build-essential bc
cd Jetson_L4T_31.1.0/kernel_src/kernel/kernel-4.9
TEGRA_KERNEL_OUT=build
mkdir -p $TEGRA_KERNEL_OUT
make ARCH=arm64 O=$TEGRA_KERNEL_OUT tegra_defconfig
make ARCH=arm64 O=$TEGRA_KERNEL_OUT -j8

cd /lib/modules/4.9.108-tegra/kernel/drivers/net/can/mttcan/native
sudo mv mttcan.ko mttcan_backup.ko
sudo cp Jetson_L4T_31.1.0/kernel_src/kernel/kernel-4.9/build/drivers/net/can/mttcan/native/mttcan.ko mttcan.ko

Reboot
It works Thanks @shgarg