OK. Here goes with some code formatting ;-)
I couldn't for some reason attach a zip file -- so I've now put all the needed files on github -- so you should be able to get the files you need by clone the repository from your Beaglebone / Bela:
git clone https://github.com/glennsky/bela_CAN.git
Then to copy the files to their appropriate place - you can just run the copy_to_bela script:
cd bela_CAN
./copy_to_bela
Hopefully this will copy everything you need to the right place on the Beaglebone and upon reboot you CAN bus will be enabled! However, below are more details...
I've only tested things on a Beaglebone Green, but it works with Bela images v0.1.0a to v0.2.0b. I also included the Beaglebone Black .dtb/.dts file with the same changes so it should also work - but not tested. This is the relevant part that is changed -- moving the I2C1 pins to other pins to allow the DCAN1 to use those pins. Original line left there but commented out.
pinmux_i2c1_pins {
//pinctrl-single,pins = <0x180 0x73 0x184 0x73>;
pinctrl-single,pins = <0x168 0x73 0x16C 0x73>;
linux,phandle = <0x7>;
phandle = <0x7>;
};
To compile the .dts files you do:
dtc -O dtb -o am335x-boneblack.dtb -b 0 -@ am335x-boneblack.dts
dtc -O dtb -o am335x-bonegreen.dtb -b 0 -@ am335x-bonegreen.dts
Then they need to be copied to /boot/uboot/dtbs
The device tree overlay for the DCAN1 is BB-DCAN1-00A0.dts:
/dts-v1/;
/plugin/;
/ {
compatible = "ti,beaglebone", "ti,beaglebone-black", "ti,beaglebone-green";
/* identification */
part-number = "dcan1pinmux";
fragment@0 {
target = <&am33xx_pinmux>;
__overlay__ {
dcan1_pins_s0: dcan1_pins_s0 {
pinctrl-single,pins = <
0x180 0x12 /* d_can1_tx, SLEWCTRL_FAST | INPUT_PULLUP | MODE2 */
0x184 0x32 /* d_can1_rx, SLEWCTRL_FAST | RECV_ENABLE | INPUT_PULLUP | MODE2 */
>;
};
};
};
fragment@1 {
target = <&dcan1>;
__overlay__ {
#address-cells = <1>;
#size-cells = <0>;
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&dcan1_pins_s0>;
};
};
};
Which is compiled with:
dtc -O dtb -o BB-DCAN1-00A0.dtbo -b 0 -@ BB-DCAN1-00A0.dts
And then the .dtbo copied to /lib/firmware
Then you need to startup the CAN at bootup by adding these lines to /etc/rc.local
su -c "echo BB-DCAN1 > /sys/devices/bone_capemgr.9/slots"
su -c "modprobe can"
su -c "modprobe can-dev"
su -c "modprobe can-raw"
su -c "ip link set can0 up type can bitrate 500000"
su -c "ip link set can0 up txqueuelen 16"
su -c "ifconfig can0 up"
exit 0
You may want to change the bitrate to whatever you're using. I added the txqueuelen 16 to have a slightly larger transmit buffer.
If all goes well, upon reboot -- you'll be able to see the can0 by doing:
ifconfig
You can check for bootup messages regarding the CAN bus by doing:
dmesg | grep -i CAN
You should also install can-utils -- very useful socketcan routines.
sudo apt-get install can-utils
Then you should be able to run this command to see incoming packets on the CAN bus.:
candump can0
Good luck!! Let me know if it works...
Glenn