Enable SPI on IMX8QXP with Torizon OS

I want to use the SPI on Colibri IMX8 with Torizon. I currently use “TorizonCore image with Docker runtime, 4.0.0-devel-20200324+build 27” but there are no SPI devices visible in the /dev folder.

Is the SPI port enabled by default? If not, how can I enable it and verify that the port is enabled?

Greetings @Jacmo,

It seems you are correct according to the device tree source here, there is a spidev defined but is is disabled by default. I’ll speak with our team to see if this is something we can have enabled by default as to match the behavior of other Torizon compatible modules.

As for the time-being however this is certainly something you can change. You just need to change the single line in the source code I linked above from “disabled” to “okay”. If you need further instructions on how to build our kernel source you can see the article here.

The article is written for our non-Torizon BSP, but in the case of the i.MX8X we use the same kernel in Torizon. So those instructions should be okay for setting up and building the kernel after you make your changes.

The deployment of your new device tree however is a slightly different for Torizon. After you have built you new device tree binary you need just replace the old one which should be at this location on the device: /boot/ostree/torizon-{some checksum}/. At this directory location you need just replace the old device tree binary with the new one. After a quick reboot the system should load the new device tree with your SPI changes.

Please note we aim to make such device tree changes will be easier in the future, as we increase support for the new i.MX8X platform.

Best Regards,
Jeremias

Hi,

Could you elaborate what you mean by the device is visible but you can’t access it?

Best Regards,
Jeremias

The device is visible in the /dev folder but I can not open it. This is what I am trying to do:

#define SPI_DEVICE "/dev/spidev0.0"

fd = open(SPI_DEVICE, O_RDWR | O_NONBLOCK);
if (fd < 0)
{
   err = errno;
   if (DEBUG == TRUE)
   {
      printf("spi_init - fatal: Failed to open device \"%s\", errno: %i\n", SPI_DEVICE, err);
   }
   return SPI_OPEN_FAIL;
}

Hi Jeremias,

I have changed the line in the source code and built a new device tree binary. I have also disabled the mcp2515 device as mentioned here. The spidev0.0 is now visible in the /dev folder but I can still not access the device. Is there something I have missed as the device is not available for our software solution?

At initial glance nothing seems odd about your code snippet. Some further questions I have:

  • Other than enabling spidev were any other changes made to the system?
  • Are you running your code on the base OS or in a container?
  • Anything unique about the SPI device you’re trying to use?

Another suggestion I have is try the spidev testing utility available in the Linux Kernel: https://github.com/torvalds/linux/blob/master/tools/spi/spidev_test.c

Best Regards,
Jeremias