0

I am trying to get a MCP2515 (CAN-bus IC that works on SPI) to work on a Raspberry Pi Compute Module 4 (8GB eMMC, No Wifi, 4GB RAM).

I have been able to get the module working on a regular Raspberry Pi 4B. Although not yet on the Compute module with my custom OS.

I have been building my own Pi image with Yocto (and the Poky distro) with a 64-bits version of the OS. The meta-raspberrypi layer has been used to get the correct BSP (Board support package) for the hardware I'm using.

The kernel I'm currently using is: Linux raspberrypi4-64 5.10.81-v8 #1 SMP PREEMPT Mon Nov 22 14:00:03 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux

As far as I am concerned, SPI should get enabled when I add the following lines to /boot/config.txt:
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=22
dtparam=spi=on

The mcp2515-can0.dtbo file is present in the /boot/overlays folder.

When the Pi boots, I can't seem to find an entry for SPI in /dev/ (checked with ls | grep spi)

The /sys/bus/spi/devices folder is also completely empty.

The kernel does not seem to give any errors regarding SPI (checked with dmesg | grep spi).

So I started to think that the some other dtbo files are absent or something along those lines. So I added some deprecated lines to the /boot/config.txt file, to see if that makes a difference:
dtoverlay=spi-bcm2835-overlay
dtoverlay=spi-bcm2835

Which seems to change nothing (as expected, since they are deprecated overlay files, which aren't present in the newest RPi Firmware files: https://github.com/raspberrypi/firmware/tree/master/boot/overlays)

There also are no blacklisting files present in /etc/modprobe.d or in /etc/modules

Then finally, I have also tested the spi0-1cs.dtbo file with the following line (note, I commented all the other config.txt lines, so this line is the only one present):
dtoverlay=spi0-1cs,cs0_spidev, still not even the slightest hint that the SPI bus is present.

EDIT: I also found out that when I list all kernel modules with lsmod, that only the sch_fq_codel and the ipv6 modules are loaded. When I check the /proc/modules file, it also only shows those 2 entries.

The /lib/modules/5.10.81-v8/kernel folder only seems to contain entries for net modules, although the /lib/modules/5.10.81-v8/modules.builtin file does have entries regarding SPI. (pointing to kernel/drivers/base/regmap/regmap-spi.ko and kernel/drivers/mfd/stmpe-spi.ko, which both don't seem to exist.) So it seems like the kernel modules are not available in this build? Does anyone know how I could force these modules into my build?

Also, there is no /etc/modules file present in my build by default. If I understand correctly it will imitate calling modprobe $MODULE for each line entry. When I try to run modprobe spidev (or modprobe spi-dev for that matter, or modprobe i2c-dev) it gives an error modprobe: FATAL: Module spidev not found in directory /lib/modules/5.10.81-v8 which sounds logical, since those files are not present in my filesystem.

I am running out of ideas to try. Does anyone else maybe have a idea on what I could try?

Thanks in advance.

With kind regards,
Mats de Waard

2 Answers 2

3

Alright ladies and gents...

I got it to work!

Turns out Yocto does not add the kernel modules to the final image.tar.bz2, but keeps in in a seperate modules.tgz file. I was manually copying the image.tar.bz2 contents and the bootfiles contents onto my CM4 (so this did not include the modules).

Manually adding the files to the eMMC of the Raspberry Pi CM4 seemed to work after I updated the kernel dependencies with depmod. After updating these dependencies, the modprobe spidev command works correctly, and I can now access the SPI device under /dev/spidev0.0 and /dev/spidev0.1!

It might be possible that this problem would be bypassed, if I had learned to use the .WIC files, delivered with a Yocto build, instead of copying the files manually to the eMMC.

Hopefully my findings will save someone some headaches :)

0

I would like to add few details to the accepted solution. I fixed by appending all the required kernel modules in my custom image recipe:

IMAGE_INSTALL:append = " iproute2"
IMAGE_INSTALL:append = " kernel-module-spidev"
IMAGE_INSTALL:append = " kernel-module-spi-bcm2835"
IMAGE_INSTALL:append = " kernel-module-can"
IMAGE_INSTALL:append = " kernel-module-can-dev"
IMAGE_INSTALL:append = " kernel-module-can-raw"
IMAGE_INSTALL:append = " kernel-module-mcp251x"

Note that this depends by the hardware you are using. In my case it is an MCP2515 connected to a Raspberry CM4.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.