Linux /dev/spidev1.0 present, but no SPI communication

Dear Toradex Community,

I want to test SPI on Colibri VF61 using the spidev_test testing utility from Linux sources. The spidev_test tool prints the data it is receiving. As I connected SPI MOSI with SPI MISO, I expect to see the data sent. I also connected SPI clock and MOSI to an oscilliscope but I can see neither a clock nor data. The \dev\spidev1.0 entry is present in the Linux file system. Therer are no error messages when opening a filedescriptor or doing the configuration using ioctl(). But there is simply no communication on the pins.

We are using Colibri VF61 together with Viola carrier board Rev 1.1.
On the X9 expansion header of Viola carrier board I made the following connections:

  • MOSI - X9 PIN20 (Colibri PIN_92)
  • MISO - X9 PIN21 (Colibri PIN_90)
  • CLK - X9 PIN22 (Colibri PIN_88)

We use the following Linux configuration

  • Buildroot 2015.11
  • Linux kernel from git://git.toradex.com/linux-toradex.git (version c78b5ae472e69452d5fe44c261d57c8083c59f74)
  • Device tree from kernel vf610-colibri-eval-v3

The kernel you are using is V2.3 Beta 7, which still uses the old NAND ECC format. I recommend to switch to a newer, 4.1 based kernel, e.g. our stable release (branch toradex_vf_4.1, e6d111cd909551cec5902358db1e25dcaa8c86bb).

There is one caveat though, with that release, you need to alter the device tree or kernel sources to enable the spidev, see Unable to find SPI node in /dev directory - Toradex Community

With the new kernel and using spidev as compatible string, I could successfully communicate with a MCP2515 (which is available on our Colibri Evaluation Carrier Board)

spidev_test -D /dev/spidev1.0  -p "\x03\x0f\x00" -v
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 KHz)
TX | 03 0F 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __     __  | ...
RX | FF FF 87 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  | ..�

Dear Toradex Community,

I’ve switched to 4.1 based kernel and created a custom device tree file with the following lines.

&dspi1 {
	status = "okay";

	mcp2515can: can@0 {
		status = "disabled";
	};

	spidev1: dspi@1 {
		status = "okay";
		compatible = "spidev";
		reg = <0>;
		spi-max-frequency = <50000000>;
	};
	
};

I got the /dev/spidev1.0 entry on the file system but still were not able to send spi messages connecting MOSI and MISO and using the spidev_test tool. The problem was that I’ve used an older version of the spidev_test tool that didn’t set all entries in the spi_ioc_transfer struct. My version was:

	struct spi_ioc_transfer tr;
	tr.tx_buf = (unsigned long)tx;
	tr.rx_buf = (unsigned long)rx;
	tr.len = len;
	tr.delay_usecs = delay;
	tr.speed_hz = speed;
	tr.bits_per_word = bits;

And the version that perfectly works is:

	struct spi_ioc_transfer tr;
	tr.tx_buf = (unsigned long)tx;
	tr.rx_buf = (unsigned long)rx;
	tr.len = len;
	tr.delay_usecs = delay;
	tr.speed_hz = speed;
	tr.bits_per_word = bits;
	tr.tx_nbits = 0;
	tr.rx_nbits = 0;
	tr.pad = 0;

Thanks for your update.

To avoid such issues in the future I recommend to make sure that the struct is either not on stack, or initialized properly using

memset(&tr, 0, sizeof(tr));

Or with C99 compound literals

struct spi_ioc_transfer tr = (const struct spi_ioc_transfer){ 0 };