Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdp7/1b6abf01d1adaaffb5214ef1cb0cb26c to your computer and use it in GitHub Desktop.
Save pdp7/1b6abf01d1adaaffb5214ef1cb0cb26c to your computer and use it in GitHub Desktop.
SWCAN instructions for PocketBeagle and Macchina M2

NOTE: the files /boot/uEnv.txt and /opt/source/bb.org-overlays/src/arm/PB-MCP2515-SPI1.dts are below in this Gist.

Step 1:

Download the BeagleBoard.org Debian SD card image from 2019-04-07 with kernel 4.14.108-ti-r103:

Step 2:

Change directory:

cd /opt/source/bb.org-overlays/

Paste the contents of PB-MCP2515-SPI1.dts or scp the file to the PocketBeagle over USB or WiFi:

sudo nano src/arm/PB-MCP2515-SPI1.dts

Change directory:

cd /opt/source/bb.org-overlays/

Compile the dts files and install compiled dtbo files

sudo install.sh

Verify that that the dtbo exists

ls -ltar /lib/firmware/PB-MCP2515-SPI1.dtbo

Edit the boot configuration

sudo nano /boot/uEnv.txt

add this line /boot/uEnv.txt to cause the MCP2515 overlay to be loaded:

uboot_overlay_addr0=/lib/firmware/PB-MCP2515-SPI1.dtbo

and then reboot.

Step 4

Run these commands to make the SWCAN transceiver M0/M1 modes pins go high (3.3V) for normal mode.

For P2.6:

sudo bash -c "echo out > /sys/class/gpio/gpio57/direction"
sudo bash -c "echo 1 > /sys/class/gpio/gpio57/value"

For P2.18:

sudo bash -c "echo out > /sys/class/gpio/gpio47/direction"
sudo bash -c "echo 1 > /sys/class/gpio/gpio47/value"

Note: the GPIO number to pin number mappings in on the PocketBeagle pin diagram

Step 4

Run these commands to initialize the can2 interface:

sudo ip link set can2 type can bitrate 33000 listen-only on
sudo ifconfig can2 up

Check that it is up:

sudo ifconfig can2

View the CAN traffic:

candump -cae can2,0:0,#FFFFFFFF

Note: The traffic received by the PocketBeagle is transmitted by a seperate Macchina M2 running SWCAN_TX_Example.ino. The mode pins on the transceiver are set in MCP2515_sw_can.cpp.

