Skip to content

Instantly share code, notes, and snippets.

@pdp7
Created October 27, 2020 06:28
Show Gist options
  • Save pdp7/784d0ba8b9648d20ab055747ec945225 to your computer and use it in GitHub Desktop.
Save pdp7/784d0ba8b9648d20ab055747ec945225 to your computer and use it in GitHub Desktop.
2xMCP2517FD-overlay.dts
/*
* Device tree overlay for mcp251x/mcp2517fd on spi0.0
*/
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";
/* disable spi-dev for spi0.0 */
fragment@0{
target = <&spidev0>;
__overlay__ {
status = "disabled";
};
};
fragment@1{
target = <&spidev1>;
__overlay__ {
status = "disabled";
};
};
/* the interrupt pin of the can-controller */
fragment@2 {
target = <&gpio>;
__overlay__ {
can_int_pins: can_int_pins {
brcm,pins = <25 16>;
brcm,function = <0>; /* input */
};
spi1_pins: spi1_pins {
brcm,pins = <19 20 21>;
brcm,function = <3>; /* alt4 */
};
spi1_cs_pins: spi1_cs_pins {
brcm,pins = <26>;
brcm,function = <1>; /* output */
};
};
};
/* the clock/oscillator of the can-controller */
fragment@3 {
target-path = "/clocks";
__overlay__ {
/* external 40M oscillator of mcp2517fd on SPI0.0 */
mcp2517fd_osc: mcp2517fd_osc {
compatible = "fixed-clock";
#clock-cells = <0>;
clock-frequency = <40000000>;
};
};
};
/* the spi config of the can-controller itself binding everything together */
fragment@4 {
target = <&spi0>;
__overlay__ {
/* needed to avoid dtc warning */
#address-cells = <1>;
#size-cells = <0>;
status = "okay";
can0: can@0 {
reg = <0>;
pinctrl-names = "default";
pinctrl-0 = <&can_int_pins>;
compatible = "microchip,mcp2517fd";
spi-max-frequency = <125000000>;
interrupt-parent = <&gpio>;
interrupts = <25 8>; /* IRQ_TYPE_LEVEL_LOW */
clocks = <&mcp2517fd_osc>;
};
};
};
/* the spi config of the can-controller itself binding everything together */
fragment@5 {
target = <&spi1>;
__overlay__ {
/* needed to avoid dtc warning */
#address-cells = <1>;
#size-cells = <0>;
cs-gpios = <&gpio 26 1>;
status = "okay";
can1: can@1 {
reg = <0>;
pinctrl-names = "default";
pinctrl-0 = <&spi1_pins &spi1_cs_pins>;
compatible = "microchip,mcp2517fd";
spi-max-frequency = <125000000>;
interrupt-parent = <&gpio>;
interrupts = <16 8>; /* IRQ_TYPE_LEVEL_LOW */
clocks = <&mcp2517fd_osc>;
};
};
};
};
@mickeyl
Copy link

mickeyl commented Mar 1, 2022

This is the only overlay that can get my Waveshare 2 CAN FD HAT to work with the mainline drivers, thanks a lot!

@alexbewley
Copy link

How did you get it to work?

dtc -O dts -o 2xMCP2517FD-overlay.dtbo 2xMCP2517FD-overlay.dts
2xMCP2517FD-overlay.dts:93.25-102.15: Warning (spi_bus_reg): /fragment@5/overlay/can@1: SPI bus unit address format error, expected "0"

Could you share your /boot/config.txt file Raspberry PI version and OS?
I have the exact same Waveshare 2 CAN FD HAT unit and only one interface starts up and even then, I don't get any data.

@mickeyl
Copy link

mickeyl commented Mar 29, 2022

@alexbewley Ok, here's the details. Right now, I'm running a Raspberry Pi4. /boot/config.txt is:

# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
framebuffer_width=1280
framebuffer_height=800

# uncomment if hdmi display is not detected and composite is being output
hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=on

# Uncomment this to enable infrared communication.
#dtoverlay=gpio-ir,gpio_pin=17
#dtoverlay=gpio-ir-tx,gpio_pin=18
# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=on

# Uncomment this to enable infrared communication.
#dtoverlay=gpio-ir,gpio_pin=17
#dtoverlay=gpio-ir-tx,gpio_pin=18

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
dtparam=audio=off

# Automatically load overlays for detected cameras
camera_auto_detect=1

# Automatically load overlays for detected DSI displays
display_auto_detect=1

# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d
max_framebuffers=2

# Run in 64-bit mode
arm_64bit=1

# Disable compensation for displays with overscan
disable_overscan=1

[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
otg_mode=1

[all]

[pi4]
# Run as fast as firmware / board allows
arm_boost=1

[all]
# CAN HAT
dtoverlay=2xMCP2517FD

Kernel version is Linux pi4 5.15.24-v8+ #1526 SMP PREEMPT Fri Feb 18 14:59:51 GMT 2022 aarch64 GNU/Linux.

Userland is arm64-Raspbian based on Debian Bullseye.

Here's the relevant detection part from dmesg:

[    7.149903] spi_master spi1: will run message pump with realtime priority
[    7.156606] mcp251xfd spi1.0 (unnamed net_device) (uninitialized): Detected MCP2518FD, but firmware specifies a MCP2517FD. Fixing up.
[    7.161757] mcp251xfd spi1.0 can0: MCP2518FD rev0.0 (-RX_INT -MAB_NO_WARN +CRC_REG +CRC_RX +CRC_TX +ECC -HD c:40.00MHz m:125.00MHz r:17.00MHz e:16.66MHz) successfully initialized.
[    7.170694] vc4-drm gpu: bound fef00700.hdmi (ops vc4_hdmi_ops [vc4])
[    7.172958] Registered IR keymap rc-cec
[    7.176064] spi_master spi0: will run message pump with realtime priority
[    7.184129] mcp251xfd spi0.0 (unnamed net_device) (uninitialized): Detected MCP2518FD, but firmware specifies a MCP2517FD. Fixing up.
[    7.193176] rc rc1: vc4 as /devices/platform/soc/fef05700.hdmi/rc/rc1
[    7.212449] input: vc4 as /devices/platform/soc/fef05700.hdmi/rc/rc1/input3
[    7.256007] vc4-drm gpu: bound fef05700.hdmi (ops vc4_hdmi_ops [vc4])
[    7.256441] vc4-drm gpu: bound fe004000.txp (ops vc4_txp_ops [vc4])
[    7.256762] vc4-drm gpu: bound fe206000.pixelvalve (ops vc4_crtc_ops [vc4])
[    7.257070] vc4-drm gpu: bound fe207000.pixelvalve (ops vc4_crtc_ops [vc4])
[    7.257354] vc4-drm gpu: bound fe20a000.pixelvalve (ops vc4_crtc_ops [vc4])
[    7.257585] vc4-drm gpu: bound fe216000.pixelvalve (ops vc4_crtc_ops [vc4])
[    7.257863] vc4-drm gpu: bound fec12000.pixelvalve (ops vc4_crtc_ops [vc4])
[    7.265412] mcp251xfd spi0.0 can1: MCP2518FD rev0.0 (-RX_INT -MAB_NO_WARN +CRC_REG +CRC_RX +CRC_TX +ECC -HD c:40.00MHz m:125.00MHz r:17.00MHz e:16.66MHz) successfully initialized.

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