Skip to content

Instantly share code, notes, and snippets.

@pdp7
Created December 26, 2018 17:42
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/5741ff33c899f877ea22343980124849 to your computer and use it in GitHub Desktop.
Save pdp7/5741ff33c899f877ea22343980124849 to your computer and use it in GitHub Desktop.
PB-MCP2515.dts
/dts-v1/;
/plugin/;
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/am33xx.h>
#include <dt-bindings/interrupt-controller/irq.h>
/*
Macchina SPI0 for SWCAN MCP2515 is PocketBeagle SPI1
Macchina PB adapter J3 is PB P1
Macchina PB adapter J2 is next to J3 / PB P1
Macchina PB adapter J4 is PB P2
Macchina PB adapter J1 is next to J4 / PB P2
https://github.com/macchina/pocketbeagle-adapter-hardware/blob/master/SCH-01010%20R0%20SCHEM_RELEASE.PDF
https://github.com/macchina/m2-hardware/tree/master/M2-B
https://github.com/macchina/m2-hardware/blob/master/M2-B/Interface%20Board%20PCB.pdf
M2 J3 is plugs into PB adapter J2, next to PB P1 (which is PB adapter J3)
M2 J4 is plugs into PB adapter J1, next to PB P2 (which is PB adapter J4)
M2 J4.20: SWC nINT <-> P2.8
M2 J3.6 : SWC_nRESET <-> P2.32
M2 J4.9 : SWC_M0 <-> P2.6
M2 J4.28: SWC_M1 <-> P2.18
M2 J3.30: SWC_CLK <-> NC
M2 J4.25: SWC_SOF <-> NC
M2 J4.29: SWC_nRX0BF <-> NC
M2 J4.30: SWC_nRX1BF <-> NC
M2 J4.27: SPI0_CLK <-> PB adapter J2.27: SPI1_CLK
M2 J4.24: SPI0_MISO <-> PB adapter J2.24: SPI1_MISO
M2 J4.26: SPI0_MOSI <-> PB adapter J2.26: SPI1_MOSI
M2 J3.25: SPI0_nCS3 <-> PB adapter J1.25: SPI1_CS
PB adapter J4.25: SPI1_MOSI <-> PB 2.25: SPI1_MOSI
PB adapter J4.27: SPI1_MISO <-> PB 2.27: SPI1_MISO
PB adapter J4.29: SPI1_CLK <-> PB 2.29: SPI1_CLK
PB adapter J4.31: SPI1_CS <-> PB 2.31: SPI1_CS
1006 Signals 1006 headers2 1010/PB header
SWC nRESET J3P6 P2-32
SPI0_nCS3 J3P25 P2-31
SPI0 MISO J4P24 P2-27
SPI0 MOSI J4P26 P2-25
SPI0 CLK J4P27 P2-29
SWC nINT J4P20 P2-8
SWC nRX0BF J4P29 NC
SWC nRX1BF J4P30 NC
SWC SOF J4P25 NC
SWC CLK J3P30 NC
SWC M0 J4P9 P2-6
SWC M1 J4P28 P2-18
*/
/ {
fragment@0 {
target = <&ocp>;
__overlay__ {
/*
M2 J4.20: SWC nINT <-> P2.8 <&gpio1 28 0>, needs GPIO input
M2 J3.6 : SWC_nRESET <-> P2.32 GPIO 112 / PRU0.2, <&gpio3 16 0>, needs GPIO OUTPUT
M2 J4.9 : SWC_M0 <-> P2.6
M2 J4.28: SWC_M1 <-> P2.18
*/
P2_08_pinmux { status = "disabled"; }; /* SWC nINT */
P2_32_pinmux { status = "disabled"; }; /* SWC nRESET */
P2_25_pinmux { status = "disabled"; }; /* MOSI - gpio1_9 */
P2_27_pinmux { status = "disabled"; }; /* MISO - gpio1_8 */
P2_29_pinmux { status = "disabled"; }; /* CLK - gpio0_7 */
P2_31_pinmux { status = "disabled"; }; /* CS - gpio0_19 */
};
};
fragment@1 {
target = <&spi1>;
__overlay__ {
status = "okay";
pinctrl-names = "default";
/*
M2 J4.20: SWC nINT <-> P2.8 <&gpio1 28 0>, needs GPIO input
M2 J3.6 : SWC_nRESET <-> P2.32 GPIO 112 / PRU0.2, <&gpio3 16 0>, needs GPIO OUTPUT
M2 J4.9 : SWC_M0 <-> P2.6 GPIO 57, needs GPIO OUTPUT
M2 J4.28: SWC_M1 <-> P2.18 GPIO 47, needs GPIO OUTPUT
*/
pinctrl-0 = <
/* connected to MCP2515 pin 19 _RESET
hopefully pullup will enable the chip */
&P2_32_gpio_pu_pin
/* SWC nINT */
/* &P2_08_gpio_input_pin is not mode 0x37, so wrong? */
&P2_08_default_pin /* this should be mode 0x37 */
/* SPI1 */
&P2_31_spi_cs_pin
&P2_29_spi_sclk_pin
&P2_27_spi_pin
&P2_25_spi_pin
>;
channel@0{ status = "disabled"; };
channel@1{ status = "disabled"; };
};
};
fragment@2 {
target = <&am33xx_pinmux>;
__overlay__ {
/*
this was originally for BeagleBone Black and used P8.06
from http://exploringbeaglebone.com/wp-content/uploads/resources/BBBP8Header.pdf
P8_06 3 0x80c/00c 35 GPIO1_3 gpio1[3]
pinctrl-single,pins = < 0x00c 0x37 >;
#0x37 : PIN_OUTPUT_PULLUP | INPUT_EN | MUX_MODE7
for PocketBeagle, Macchina puts nINT on P2.08 (ZCZ ball U18) gpio1_28
P2_08_default_pin: pinmux_P2_08_default_pin { pinctrl-single,pins = <
AM33XX_IOPAD(0x0878, PIN_OUTPUT_PULLUP | INPUT_EN | MUX_MODE7) >; }; gpmc_be1n.gpio1_28
where 0x0878 = PB_P2_08
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/dt-bindings/pinctrl/omap.h#n57
https://github.com/beagleboard/bb.org-overlays/blob/master/tools/pinmux-generator/PocketBeagle.dts#L465-L467
https://github.com/beagleboard/bb.org-overlays/blob/master/tools/pinmux-generator/lib/pinmux.sh#L631
so let's try giving pincntrl-single 0x087 which should be the offset from the 0x0800 base
*/
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";
reg = <0>;
compatible = "microchip,mcp2515";
pinctrl-names = "default";
pinctrl-0 = <&mcp2515_int>;
spi-max-frequency = <10000000>;
interrupt-parent = <&gpio1>;
interrupts = <3 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";
};
};
@pdp7
Copy link
Author

pdp7 commented Dec 26, 2018

@pdp7
Copy link
Author

pdp7 commented Dec 26, 2018

interrupt-parent = <&gpio1>;
this makes since as it P2_08 is <&gpio1 28 0>

interrupts = <3 2>;
I don't yet understand what uses this

mcp251x,irq-gpios = <&gpio1 28 0>;
I'm not sure what there is this property and interrupt-parent

@pdp7
Copy link
Author

pdp7 commented Dec 26, 2018

Robert Nelson is wonderful!

interrupts = <28 IRQMODE>;

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/dt-bindings/interrupt-controller/irq.h#n15

#define IRQ_TYPE_EDGE_FALLING 2

@pdp7
Copy link
Author

pdp7 commented Dec 27, 2018

dmesg after boot:

[   42.697191] DEBUG SWCAN: mcp251x_can_probe()
[   42.933800] DEBUG SWCAN: mcp251x_can_probe()
[   42.998722] DEBUG SWCAN: mcp251x_can_probe(): spi=db5e8800
[   43.190862] DEBUG SWCAN: mcp251x_can_probe(): spi->chip_select=0x00
[   43.521368] DEBUG SWCAN: mcp251x_can_probe(): spi->irq=0x6c
[   43.706705] DEBUG SWCAN: mcp251x_can_probe(): spi->modalias=mcp2515
[   43.884667] DEBUG SWCAN: mcp251x_can_probe(): spi->cs_gpio=0xfffffffe
[   44.169672] c_can_platform 481cc000.can: c_can_platform device registered (regs=fa1cc000, irq=39)
[   44.182773] DEBUG SWCAN: mcp251x_can_probe(): spi->controller=db5e8400
[   44.231113] c_can_platform 481d0000.can: c_can_platform device registered (regs=fa1d0000, irq=40)
[   44.433849] DEBUG SWCAN: mcp251x_can_probe(): spi->controller->bus_num=0x01
[   44.658748] DEBUG SWCAN: mcp251x_can_probe(): spi->dev=db5e8978
[   44.810798] DEBUG SWCAN: mcp251x_can_probe(): spi->dev->of_node=dcb4726c
[   44.962720] DEBUG SWCAN: mcp251x_can_probe(): spi->dev->parent=db5e8400
[   45.114765] DEBUG SWCAN: mcp251x_can_probe(): spi->dev->init_name=(null)
[   45.290766] DEBUG SWCAN: mcp251x_can_probe(): spi->dev->bus->name=spi
[   45.442945] DEBUG SWCAN: mcp251x_can_probe(): spi->dev->bus->dev_name=(null)
[   45.648036] DEBUG SWCAN: mcp251x_can_probe(): spi->dev->bus->dev_root=(null)
[   45.826855] DEBUG SWCAN: mcp251x_can_probe(): clk=dabb9ac0
[   45.939032] DEBUG SWCAN: mcp251x_can_probe(): pdata=  (null)
[   46.072588] DEBUG SWCAN: mcp251x_can_probe(): freq = clk_get_rate(clk)
[   46.255131] DEBUG SWCAN: mcp251x_can_probe(): freq=0x7a1200
[   46.342735] DEBUG SWCAN: mcp251x_can_probe(): freq=8000000
[   46.444733] DEBUG SWCAN: mcp251x_can_probe(): net=daadf000
[   46.614813] DEBUG SWCAN: mcp251x_can_probe(): ret = clk_prepare_enable(clk): 0x00
[   46.746928] DEBUG SWCAN: mcp251x_can_probe(): call mcp251x_hw_probe()
[   46.965520] DEBUG SWCAN: mcp251x_hw_probe: spi=db5e8800
[   47.098776] DEBUG SWCAN: mcp251x_hw_reset(): spi=db5e8800
[   47.206867] DEBUG SWCAN: mcp251x_hw_reset(): priv=daadf4a0
[   47.465837] DEBUG SWCAN: mcp251x_hw_reset(): spriv->spi_tx_buf[0]=0xc0
[   47.650789] DEBUG SWCAN: mcp251x_hw_reset(): call mcp251x_spi_trans(spi, 1)
[   47.818738] DEBUG SWCAN: mcp251x_spi_trans: spi=db5e8800
[   47.934302] DEBUG SWCAN: mcp251x_spi_trans: len=0x01
[   48.070794] DEBUG SWCAN: mcp251x_spi_trans: spi_message_init(&m)
[   48.242843] DEBUG SWCAN: mcp251x_spi_trans: m=da843a18
[   48.369840] DEBUG SWCAN: mcp251x_spi_trans: mcp251x_enable_dma=0x00
[   48.503141] DEBUG SWCAN: mcp251x_spi_trans: spi_message_add_tail(&t, &m)
[   48.698886] DEBUG SWCAN: mcp251x_spi_trans: ret=0x00
[   48.865075] DEBUG SWCAN: mcp251x_hw_reset(): CANSTAT=0x0e
[   48.971222] DEBUG SWCAN: mcp251x_hw_reset(): call mcp251x_read_reg()
[   49.118797] DEBUG SWCAN: mcp251x_read_reg: spi=db5e8800
[   49.278740] DEBUG SWCAN: mcp251x_read_reg: reg=0x0e
[   49.402365] DEBUG SWCAN: mcp251x_spi_trans: spi=db5e8800
[   49.530952] DEBUG SWCAN: mcp251x_spi_trans: len=0x03
[   49.602896] DEBUG SWCAN: mcp251x_spi_trans: spi_message_init(&m)
[   49.782731] DEBUG SWCAN: mcp251x_spi_trans: m=da8439f8
[   49.851027] DEBUG SWCAN: mcp251x_spi_trans: mcp251x_enable_dma=0x00
[   50.042370] DEBUG SWCAN: mcp251x_spi_trans: spi_message_add_tail(&t, &m)
[   50.230866] DEBUG SWCAN: mcp251x_spi_trans: ret=0x00
[   50.290781] DEBUG SWCAN: mcp251x_read_reg: val=0x80
[   50.454753] DEBUG SWCAN: mcp251x_hw_reset(): reg=0x80
[   50.562777] DEBUG SWCAN: mcp251x_hw_reset(): CANCTRL_REQOP_MASK=0xe0
[   50.670709] DEBUG SWCAN: mcp251x_hw_reset(): CANCTRL_REQOP_CONF=0x80
[   50.838874] DEBUG SWCAN: mcp251x_hw_reset(): (reg & CANCTRL_REQOP_MASK)=0x80
[   51.018781] DEBUG SWCAN: mcp251x_hw_probe: ret=0
[   51.103053] DEBUG SWCAN: mcp251x_hw_probe: CANCTRL=0x0f
[   51.202915] DEBUG SWCAN: mcp251x_read_reg: spi=db5e8800
[   51.381479] DEBUG SWCAN: mcp251x_read_reg: reg=0x0f
[   51.486849] DEBUG SWCAN: mcp251x_spi_trans: spi=db5e8800
[   51.622094] DEBUG SWCAN: mcp251x_spi_trans: len=0x03
[   51.751648] DEBUG SWCAN: mcp251x_spi_trans: spi_message_init(&m)
[   51.858799] DEBUG SWCAN: mcp251x_spi_trans: m=da843a20
[   51.995170] DEBUG SWCAN: mcp251x_spi_trans: mcp251x_enable_dma=0x00
[   52.150734] DEBUG SWCAN: mcp251x_spi_trans: spi_message_add_tail(&t, &m)
[   52.330246] DEBUG SWCAN: mcp251x_spi_trans: ret=0x00
[   52.361567] DEBUG SWCAN: mcp251x_read_reg: val=0xca
[   52.550809] DEBUG SWCAN: mcp251x_hw_probe: ctrl=0xca
[   52.638845] DEBUG SWCAN: mcp251x_hw_probe: ((ctrl & 0x17)=0x02
[   52.789912] mcp251x spi1.0: CANCTRL 0xca
[   52.789924] mcp251x spi1.0: Cannot initialize MCP2515. Wrong wiring?
[   52.966796] mcp251x spi1.0: Probe failed, err=19

@pdp7
Copy link
Author

pdp7 commented Dec 27, 2018

PocketBeagle MCP2515 SPI1 device tree overlay for Macchina adapter

https://gist.github.com/pdp7/283e39a63645e47c3ed86b8207bac79d

BeagleBone Black with MCP2515 breakout board

https://gist.github.com/pdp7/20dddbeffe83082e3c94ab0903563783

@pdp7
Copy link
Author

pdp7 commented Dec 27, 2018

Connected to Macchina M2 and PB adapter:

[   44.749665] DEBUG SWCAN: mcp251x_can_probe(): spi->chip_select=0x00
[   44.850643] DEBUG SWCAN: mcp251x_can_probe(): spi->irq=0x6c
[   44.879039] c_can_platform 481cc000.can: c_can_platform device registered (regs=fa1cc000, irq=39)
[   44.906918] c_can_platform 481d0000.can: c_can_platform device registered (regs=fa1d0000, irq=40)
[   44.907600] DEBUG SWCAN: mcp251x_can_probe(): spi->modalias=mcp2515
[   45.011990] DEBUG SWCAN: mcp251x_can_probe(): spi->cs_gpio=0xfffffffe
[   45.082699] DEBUG SWCAN: mcp251x_can_probe(): spi->controller->bus_num=0x01
[   45.142728] DEBUG SWCAN: mcp251x_can_probe(): spi->dev->init_name=(null)
[   45.204039] DEBUG SWCAN: mcp251x_can_probe(): spi->dev->bus->name=spi
[   45.294769] DEBUG SWCAN: mcp251x_can_probe(): spi->dev->bus->dev_name=(null)
[   45.373666] DEBUG SWCAN: mcp251x_can_probe(): freq = clk_get_rate(clk)
[   45.461550] DEBUG SWCAN: mcp251x_can_probe(): freq=0x7a1200
[   45.542668] DEBUG SWCAN: mcp251x_can_probe(): freq=8000000
[   45.614759] DEBUG SWCAN: mcp251x_can_probe(): net=db4f9000
[   45.666663] DEBUG SWCAN: mcp251x_can_probe(): ret = clk_prepare_enable(clk): 0x00
[   45.774734] DEBUG SWCAN: mcp251x_can_probe(): call mcp251x_power_enable()
[   45.809778] DEBUG SWCAN: mcp251x_can_probe(): call mcp251x_hw_probe()
[   45.906674] DEBUG SWCAN: mcp251x_hw_probe: call mcp251x_hw_reset()
[   45.944656] DEBUG SWCAN: mcp251x_hw_reset(): spriv->spi_tx_buf[0]=0xc0
[   46.097248] DEBUG SWCAN: mcp251x_hw_reset(): call mcp251x_spi_trans(spi, 1)
[   46.166609] DEBUG SWCAN: mcp251x_spi_trans(len=0x01): call spi_message_init()
[   46.214617] DEBUG SWCAN: mcp251x_spi_trans(): call spi_message_add_tail(&t, &m)
[   46.254627] DEBUG SWCAN: mcp251x_spi_trans(): call spi_sync(spi, &m)
[   46.317676] DEBUG SWCAN: mcp251x_spi_trans(): return ret=0x00
[   46.409787] DEBUG SWCAN: mcp251x_hw_reset(): call mcp251x_read_reg(spi, CANSTAT)
[   46.484823] DEBUG SWCAN: mcp251x_read_reg(reg=0x0e): call mcp251x_spi_trans()
[   46.570639] DEBUG SWCAN: mcp251x_spi_trans(len=0x03): call spi_message_init()
[   46.658614] DEBUG SWCAN: mcp251x_spi_trans(): call spi_message_add_tail(&t, &m)
[   46.749926] DEBUG SWCAN: mcp251x_spi_trans(): call spi_sync(spi, &m)
[   46.814841] DEBUG SWCAN: mcp251x_spi_trans(): return ret=0x00
[   46.898313] DEBUG SWCAN: mcp251x_read_reg(): return val=0x80
[   46.964225] DEBUG SWCAN: mcp251x_hw_reset(): reg=0x80
[   46.998689] DEBUG SWCAN: mcp251x_hw_reset(): (reg & CANCTRL_REQOP_MASK)=0x80
[   47.108506] DEBUG SWCAN: mcp251x_hw_probe: ret=0
[   47.150212] DEBUG SWCAN: mcp251x_hw_probe: call mcp251x_read_reg(spi, CANCTRL)
[   47.150236] DEBUG SWCAN: mcp251x_read_reg(reg=0x0f): call mcp251x_spi_trans()
[   47.326704] DEBUG SWCAN: mcp251x_spi_trans(len=0x03): call spi_message_init()
[   47.422701] DEBUG SWCAN: mcp251x_spi_trans(): call spi_message_add_tail(&t, &m)
[   47.486598] DEBUG SWCAN: mcp251x_spi_trans(): call spi_sync(spi, &m)
[   47.574722] DEBUG SWCAN: mcp251x_spi_trans(): return ret=0x00
[   47.630786] DEBUG SWCAN: mcp251x_read_reg(): return val=0x48
[   47.699650] DEBUG SWCAN: mcp251x_hw_probe: ctrl=0x48
[   47.762658] DEBUG SWCAN: mcp251x_hw_probe: ((ctrl & 0x17)=0x00
[   47.830233] mcp251x spi1.0: CANCTRL 0x48
[   47.830245] mcp251x spi1.0: Cannot initialize MCP2515. Wrong wiring?
[   47.911533] mcp251x spi1.0: Probe failed, err=19

@pdp7
Copy link
Author

pdp7 commented Dec 28, 2018

Changed the DT overlay to use SPI0 and wired MCP2515 breakout board to SPI0 on PocketBeagle. The mcp251x driver was able to initialize the device OK!

The mcp251x driver also initialized the MCP2515 device OK when connect to SPI0 on BeagleBone Black.

So why does SPI1 not work?

For SPI0 on PocketBeagle, I used:

PB-MCP2515.dts

debian@beaglebone:/opt/source/bb.org-overlays$ cat src/arm/PB-MCP2515.dts
/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/am33xx.h>
#include <dt-bindings/interrupt-controller/irq.h>

/*

Macchina SPI0 for SWCAN MCP2515 is PocketBeagle SPI1

Macchina PB adapter J3 is PB P1
Macchina PB adapter J2 is next to J3 / PB P1

Macchina PB adapter J4 is PB P2
Macchina PB adapter J1 is next to J4 / PB P2

https://github.com/macchina/pocketbeagle-adapter-hardware/blob/master/SCH-01010%20R0%20SCHEM_RELEASE.PDF
https://github.com/macchina/m2-hardware/tree/master/M2-B
https://github.com/macchina/m2-hardware/blob/master/M2-B/Interface%20Board%20PCB.pdf

M2 J3 is plugs into PB adapter J2, next to PB P1 (which is PB adapter J3)
M2 J4 is plugs into PB adapter J1, next to PB P2 (which is PB adapter J4)

M2 J4.20: SWC nINT <-> P2.8
M2 J3.6 : SWC_nRESET  <-> P2.32
M2 J4.9 : SWC_M0  <-> P2.6
M2 J4.28: SWC_M1  <-> P2.18
M2 J3.30: SWC_CLK  <-> NC
M2 J4.25: SWC_SOF  <-> NC
M2 J4.29: SWC_nRX0BF  <-> NC
M2 J4.30: SWC_nRX1BF  <-> NC

M2 J4.27: SPI0_CLK  <-> PB adapter J2.27: SPI1_CLK
M2 J4.24: SPI0_MISO <-> PB adapter J2.24: SPI1_MISO
M2 J4.26: SPI0_MOSI <-> PB adapter J2.26: SPI1_MOSI
M2 J3.25: SPI0_nCS3 <-> PB adapter J1.25: SPI1_CS

PB adapter J4.25: SPI1_MOSI <-> PB 2.25: SPI1_MOSI
PB adapter J4.27: SPI1_MISO <-> PB 2.27: SPI1_MISO
PB adapter J4.29: SPI1_CLK  <-> PB 2.29: SPI1_CLK
PB adapter J4.31: SPI1_CS   <-> PB 2.31: SPI1_CS

1006 Signals    1006 headers2    1010/PB header
SWC nRESET      J3P6             P2-32
SPI0_nCS3       J3P25            P2-31
SPI0 MISO       J4P24            P2-27
SPI0 MOSI       J4P26            P2-25
SPI0 CLK        J4P27            P2-29
SWC nINT        J4P20            P2-8
SWC nRX0BF      J4P29            NC
SWC nRX1BF      J4P30            NC
SWC SOF         J4P25            NC
SWC CLK         J3P30            NC
SWC M0          J4P9             P2-6
SWC M1          J4P28            P2-18

*/


/ {
        fragment@0 {
                target = <&ocp>;
                __overlay__ {
/* 
M2 J4.20: SWC nINT <-> P2.8 <&gpio1 28 0>, needs GPIO input
M2 J3.6 : SWC_nRESET  <-> P2.32 GPIO 112 / PRU0.2, <&gpio3 16 0>, needs GPIO OUTPUT
M2 J4.9 : SWC_M0  <-> P2.6
M2 J4.28: SWC_M1  <-> P2.18
*/
			P1_12_pinmux { status = "disabled"; };	/* MOSI - gpio0_4 */
			P1_10_pinmux { status = "disabled"; };	/* MISO - gpio0_3 */
			P1_08_pinmux { status = "disabled"; };	/* CLK - gpio0_2 */
			P1_06_pinmux { status = "disabled"; };	/* CS - gpio0_5 */

                        P2_08_pinmux { status = "disabled"; };  /* SWC nINT */
                        P2_32_pinmux { status = "disabled"; };  /* SWC nRESET */
                };
	};


			
        fragment@1 {
                target = <&spi0>;
                __overlay__ {
                        status = "okay";
                        pinctrl-names = "default";
/* 
M2 J4.20: SWC nINT <-> P2.8 <&gpio1 28 0>, needs GPIO input
M2 J3.6 : SWC_nRESET  <-> P2.32 GPIO 112 / PRU0.2, <&gpio3 16 0>, needs GPIO OUTPUT
M2 J4.9 : SWC_M0  <-> P2.6 GPIO 57, needs GPIO OUTPUT
M2 J4.28: SWC_M1  <-> P2.18 GPIO 47, needs GPIO OUTPUT
*/
                        pinctrl-0 = <
                                /* connected to MCP2515 pin 19 _RESET 
                                   hopefully pullup will enable the chip */
                                &P2_32_gpio_pu_pin
                                /* SWC nINT */
                                /* &P2_08_gpio_input_pin is not mode 0x37, so wrong? */
                                &P2_08_default_pin /* this should be mode 0x37 */
                                /* SPI0 */
				&P1_06_spi_cs_pin
				&P1_08_spi_sclk_pin
				&P1_10_spi_pin
				&P1_12_spi_pin
                        >;

                        channel@0{ status = "disabled"; };
                        channel@1{ status = "disabled"; };
                };
        };


        fragment@2 {
		target = <&am33xx_pinmux>;
		__overlay__ {
/*
this was originally for BeagleBone Black and used P8.06

from http://exploringbeaglebone.com/wp-content/uploads/resources/BBBP8Header.pdf
P8_06 3 0x80c/00c 35 GPIO1_3 gpio1[3]

pinctrl-single,pins = < 0x00c 0x37 >;

#0x37 : PIN_OUTPUT_PULLUP | INPUT_EN | MUX_MODE7



for PocketBeagle, Macchina puts nINT on P2.08 (ZCZ ball U18) gpio1_28 
P2_08_default_pin: pinmux_P2_08_default_pin { pinctrl-single,pins = <
AM33XX_IOPAD(0x0878, PIN_OUTPUT_PULLUP | INPUT_EN | MUX_MODE7) >; }; gpmc_be1n.gpio1_28 

where 0x0878 = PB_P2_08
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/dt-bindings/pinctrl/omap.h#n57
https://github.com/beagleboard/bb.org-overlays/blob/master/tools/pinmux-generator/PocketBeagle.dts#L465-L467
https://github.com/beagleboard/bb.org-overlays/blob/master/tools/pinmux-generator/lib/pinmux.sh#L631
so let's try giving pincntrl-single 0x087 which should be the offset from the 0x0800 base
*/
			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 = <&spi0>;
		__overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			can0: mcp2515@0 {
				status = "okay";
				reg = <0>;
				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";
	};

};

dmesg

[   36.889216] IPv6: ADDRCONF(NETDEV_UP): usb0: link is not ready
[   37.183016] IPv6: ADDRCONF(NETDEV_CHANGE): usb0: link becomes ready
[   42.103806] DEBUG SWCAN: mcp251x_can_probe(): spi->chip_select=0x00
[   42.354826] DEBUG SWCAN: mcp251x_can_probe(): spi->irq=0x50
[   42.530893] DEBUG SWCAN: mcp251x_can_probe(): spi->modalias=mcp2515
[   42.781591] DEBUG SWCAN: mcp251x_can_probe(): spi->cs_gpio=0xfffffffe
[   42.964563] DEBUG SWCAN: mcp251x_can_probe(): spi->controller->bus_num=0x00
[   43.270939] DEBUG SWCAN: mcp251x_can_probe(): spi->dev->init_name=(null)
[   43.526138] DEBUG SWCAN: mcp251x_can_probe(): spi->dev->bus->name=spi
[   43.703474] c_can_platform 481cc000.can: c_can_platform device registered (regs=fa1cc000, irq=39)
[   43.726982] DEBUG SWCAN: mcp251x_can_probe(): spi->dev->bus->dev_name=(null)
[   43.779223] c_can_platform 481d0000.can: c_can_platform device registered (regs=fa1d0000, irq=40)
[   43.992895] DEBUG SWCAN: mcp251x_can_probe(): freq = clk_get_rate(clk)
[   44.250869] DEBUG SWCAN: mcp251x_can_probe(): freq=0x7a1200
[   44.407104] DEBUG SWCAN: mcp251x_can_probe(): freq=8000000
[   44.674954] DEBUG SWCAN: mcp251x_can_probe(): net=daa9b000
[   44.792908] DEBUG SWCAN: mcp251x_can_probe(): ret = clk_prepare_enable(clk): 0x00
[   44.963056] DEBUG SWCAN: mcp251x_can_probe(): call mcp251x_power_enable()
[   45.075205] DEBUG SWCAN: mcp251x_can_probe(): call mcp251x_hw_probe()
[   45.274882] DEBUG SWCAN: mcp251x_hw_probe: call mcp251x_hw_reset()
[   45.373637] DEBUG SWCAN: mcp251x_hw_reset(): spriv->spi_tx_buf[0]=0xc0
[   45.634937] DEBUG SWCAN: mcp251x_hw_reset(): call mcp251x_spi_trans(spi, 1)
[   45.778902] DEBUG SWCAN: mcp251x_spi_trans(len=0x01): call spi_message_init()
[   46.002989] DEBUG SWCAN: mcp251x_spi_trans(): call spi_message_add_tail(&t, &m)
[   46.211014] DEBUG SWCAN: mcp251x_spi_trans(): call spi_sync(spi, &m)
[   46.372847] DEBUG SWCAN: mcp251x_spi_trans(): return ret=0x00
[   46.586661] DEBUG SWCAN: mcp251x_hw_reset(): call mcp251x_read_reg(spi, CANSTAT)
[   46.739117] DEBUG SWCAN: mcp251x_read_reg(reg=0x0e): call mcp251x_spi_trans()
[   46.921698] DEBUG SWCAN: mcp251x_spi_trans(len=0x03): call spi_message_init()
[   47.126881] DEBUG SWCAN: mcp251x_spi_trans(): call spi_message_add_tail(&t, &m)
[   47.243076] DEBUG SWCAN: mcp251x_spi_trans(): call spi_sync(spi, &m)
[   47.408906] DEBUG SWCAN: mcp251x_spi_trans(): return ret=0x00
[   47.528872] DEBUG SWCAN: mcp251x_read_reg(): return val=0x80
[   47.706895] DEBUG SWCAN: mcp251x_hw_reset(): reg=0x80
[   47.851419] DEBUG SWCAN: mcp251x_hw_reset(): (reg & CANCTRL_REQOP_MASK)=0x80
[   48.007196] DEBUG SWCAN: mcp251x_hw_probe: ret=0
[   48.114939] DEBUG SWCAN: mcp251x_hw_probe: call mcp251x_read_reg(spi, CANCTRL)
[   48.114963] DEBUG SWCAN: mcp251x_read_reg(reg=0x0f): call mcp251x_spi_trans()
[   48.446946] DEBUG SWCAN: mcp251x_spi_trans(len=0x03): call spi_message_init()
[   48.590916] DEBUG SWCAN: mcp251x_spi_trans(): call spi_message_add_tail(&t, &m)
[   48.810969] DEBUG SWCAN: mcp251x_spi_trans(): call spi_sync(spi, &m)
[   48.938944] DEBUG SWCAN: mcp251x_spi_trans(): return ret=0x00
[   49.039159] DEBUG SWCAN: mcp251x_read_reg(): return val=0x87
[   49.242932] DEBUG SWCAN: mcp251x_hw_probe: ctrl=0x87
[   49.307830] DEBUG SWCAN: mcp251x_hw_probe: ((ctrl & 0x17)=0x07
[   49.462455] mcp251x spi0.0: CANCTRL 0x87
[   49.462467] DEBUG SWCAN: mcp251x_spi_trans(len=0x03): call spi_message_init()
[   49.618942] DEBUG SWCAN: mcp251x_spi_trans(): call spi_message_add_tail(&t, &m)
[   49.814674] DEBUG SWCAN: mcp251x_spi_trans(): call spi_sync(spi, &m)
[   49.962984] DEBUG SWCAN: mcp251x_spi_trans(): return ret=0x00
[   50.114968] mcp251x spi0.0 can2: MCP2515 successfully initialized.
debian@beaglebone:~$ 

NOTE:

the other change made at the same time I switched SPI1 to SPI0, I changed interrupts = <3 2>; to interrupts = <28 2>; based on advise from Robert Nelson

interrupts = <28 IRQMODE>;
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/dt-bindings/interrupt-controller/irq.h#n15
#define IRQ_TYPE_EDGE_FALLING 2

@pdp7
Copy link
Author

pdp7 commented Dec 28, 2018

pocketbeagle with mcp2515 on SPI0:

create CAN interface

debian@beaglebone:~$ sudo ip link set can0 type can bitrate 500000 listen-only on
debian@beaglebone:~$ dmseg
-bash: dmseg: command not found
debian@beaglebone:~$ dmesg
debian@beaglebone:~$ sudo ifconfig can0 up
debian@beaglebone:~$ dmesg
[  577.908721] c_can_platform 481cc000.can can0: setting BTR=1c02 BRPE=0000
debian@beaglebone:~$ 

@pdp7
Copy link
Author

pdp7 commented Jan 8, 2019

does that seem correct?

  • P2_31_spi_cs_pin
  • P2_29_spi_sclk_pin
  • P2_27_spi_pin
  • P2_25_spi_pin

jkridner [11:01 PM]
dang PRU path changes SOOO much.

rcn-ee [11:01 PM]
each one is different... it's annoying...
@fustini i think P2_29_spi_sclk_pin is wrong, based of a post on beagleboard group..

fustini [11:02 PM]
@jkridner is the pins you use for SPI1: P2.29, P2.31, P2.27, P2.25 ?
oh (edited)
@rcn-ee interesting, which post?

jkridner [11:03 PM]
yeah

rcn-ee [11:04 PM]
@fustini https://groups.google.com/d/msg/beagleboard/SFsmDpdTz-Q/ZIZo9uvIEgAJ

jkridner [11:06 PM]
the extra on techlab is a buzzer on the PRU.
also, the potentiometer is gone and a light sensor is there instead.

fustini [11:06 PM]
@rcn-ee so this is correct?
P2_29_spi_cs_pin: pinmux_P2_29_spi_cs_pin { pinctrl-single,pins = < AM33XX_IOPAD(0x0964, PIN_OUTPUT_PULLUP | INPUT_EN | MUX_MODE2) >; }; /* eCAP0_in_PWM0_out.spi1_cs1 */
https://github.com/jadonk/linux-1/blob/add-mcp23s08/arch/arm/boot/dts/am335x-pocketbeagle-common.dtsi#L829
GitHub
jadonk/linux-1
Contribute to jadonk/linux-1 development by creating an account on GitHub.

rcn-ee [11:09 PM]
@fustini i think we need to change PIN_OUTPUT_PULLUP to PIN_INPUT_PULLUP to be 100% correct, i think we are sometimes saved by "INPUT_EN"...
@fustini ti's pinmux say:

    pinctrl-single,pins = <
        AM33XX_IOPAD(0x108, PIN_INPUT_PULLUP | MUX_MODE2) /* (H16) gmii1_col.spi1_sclk */
        AM33XX_IOPAD(0x10c, PIN_INPUT_PULLUP | MUX_MODE2) /* (H17) gmii1_crs.spi1_d0 */
        AM33XX_IOPAD(0x110, PIN_INPUT_PULLUP | MUX_MODE2) /* (J15) gmii1_rxer.spi1_d1 */
        AM33XX_IOPAD(0x144, PIN_INPUT_PULLUP | MUX_MODE2) /* (H18) rmii1_refclk.spi1_cs0 */
    >;
};```

fustini [11:15 PM]
thanks

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