Hello. Wanted to share how I got the MCAN0 interface working in conjunction with a mikroBUS Single Wire CAN Click. First thing to note is the TX and RX are swapped on the MCAN0 interface which in turn means the CAN Click boards will not work as is. I had to modify the board to swap RX and TX. I did this by cutting the traces on the backside of the click board and then running wires from the IC to the click pins.
Next is modifying the Device Tree to enable the MCAN0 controller. I wasn’t really certain on how to go about this but thanks to a few examples and looking at the existing BeaglePlay DTS files I managed to get it working. I’m also certain there’s better ways to do this but I don’t know any better to say what they are. But I do want to say thanks to Nishanth Menon on here, Discord and Youtube for their great replies to other and videos that helped me get this working.
First I watched this Steps to modify and build device tree for BeaglePlay to learn the steps to modify and build the DTS files.
With the how out of the way, now modify k3-am625-beagleplay.dts located at /opt/source/dtb-5.10-ti/src/arm64/. Under the ‘aliases’ section add ‘can0 = &main_mcan0’, it will look like the following, minus the existing entries, leave those as is:
aliases {
can0 = &main_mcan0;
};
Next we need to add the PIN mux control under the ‘&main_pmx0’ section, leave everything else there and add it at the bottom, like so:
&main_pmx0 {
mikrobus_uart_pins_can: mikrobus-uart-pins-can {
pinctrl-single,pins = <
AM62X_IOPAD(0x01dc, PIN_INPUT, 0) /* (E15) MCAN0_RX */
AM62X_IOPAD(0x01d8, PIN_OUTPUT, 0) /* (C15) MCAN0_TX */
>;
};
};
Now find the ‘&main_mcan0’ section and modify it to look like the following:
&main_mcan0 {
status = "okay";
symlink = "play/mikrobus/can";
};
This should now enable the CAN bus and allow us to switch the MUX over to it as well. Next and because I’m new at this I used an example overlay file and modified it to the following:
// SPDX-License-Identifier: GPL-2.0
/*
* DT Overlay for disabling mikrobus device driver.
*
* Copyright (C) 2023 Jason Kridner, BeagleBoard.org Foundation
*/
/dts-v1/;
/plugin/;
&{/chosen} {
overlays {
K3-am625-beagleplay-release-mikrobus-can = __TIMESTAMP__;
};
};
&mikrobus0 {
status = "disabled";
};
/*
* Setup default muxes for peripheral drivers to do them instead
* of depending on mikrobus driver to select
*/
&main_i2c3 {
pinctrl-names = "default";
pinctrl-0 = <&mikrobus_i2c_pins_default>;
};
&main_spi2 {
pinctrl-names = "default";
pinctrl-0 = <&mikrobus_spi_pins_gpio>;
};
&main_mcan0 {
status = "okay";
symlink = "play/mikrobus/can";
pinctrl-names = "default";
pinctrl-0 = <&mikrobus_uart_pins_can>;
};
&main_gpio1 {
pinctrl-names = "default";
pinctrl-0 = <&mikrobus_gpio_pins_default>;
};
Saving it as ‘k3-am625-beagleplay-release-mikrobus-can.dts’. The important things here is we disable the mikroBUS, switch the UART pin MUX over to MCAN0 and switched the SPI pins to GPIO. RST and SPI2_CS0 are connected to the SWCAN transceiver mode pins.
With both files modified now I ran
make
sudo make install_arm64
sync
Basically following the video. Now enable the overlay and then reboot:
echo " fdtoverlays /overlays/k3-am625-beagleplay-release-mikrobus-can.dtbo" | sudo tee -a /boot/firmware/extlinux/extlinux.conf
sudo reboot
Once the BeaglePlay reboots you should see the can0 interface, i truncated the other interfaces:
debian@BeaglePlay:~$ ip link
5: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
link/can
To set the GPIO pins for the transceiver mode I used the following:
gpioset 601000.gpio 12=1
gpioset 601000.gpio 13=1
GPIO 12 is the RST pin and 13 is CS0.
Now setup the CAN interface:
sudo ip link set can0 type can bitrate 33333
sudo ip link set can0 up
After that the CAN bus should be functional.
Good Luck.
Lyle