/dts-v1/;
/plugin/;
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/am33xx.h>
#include <dt-bindings/interrupt-controller/irq.h>
/ {
fragment@0 {
target = <&ocp>;
__overlay__ {
P2_25_pinmux { status = "disabled"; }; /* SPI1 MOSI - gpio1_9 */
P2_27_pinmux { status = "disabled"; }; /* SPI1 MISO - gpio1_8 */
P2_29_pinmux { status = "disabled"; }; /* SPI1 CLK - gpio0_7 */
P2_30_pinmux { status = "disabled"; }; /* SPI1 CS0 - gpio3_17 */
P2_31_pinmux { status = "disabled"; }; /* SPI1 CS1 - gpio0_19 */
P2_08_pinmux { status = "disabled"; }; /* SWC nINT */
P2_32_pinmux { status = "disabled"; }; /* SWC nRESET */
P2_06_pinmux { status = "disabled"; }; /* SWC M0 */
P2_18_pinmux { status = "disabled"; }; /* SWC M1 */
};
};
fragment@1 {
target = <&spi1>;
__overlay__ {
status = "okay";
pinctrl-names = "default";
/* pinmux definitions used by pinctrl for these pins:
https://github.com/beagleboard/linux/blob/4.14/arch/arm/boot/dts/am335x-pocketbeagle.dts#L692
*/
pinctrl-0 = <
/* pull-up on P2_06 and P2_18 only yields 1.27V, so set high via /sys/class/gpio to get 3.3V for SWCAN normal mode */
&P2_06_gpio_pin /* SWC M0 */
&P2_18_gpio_pin /* SWC M1 */
&P2_32_gpio_pu_pin /* SWC nRESET: enable pullup */
&P2_08_default_pin /* SWC nINT: use mode 0x37 */
&P2_25_spi_pin /* SPI1 MOSI: uart0_rtsn.spi1_d1*/
&P2_27_spi_pin /* SPI1 MISO: uart0_ctsn.spi1_d0 */
&P2_29_spi_sclk_pin /* SPI1 CLK: eCAP0_in_PWM0_out.spi1_sclk */
&P2_30_spi_cs_pin /* SPI1 CS0: mcasp0_ahclkr.spi1_cs0 */
&P2_31_spi_cs_pin /* SPI1 CS1: xdma_event_intr0.spi1_cs1 */
>;
channel@0{ status = "disabled"; };
channel@1{ status = "disabled"; };
};
};
fragment@2 {
target = <&am33xx_pinmux>;
__overlay__ {
mcp2515_int: mcp2515_int {
pinctrl-single,pins = < 0x087 0x37 >;
};
};
};
fragment@3 {
target-path = "/";
__overlay__ {
mcp2515_clock: mcp2515_clock {
compatible = "fixed-clock";
#clock-cells = <0>;
clock-frequency = <8000000>;
};
};
};
fragment@4 {
target = <&spi1>;
__overlay__ {
#address-cells = <1>;
#size-cells = <0>;
can0: mcp2515@0 {
status = "okay";
/* use Chip Select 1. P2.31 pin is labelled
"SPI1 CS" on PB silk and is spi1_cs1 */
reg = <1>;
compatible = "microchip,mcp2515";
pinctrl-names = "default";
pinctrl-0 = <&mcp2515_int>;
spi-max-frequency = <10000000>;
interrupt-parent = <&gpio1>;
interrupts = <28 2>;
clocks = <&mcp2515_clock>;
mcp251x,oscillator-frequency = <8000000>;
mcp251x,irq-gpios = <&gpio1 28 0>;
mcp251x,stay-awake = <1>;
mcp251x,enable-clkout = <1>;
};
};
};
__overrides__ {
oscillator = <&mcp2515_clock>,"clock-frequency:0";
spimaxfrequency = <&can0>,"spi-max-frequency:0";
interrupt = <&mcp2515_int>,"pinctrl-single,pins:0",<&can0>,"interrupts:0";
};
};
# file: /boot/uEnv.txt
#Docs: http://elinux.org/Beagleboard:U-boot_partitioning_layout_2.0
uname_r=4.14.79-ti-r82
#uuid=
#dtb=
###U-Boot Overlays###
###Documentation: http://elinux.org/Beagleboard:BeagleBoneBlack_Debian#U-Boot_Overlays
###Master Enable
enable_uboot_overlays=1
###
###Overide capes with eeprom
uboot_overlay_addr0=/lib/firmware/PB-MCP2515-SPI1.dtbo
#uboot_overlay_addr1=/lib/firmware/<file1>.dtbo
#uboot_overlay_addr2=/lib/firmware/<file2>.dtbo
#uboot_overlay_addr3=/lib/firmware/<file3>.dtbo
###
###Additional custom capes
#uboot_overlay_addr4=/lib/firmware/<file4>.dtbo
#uboot_overlay_addr5=/lib/firmware/<file5>.dtbo
#uboot_overlay_addr6=/lib/firmware/<file6>.dtbo
#uboot_overlay_addr7=/lib/firmware/<file7>.dtbo
###
###Custom Cape
#dtb_overlay=/lib/firmware/<file8>.dtbo
###
###Disable auto loading of virtual capes (emmc/video/wireless/adc)
#disable_uboot_overlay_emmc=1
#disable_uboot_overlay_video=1
#disable_uboot_overlay_audio=1
#disable_uboot_overlay_wireless=1
#disable_uboot_overlay_adc=1
###
###PRUSS OPTIONS
###pru_rproc (4.4.x-ti kernel)
#uboot_overlay_pru=/lib/firmware/AM335X-PRU-RPROC-4-4-TI-00A0.dtbo
###pru_rproc (4.14.x-ti kernel)
#uboot_overlay_pru=/lib/firmware/AM335X-PRU-RPROC-4-14-TI-00A0.dtbo
###pru_uio (4.4.x-ti, 4.14.x-ti & mainline/bone kernel)
#uboot_overlay_pru=/lib/firmware/AM335X-PRU-UIO-00A0.dtbo
###
###Cape Universal Enable
enable_uboot_cape_universal=1
###
###Debug: disable uboot autoload of Cape
#disable_uboot_overlay_addr0=1
#disable_uboot_overlay_addr1=1
#disable_uboot_overlay_addr2=1
#disable_uboot_overlay_addr3=1
###
###U-Boot fdt tweaks... (60000 = 384KB)
#uboot_fdt_buffer=0x60000
###U-Boot Overlays###
cmdline=coherent_pool=1M net.ifnames=0 quiet
#In the event of edid real failures, uncomment this next line:
#cmdline=coherent_pool=1M net.ifnames=0 quiet video=HDMI-A-1:1024x768@60e
#Use an overlayfs on top of a read-only root filesystem:
#cmdline=coherent_pool=1M net.ifnames=0 quiet overlayroot=tmpfs
##enable Generic eMMC Flasher:
##make sure, these tools are installed: dosfstools rsync
#cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh
@pdp7
Copy link
Author

pdp7 commented Apr 28, 2019

josh:
sudo ip link set can2 type can bitrate 33000 listen-only on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment