Pi5 CANbus with Balena

Topics about the Software of Revolution Pi
agregg
Posts: 7
Joined: 25 Apr 2025, 04:15

Pi5 CANbus with Balena

Post by agregg »

Hi, I am trying to get the Pi5 CANbus to work with Balena OS. I have successfully loaded Balena and I am using dt overlays that work with a different MCP2515-based CAN hat. I doubt these are correct for RevPi. I'm unable to see the can devices in ifconfig. Could you tell me the correct overlays that I should be applying? Thank you!

Under Balena configuration, I'm using:
Define DT Overlays:

Code: Select all

"mcp2515-can1,oscillator=16000000,interrupt=25", "mcp2515-can0,oscillator=16000000,interrupt=23", "spi-bcm2835-overlay"
Define DT Parameters for the Default Overlay:

Code: Select all

"i2c_arm=on","spi=on","audio=on"
User avatar
nicolaiB
KUNBUS
Posts: 1131
Joined: 21 Jun 2018, 10:33
Location: Berlin
Contact:

Re: Pi5 CANbus with Balena

Post by nicolaiB »

Hi

there are several things:

- Connect 5 is using the mcp251863 controll, thus you need to use the mcp251xfd overlay
- Connect 5 uses a 20 MHz oscillator
- You must use the correct pins and SPI interface. The controller is connected to SPI1 with pin 11 as chip select (cs1)
- Controller for spi1 must be enabled with the spi1

Everything together results in the following two overlay definitions

Code: Select all

spi1-2cs,cs1_pin=11
mcp251xfd,spi1-1,interrupt=6,oscillator=20000000
If you're interested on the rest of the hardware or the overlay in general, you can find it here:

https://gitlab.com/revolutionpi/linux/- ... verlay.dts
https://gitlab.com/revolutionpi/linux/- ... verlay.dts

Nicolai
Nicolai
agregg
Posts: 7
Joined: 25 Apr 2025, 04:15

Re: Pi5 CANbus with Balena

Post by agregg »

Thanks! I started looking through the overlay files and was almost there. I tried the overlays you recommended:

Code: Select all

"spi1-2cs,cs1_pin=11","mcp251xfd,spi1-1,interrupt=6,oscillator=20000000"
After removing the default param

Code: Select all

spi=on
that was causing a gpio conflict, I was able to get can0 working!
Working on can1 now...
Last edited by agregg on 05 May 2025, 17:55, edited 1 time in total.
User avatar
nicolaiB
KUNBUS
Posts: 1131
Joined: 21 Jun 2018, 10:33
Location: Berlin
Contact:

Re: Pi5 CANbus with Balena

Post by nicolaiB »

CAN1 is attached to spi5 with irq=25, miso=13, mosi=14, clk=15 and cs=12

https://gitlab.com/revolutionpi/linux/- ... y.dts#L137

This would result in

Code: Select all

"spi5-1cs","mcp251xfd,spi5-1,interrupt=25,oscillator=20000000"
Nicolai
Nicolai
agregg
Posts: 7
Joined: 25 Apr 2025, 04:15

Re: Pi5 CANbus with Balena

Post by agregg »

I'm having trouble with that one. I tried adding it with the previous can0 overlay and also just by itself.

I get the following conflict:

root@balena:~# dmesg | grep spi
[ 3.009703] spi spi0.0: chipselect 0 already in use
[ 3.009712] spi_master spi0: spi_device register error /axi/pcie@1000120000/rp1/spi@50000/spidev@0
[ 3.009725] spi_master spi0: Failed to create SPI device for /axi/pcie@1000120000/rp1/spi@50000/spidev@0
[ 3.315641] spi_master spi0: will run message pump with realtime priority
[ 3.354154] mcp251xfd spi0.0 (unnamed net_device) (uninitialized): Failed to read Oscillator Configuration Register (osc=0xffffffff).
[ 3.354162] mcp251xfd spi0.0: error -ENODEV: Failed to detect MCP251xFD.
User avatar
nicolaiB
KUNBUS
Posts: 1131
Joined: 21 Jun 2018, 10:33
Location: Berlin
Contact:

Re: Pi5 CANbus with Balena

Post by nicolaiB »

Please double check the overlay names. In your log file the error is about spi 0 and not 5.

Nicolai
Nicolai
agregg
Posts: 7
Joined: 25 Apr 2025, 04:15

Re: Pi5 CANbus with Balena

Post by agregg »

Hi Nicolai, that's what is strange. I'm setting spi5 exactly how you wrote in your post, but the error is coming back as spi0.
agregg
Posts: 7
Joined: 25 Apr 2025, 04:15

Re: Pi5 CANbus with Balena

Post by agregg »

Bump on this ^ Are you able to replicate with Balena?
agregg
Posts: 7
Joined: 25 Apr 2025, 04:15

Re: Pi5 CANbus with Balena

Post by agregg »

Hi Nicolai, I've been tinkering with this some more and my hypothesis is that the mcp251xfd overlay of the RPi5 image doesn't support use of SPI5. Whenever I try to apply the mcp251xfd overlay with SPI5, it throws those errors about SPI0.
To enable SPI5 support, I think I would need to create a custom overlay, which essentially requires a new balena recipe for the RevPi5. Is that correct? This is new territory for me, but if I'm on the right path, let me know and I'll start down this path. If this is something you might consider doing in-house, please let me know.
User avatar
nicolaiB
KUNBUS
Posts: 1131
Joined: 21 Jun 2018, 10:33
Location: Berlin
Contact:

Re: Pi5 CANbus with Balena

Post by nicolaiB »

I tried the same overlay and it seems to work. Either Balena uses an older version of the overlay or something is missing. Can you please share your complete config?
Nicolai
Post Reply