Using SPI in Torizon 7.0.0

I need some help with accessing the SPI port on a Colibri iMX6DL from inside a container running on Torizon 7.0.0. I was able to do this in a simple way a few years ago with Torizon 5.3.0 by simply sharing /dev/spidev3.0 with my container and then just using it from within the container. But things seem to have changed in Torizon 7.0.0.

I’m trying to follow the instructions from here:

I do see a link on my module in /sys/bus/spi/devices/spi3.0 which points to /sys/devices/platform/soc/2000000.bus/2000000.spba-bus/2014000.spi/spi_master/spi3/spi3 but if I try to use that in a container using the --device option then I get the error message:

docker: Error response from daemon: error gathering device information while adding custom device "/sys/devices/platform/soc/2000000.bus/2000000.spba-bus/2014000.spi/spi_master/spi3/spi3.0": not a device node.

I also tried using --mount rather than --device on the docker command line, and then using the Linux SPI test tool, but that tool does not recognize that path as a valid SPI device.

The section on Container Access in the instructions in the link above suggests that I should see a device like dev/colibri-spi-cs0 but I don’t see anything like that.

Do I need to disable the mcp251x0 CAN device in order to free up the SPI device? I did try that in a device overlay, but it didn’t make any difference.

The reply from tdx-info on my module is:

Software summary
------------------------------------------------------------
Bootloader:               U-Boot
Kernel version:           6.6.53-7.0.0-00029-g68da80fb0462 #1-Torizon SMP PREEMPT Mon Jun 17 16:49:11 UTC 2024
Kernel command line:      enable_wait_mode=off galcore.contiguousSize=50331648 root=LABEL=otaroot rootfstype=ext4 quiet logo.nologo vt.global_cursor_default=0 plymouth.ignore-serial-consoles splash fbcon=map:3 ostree=/ostree/boot.1/torizon/8d8749c43302486d8779e311b8f4190053daefacf298711530294fb79f25b942/0
Distro name:              NAME="Torizon OS Upstream"
Distro version:           VERSION_ID=7.0.0-build.1
Hostname:                 colibri-imx6-10634753
------------------------------------------------------------

Hardware info
------------------------------------------------------------
HW model:                 Toradex Colibri iMX6DL/S on Colibri Evaluation Board V3
Toradex version:          0015 V1.1A
Serial number:            10634753
Processor arch:           armv7l
------------------------------------------------------------

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello,

Accessing SPI devices in Torizon 7.0.0 has indeed changed slightly from earlier versions. Here’s how you can resolve the issues you’re facing:

  1. Device Node Access: Ensure that the SPI device is enabled in the device tree and that the corresponding device node, such as /dev/spidev3.0, is present on the host system. This node should be used with the --device option in Docker, not paths from /sys, which are not device nodes.

  2. Using the --device Option: When running your container, use the --device option to pass the SPI device node to the container. For example:

    docker run --rm -it --device /dev/spidev3.0 my-spi-container
    

    This should allow your container to access the SPI device directly.

  3. Device Tree Overlays: If the SPI device node is not appearing, you may need to modify the device tree to enable the SPI interface. This might involve disabling conflicting devices like the mcp251x0 CAN device if they are using the same SPI bus. You can do this by creating a custom device tree overlay.

  4. Checking Device Nodes: Verify that the expected device nodes (e.g., /dev/colibri-spi-cs0) are correctly linked to the actual SPI device nodes. If these are not present, it might indicate a configuration issue in the device tree or the kernel.

  5. User Permissions: Ensure that the user running the container has the necessary permissions to access the SPI device. Torizon uses an spidev group to manage access, so adding your user to this group might be necessary.

By following these steps, you should be able to access the SPI port on your Colibri iMX6DL module from within a container on Torizon 7.0.0. If issues persist, double-check the device tree configuration and ensure that the SPI interface is correctly enabled and not conflicting with other peripherals.

Best regards,
Toradex AI Assistant.

Please, also check if these links can help you solve your problem:

https://www.toradex.com/sitemap.

Greetings @MikeS,

As the ToradexAI suggested you can still use the /dev/spidev3.0 interface like before. You just need to enable it since it’s not enabled by default anymore. We have a pre-made device tree overlay to enable this functionality.

You can either modify your device’s /boot/ostree/torizon-<some hash>/dtb/overlays.txt to have the SPIDEV overlay applied like so:

# overlays.txt
fdt_overlays=colibri-imx6_vga-640x480_overlay.dtbo colibri-imx6_spidev_overlay.dtbo

Or you can use TorizonCore Builder to create a custom image with this overlay applied by default.

Either way, once this is applied you should see the following on your device:

torizon@colibri-imx6-05102523:~$ ls -l /dev/spidev3.0
crw-rw-r-- 1 root spidev 153, 0 Dec  3 20:23 /dev/spidev3.0
torizon@colibri-imx6-05102523:~$ ls -l /dev/colibri-spi-cs0
lrwxrwxrwx 1 root root 9 Dec  3 20:23 /dev/colibri-spi-cs0 -> spidev3.0
torizon@colibri-imx6-05102523:~$ sudo tdx-info

Software summary
------------------------------------------------------------
Bootloader:               U-Boot
Kernel version:           6.6.53-7.0.0-00029-g68da80fb0462 #1-Torizon SMP PREEMPT Mon Jun 17 16:49:11 UTC 2024
Kernel command line:      root=LABEL=otaroot rootfstype=ext4 quiet logo.nologo vt.global_cursor_default=0 plymouth.ignore-serial-consoles splash fbcon=map:3 ostree=/ostree/boot.1/torizon/be872468b7b697020ed89215ad325489e49742b825240eef396819058c8d8f10/0
Distro name:              NAME="Torizon OS Upstream"
Distro version:           VERSION_ID=7.0.0-build.1
Hostname:                 colibri-imx6-05102523
------------------------------------------------------------

Hardware info
------------------------------------------------------------
HW model:                 Toradex Colibri iMX6DL/S on Colibri Evaluation Board V3
Toradex version:          0017 V1.1A
Serial number:            05102523
Processor arch:           armv7l
------------------------------------------------------------

From there you should be able to make use of /dev/spidev3.0 like you did in the past.

Best Regards,
Jeremias

Thanks for the quick reply @jeremias.tx! That appears to work as expected. I now have /dev/spidev3.0 in my file system and I can pass it into a container as a device. I used spidev_test to test it inside the container and saw these results:

root@7ea226653c13:/# ./spidev_test -D /dev/spidev3.0
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 kHz)

Next step is to access it from my own code and talk to some real hardware. Thanks again!

Perfect, glad I was able to assist.

Best Regards,
Jeremias