-
-
Save pdp7/e0dcfaca4e478be000987fb0105f2560 to your computer and use it in GitHub Desktop.
/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 = < | |
&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"; | |
}; | |
}; |
WORKING!
updated to use CS1 as "SPI1 CS" on PB silk for P2.31 is actually SPI1 CS1. I had assumed it would be CS0 which was incorrect.
debian@beaglebone:/opt/source/bb.org-overlays$ grep -v ^# /boot/uEnv.txt
uname_r=4.14.78-bone17
enable_uboot_overlays=1
uboot_overlay_addr0=/lib/firmware/PB-MCP2515-SPI1.dtbo
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
enable_uboot_cape_universal=1
cmdline=coherent_pool=1M net.ifnames=0 quiet
[ 29.991584] DEBUG SWCAN: mcp251x_can_probe(): spi->chip_select=0x01
[ 30.185572] DEBUG SWCAN: mcp251x_can_probe(): spi->irq=0x50
[ 30.378469] DEBUG SWCAN: mcp251x_can_probe(): spi->modalias=mcp2515
[ 30.640684] DEBUG SWCAN: mcp251x_can_probe(): spi->cs_gpio=0xfffffffe
[ 30.923997] DEBUG SWCAN: mcp251x_can_probe(): spi->controller->bus_num=0x01
[ 31.138383] DEBUG SWCAN: mcp251x_can_probe(): spi->dev->init_name=(null)
[ 31.406334] DEBUG SWCAN: mcp251x_can_probe(): spi->dev->bus->name=spi
[ 31.442691] c_can_platform 481cc000.can: c_can_platform device registered (regs=fa1cc000, irq=39)
[ 31.526803] c_can_platform 481d0000.can: c_can_platform device registered (regs=fa1d0000, irq=40)
[ 31.607556] DEBUG SWCAN: mcp251x_can_probe(): spi->dev->bus->dev_name=(null)
[ 31.838572] DEBUG SWCAN: mcp251x_can_probe(): freq = clk_get_rate(clk)
[ 32.046412] DEBUG SWCAN: mcp251x_can_probe(): freq=0x7a1200
[ 32.177303] DEBUG SWCAN: mcp251x_can_probe(): freq=8000000
[ 32.274620] DEBUG SWCAN: mcp251x_can_probe(): net=db4b0800
[ 32.402709] DEBUG SWCAN: mcp251x_can_probe(): ret = clk_prepare_enable(clk): 0x00
[ 32.574608] DEBUG SWCAN: mcp251x_can_probe(): call mcp251x_power_enable()
[ 32.772042] DEBUG SWCAN: mcp251x_can_probe(): call mcp251x_hw_probe()
[ 32.883983] DEBUG SWCAN: mcp251x_hw_probe: call mcp251x_hw_reset()
[ 32.957205] DEBUG SWCAN: mcp251x_hw_reset(): spriv->spi_tx_buf[0]=0xc0
[ 33.358471] DEBUG SWCAN: mcp251x_hw_reset(): call mcp251x_spi_trans(spi, 1)
[ 33.498683] DEBUG SWCAN: mcp251x_spi_trans(len=0x01): call spi_message_init()
[ 33.738486] DEBUG SWCAN: mcp251x_spi_trans(): call spi_message_add_tail(&t, &m)
[ 33.910664] DEBUG SWCAN: mcp251x_spi_trans(): call spi_sync(spi, &m)
[ 34.066523] DEBUG SWCAN: mcp251x_spi_trans(): return ret=0x00
[ 34.268065] DEBUG SWCAN: mcp251x_hw_reset(): call mcp251x_read_reg(spi, CANSTAT)
[ 34.482546] DEBUG SWCAN: mcp251x_read_reg(reg=0x0e): call mcp251x_spi_trans()
[ 34.606632] DEBUG SWCAN: mcp251x_spi_trans(len=0x03): call spi_message_init()
[ 34.782426] DEBUG SWCAN: mcp251x_spi_trans(): call spi_message_add_tail(&t, &m)
[ 34.978497] DEBUG SWCAN: mcp251x_spi_trans(): call spi_sync(spi, &m)
[ 35.150572] DEBUG SWCAN: mcp251x_spi_trans(): return ret=0x00
[ 35.266636] DEBUG SWCAN: mcp251x_read_reg(): return val=0x80
[ 35.406481] DEBUG SWCAN: mcp251x_hw_reset(): reg=0x80
[ 35.550567] DEBUG SWCAN: mcp251x_hw_reset(): (reg & CANCTRL_REQOP_MASK)=0x80
[ 35.693469] DEBUG SWCAN: mcp251x_hw_probe: ret=0
[ 35.824501] DEBUG SWCAN: mcp251x_hw_probe: call mcp251x_read_reg(spi, CANCTRL)
[ 35.824524] DEBUG SWCAN: mcp251x_read_reg(reg=0x0f): call mcp251x_spi_trans()
[ 36.174863] DEBUG SWCAN: mcp251x_spi_trans(len=0x03): call spi_message_init()
[ 36.344996] DEBUG SWCAN: mcp251x_spi_trans(): call spi_message_add_tail(&t, &m)
[ 36.502582] DEBUG SWCAN: mcp251x_spi_trans(): call spi_sync(spi, &m)
[ 36.666552] DEBUG SWCAN: mcp251x_spi_trans(): return ret=0x00
[ 36.818374] DEBUG SWCAN: mcp251x_read_reg(): return val=0x87
[ 36.922433] DEBUG SWCAN: mcp251x_hw_probe: ctrl=0x87
[ 37.056622] DEBUG SWCAN: mcp251x_hw_probe: ((ctrl & 0x17)=0x07
[ 37.150520] mcp251x spi1.1: CANCTRL 0x87
[ 37.150536] DEBUG SWCAN: mcp251x_spi_trans(len=0x03): call spi_message_init()
[ 37.367432] DEBUG SWCAN: mcp251x_spi_trans(): call spi_message_add_tail(&t, &m)
[ 37.577028] DEBUG SWCAN: mcp251x_spi_trans(): call spi_sync(spi, &m)
[ 37.681012] DEBUG SWCAN: mcp251x_spi_trans(): return ret=0x00
[ 37.896939] mcp251x spi1.1 can2: MCP2515 successfully initialized.
After rebooting, the mcp251x driver should initialize the MCP2515 device and these commands from the Macchina documentation should work:
sudo ip link set can0 type can bitrate 500000 listen-only on
sudo ifconfig can0 up
dmesg:
[ 890.227485] c_can_platform 481cc000.can can0: setting BTR=1c02 BRPE=0000
ifconfig:
debian@beaglebone:/opt/source/bb.org-overlays$ ifconfig can0
can0: flags=193<UP,RUNNING,NOARP> mtu 16
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 10 (UNSPEC)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 39
The PocketBeagle connected to Macchina adapter is now able to
SUCCESSFULLY initialize the MCP2515 on the Macchina M2. This DT
overlay now causes the mcp251x driver to look for the MCP2515 on
spi1_cs1.
The PocketBeagle silkscreen is confusing with regard to chip selects.
The "SPI0 CS" pin is spi0_cs0, while the "SPI1 CS" pin is spi1_cs1.
This breaks the symmetry that I would have expected: "CS" means cs0.
I am going to follow up with Jason Kridner and Robert Nelson to see
how we can better document this so others don't make the same mistake.
I used these commands from the Macchina documentation:
sudo ip link set can0 type can bitrate 500000 listen-only on
sudo ifconfig can0 up
And the can0 interface seems to be initialized OK:
can0: flags=193<UP,RUNNING,NOARP> mtu 16
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
txqueuelen 10 (UNSPEC)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 39
I would like to verify that CAN is functioning reliably before I start
modifying the driver to toggle P2.6 (SWC_M0) and P2.18 (SWC_M1) to set
the SWC transceiver mode.
Test instructions
microSD/Standalone: (stretch-iot) (All BeagleBone Variants & PocketBeagle)
Kernel: 4.14.79-ti-r89
Get prebuilt image:
&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 */
TEST INSTRUCTIONS
49 cd /opt/source/bb.org-overlays/
50 git pull
53 sudo vi src/arm/PB-MCP2515-SPI1.dts
54 sudo ./install.sh
55 ls -ltar /lib/firmware/PB-MCP2515-SPI1.dtbo
56 sudo vi /boot/uEnv.txt
debian@beaglebone:/opt/source/bb.org-overlays$ cat /boot/uEnv.txt |grep -v ^#
uname_r=4.14.79-ti-r82
enable_uboot_overlays=1
uboot_overlay_addr0=/lib/firmware/PB-MCP2515-SPI1.dtbo
enable_uboot_cape_universal=1
cmdline=coherent_pool=1M net.ifnames=0 quiet
debian@beaglebone:~$ sudo ip link set can2 type can bitrate 500000 listen-only on
debian@beaglebone:~$ sudo ifconfig can2 up
debian@beaglebone:~$ sudo ifconfig can2
can2: flags=193<UP,RUNNING,NOARP> mtu 16
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 10 (UNSPEC)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
debian@beaglebone:~$ dmesg |grep -i can |grep -vi cannot
[ 1.222968] CAN device driver interface
[ 1.224194] c_can_platform 481cc000.can: c_can_platform device registered (regs=fa1cc000, irq=39)
[ 1.225118] c_can_platform 481d0000.can: c_can_platform device registered (regs=fa1d0000, irq=40)
[ 1.339474] can: controller area network core (rev 20170425 abi 9)
[ 36.450040] mcp251x spi2.1 can2: MCP2515 successfully initialized.
Here is the Device Tree overlay: PB-MCP2515-SPI1.dts
https://gist.github.com/pdp7/e0dcfaca4e478be000987fb0105f2560
I was using the BeagleBoard.org Debian SD card image from 2019-01-06 with kernel 4.14.79-ti-r89:
wget https://rcn-ee.com/rootfs/bb.org/testing/2019-01-06/stretch-iot/bone-debian-9.6-iot-armhf-2019-01-06-4gb.img.xz
Test instructions are in this comment on the Gist linked above:
https://gist.github.com/pdp7/e0dcfaca4e478be000987fb0105f2560#gistcomment-2814268
I'll paste them here:
===========================================
cd /opt/source/bb.org-overlays/
git pull
#paste the contents of the Gist above
# or scp the file to the PocketBeagle over USB or WiFi
sudo vi src/arm/PB-MCP2515-SPI1.dts
#this will 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 vi /boot/uEnv.txt
===========================================
The contents should be the following. The "uboot_overlay_addr0" property will cause the MCP2515 overlay to be loaded:
===========================================
uname_r=4.14.79-ti-r82
enable_uboot_overlays=1
uboot_overlay_addr0=/lib/firmware/PB-MCP2515-SPI1.dtbo
enable_uboot_cape_universal=1
cmdline=coherent_pool=1M net.ifnames=0 quiet
===========================================
PB-MCP2515-SPI0.dts
https://gist.github.com/pdp7/16294be504aeb75daca44f49f287f044