[iMX8] SPI2 (spidev1.0) not working on 3.0b4


after updating to 3.0b4, the spi2 interface is unfortunately not working.

The program was working proberly on 3.0b3

#define SPI1_MODE 2
#define SPI1_CLK_SPEED 10 * 1000000 //10Mhz
#define SPI1_BITS 8
#define SPI1_DELAY 0
static const char *SPI_dev_name = "/dev/spidev1.0";
uint8_t rxBuffer[2];
uint8_t CONFIG1[2] =  {0x40,0x03};

void transferSPI(int fd,struct spi_ioc_transfer* tr, uint8_t const *tx, uint8_t const *rx, size_t len)
	int ret;
	tr->tx_buf = (unsigned long)tx;
	tr->rx_buf = (unsigned long)rx;
	tr->len = len;

	ret = ioctl(fd, SPI_IOC_MESSAGE(1), tr);
	if (ret < 1)
		pabort("can't send spi message");


int SPI_initialize( const char  *dev,struct spi_ioc_transfer *tr,uint32_t mode,uint8_t bits,uint32_t speed,uint16_t delay)
	int spiFD,ret;

	tr->delay_usecs = delay;
	tr->speed_hz = speed;
	tr->bits_per_word = bits;

	if (mode & SPI_TX_QUAD)
		tr->tx_nbits = 4;
	else if (mode & SPI_TX_DUAL)
		tr->tx_nbits = 2;
	if (mode & SPI_RX_QUAD)
		tr->rx_nbits = 4;
	else if (mode & SPI_RX_DUAL)
		tr->rx_nbits = 2;
	if (!(mode & SPI_LOOP)) {
		if (mode & (SPI_TX_QUAD | SPI_TX_DUAL))
			tr->rx_buf = 0;
		else if (mode & (SPI_RX_QUAD | SPI_RX_DUAL))
			tr->tx_buf = 0;

	spiFD = open(dev, O_RDWR);
	if (spiFD < 0)
		pabort("can't open device");

	 // spi mode
	ret = ioctl(spiFD, SPI_IOC_WR_MODE32, &mode);
	if (ret == -1)
		pabort("can't set spi mode");

	ret = ioctl(spiFD, SPI_IOC_RD_MODE32, &mode);
	if (ret == -1)
		pabort("can't get spi mode");

	 //bits per word
	ret = ioctl(spiFD, SPI_IOC_WR_BITS_PER_WORD, &bits);
	if (ret == -1)
		pabort("can't set bits per word");

	ret = ioctl(spiFD, SPI_IOC_RD_BITS_PER_WORD, &bits);
	if (ret == -1)
		pabort("can't get bits per word");

	 // max speed hz
	ret = ioctl(spiFD, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
	if (ret == -1)
		pabort("can't set max speed hz");

	ret = ioctl(spiFD, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
	if (ret == -1)
		pabort("can't get max speed hz");

	printf("spi mode: 0x%x\n", mode);
	printf("bits per word: %d\n", bits);
	printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000);
	return (spiFD);


void pabort(const char *s)

void main()
	fd_spi1 = SPI_initialize(SPI_dev_name,&spi_tr1,SPI1_MODE,SPI1_BITS,SPI1_CLK_SPEED,SPI1_DELAY);
transferSPI(fd_spi1,&spi_tr1,(uint8_t *)CONFIG1,(uint8_t *)rxBuffer,2);


I get also kernel oops when the program starts: oops.log

Best regards, Majd

Hi @majd.m

I installed the Bsp 3.0.4 (non RT) release and I compiled and run your application. It is working fine.

Have you done any changes to the Software (devicetree, …)?
If yes, could you share these changes?

Best regards,

Hi @jaski.tx,

Thanks for your reply, I changed the spi frequency, which worked properly with SPI1, in addition to some other changes: DT_changes.patch

I also used the device tree (generated from yocto) without changes, unfortunately didnt work.

The SPI can be initialized correctly, but the transfer doesnt work when the
ioctl(fd, SPI_IOC_MESSAGE(1), tr); is used (it returns < 1)

Hi Majd

I applied your patch to the kernel branch toradex_4.14-2.3.x-imx and it is working fine. There are no kernel messages.

The issue might be the RealTime Patch. Could you share your kernel config?

Best regards,

Hi @jaski.tx,

here how the kernel config looks like: kernel_config

Best regards, Majd

Hi @jaski.tx

i’ve added (assigned-clock-rates=<40000000>; to the spi node)

The SPI2 seem to work properly with my chip with clock frequency up to 5MHz
It does not work with 10MHz nor 20Mhz

When I turn the frequency to 20Mhz, the SPI communication seem not behaving correctly on the oscilloscope
The SPI clock signal toggels infinitly and the SPI_CS stays always low.

When I downgrade the kernel to the 4.14.159 with the same device tree configurations, the frequency 20Mhz works without problems

Best regards, Majd
[1]: https://share.toradex.com/6cg5jdedbsz1iaw?direct

Hi @majd.m

I installed the following image (from CI feeds), which has same kernel config as yours. There spidev is working perfectly with spi clock frequency up to 12MHz. I did not change the devicetree to get a higher clock.

TDX Wayland with XWayland RT 4.0.0-devel-20200603+build.105 (zeus) \n \l

Best regards,