SPI Slave configuration on Apalis imx8qp devicetree setup

Hi,

We are trying to configure the SPI device on the Apalis imx8. Our setup consist of a (Custom) Apalis board we call “Core” and one of more Slave device’s we call “Hubs”. We connect the Core and Hubs using a Daisy chain configuration and want to configure one SPI bus on the Apalis board as Master and a 2nd one as a Slave device.

SP1 as a master and SP2 as a slave. In the devicetree both SPI buses are configured as Master if I understand correctly . To set the Apalis SPI2 as a slave device I adjusted the devicetree files as follow:

file:imx8-aplais-ixora-custom.dtsi →

/* Apalis SPI2 */
&lpspi2 {
	spi-slave;
	status = "okay";
};

file :imx8-apalis-v1.1.dtsi →

/* Apalis SPI2 */
&lpspi2 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_lpspi2>;
	#address-cells = <1>;
	#size-cells = <0>;
	cs-gpios = <&lsio_gpio3 10 GPIO_ACTIVE_LOW>;

	spidev1: slave@0 {
		compatible = "toradex,evalspi";
		reg = <0>;
		spi-max-frequency = <4000000>;
	};
};

After flashing the newly created image I was able to Init and set both SPI devices (Using the SPiTestUtility.c with spidev driver). After sending data the spi master stops responding.

Without devicetree adjustment I could send data of the SPI Master (SPI1) but not receive it on SPI2.

Did I configure the devicetree correctly ?
In Linux two spi device’s are available /dev/spidev0.0 (master) and dev/spidev1.0 (slave)

Connection Layout (pin config default):

SPI1_CLK  :  OUT CLK
SPI1_MOSI: OUT DATA
SP1_CS      : OUT SS

SPI2_MOSI: IN DATA
SP2_CS     :  IN_CS
SPI2_CLK :  IN_CLK

Test Logging (Visual Studio Code):

  • Init spi 1 *
    spi mode: 0x1
    bits per word: 8
  • Init spi 2 *
    spi mode: 0x1
    bits per word: 8
    speed set to: 300000
    set bits per burst to: 8

System:
Module : Toradex Apalis iMX8QP
Linux with TorizonCore 5.7.0 docker containers

Note: core and hub worked with an iMX6 Module and dedicated spi_driver.

Hello @wjanssen ,
Pleas have a look at this thread in the NXP community, it might help.

Best regards,
Josep

Hi Josep,

I looked the information on the NXP site however the links to the examples provided are broken. Can you supply an Example or an updated link that works ?

I was able to get a new link to the SCFWKIT but that did not help me much
scfwkit :
https://www.nxp.com/webapp/sps/download/license.jsp?colCode=L4.14.98_2.0.0_SCFWKIT-1.2

Greetings,
Willem

Hello @wjanssen ,
We have also found this one :

Please note that all the links to codeaurora.com are broken (https://bye.codeaurora.org) You might try to find the examples on NXP’s Github (NXP · GitHub).

Best regards,
Josep

Hi @wjanssen !

Do you have an update about this thread? Was your issue solved? :slight_smile:

Best regards,

Unfortunately we are still struggling with this. Using a daisy chain setup is not widely used. We were not able to find a good example. In more detail the data in is connected on the MOSI port in the daisy chain setup which is different when using regular SPI.

Hi @wjanssen !

I would like to ask you to try the following:

  • Add spi-slave to &lpspi2 (as you have already done)
  • Remove/Delete the cs-gpios property from &lpspi2
    • You need to add /delete-property/ cs-gpios; to the node.
      • Important: It can’t be done in a device tree overlay
  • Change the mux of the pin IMX8QM_SPI2_CS0 from LSIO_GPIO3_IO10 to DMA_SPI2_CS0
    • You can change direcly the pinctrl_ecspi2 or create a new pinctrl set and assign it to the pinctrl-0 property of &lpspi2

This should be it for the device tree modification.

To test it, please refer to Tests:MSIOF-SPI-Slave - eLinux.org.

Let us know if this helps you :slight_smile:

Best regards,

Hi,

Thank you for your suggestions. I have added the /delete propertery/ cs-gpios to the &lpspi2 and changed the mux of the pin in the devicetree. The result was that the slave device was able to receive bytes but the spimaster locks up after sending data.
Next I updated the SPI master &lpspi0 by adding the /delete-property cgpios and
changing the mux of the pin IMX8QM_SPI0_CS0 from IMX8QM_SPI0_CS0_LSIO_GPIO3_IO05 to
DMA_SPI0_CS0. Now the SPI Master was able to send data successfully but as soon as I tried to retrieve a message from the spi slave the slave device blocks. Here the output from SPITester on the last change (1st the spi master, then the spi slave on spidev1.0) :

root@f99f75e4e81a:/ProgramLogic/bin# ./SPITest -v
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 kHz)
TX | 00 00 00 80 00 01 00 00 00 00 00 00 80 00 02 55 AA CC __ __ __ __ __ __ __ __ __ __ __ __ __ __ |…U…|
RX | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ |…|
root@f99f75e4e81a:/ProgramLogic/bin# ./SPITest -v -D /dev/spidev1.0
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 kHz)

Afterwards dmseg shows the following output:
[11316.764060] spidev spi1.0: SPI transfer failed: -4
[11316.768904] spi_slave spi1: failed to transfer one message from queue

Greetings,
Willem

Hi @wjanssen !

Are you sure you should remove the cs-gpios property from the master SPI? AFAIK, it should be there, so the driver can use the CS pins.

A reference I found about i.MX8QM and SPI slave: imx8qm-lpddr4-val-lpspi-slave.dts « freescale « dts « boot « arm64 « arch - linux-toradex.git - Linux kernel for Apalis, Colibri and Verdin modules

But, as you are using daisy chain, I do not have information if the driver actually supports this topology (also, I am not sure whether this topology needs driver support or not - currently my guess is that it does).

Best regards,

Hi,

Good point. I added the cs-gpios to the master SPI again and tested it. In our case it did not make any difference. It could be that the driver does not fully support our setup. One single master or a single slave SPI device seems to work but not combined in one solution.

Hi @wjanssen !

Do you mean that if you connect SPI1 as master directly to SPI2 as slave it doesn’t work?

Or you meant that having more than one slave (in daisy chain) doesn’t work?

Or something else?

Best regards,

Hi @wjanssen!

Did you have time to go through the questions above?

An important remark: the slave must have its buffer defined with data before being called (e.g. with spidev). So you can’t define the answer to a message after you received it.


Also, could you please share how you did the setup on Apalis iMX6 to use the daisy chain on SPI? This could help us with some pointers. Which BSP version you used in Apalis iMX6? And was it upstream or downstream?

Best regards,