Mainline Kernel , Apalis T30 and SPI

Dear all/ @marcel.tx

I am using Apalis T30 module version 1.0 E on Ixora carrier board v1.0A.
I have successfully compiled mainline kernel 4.18.11 and I am quite happy with the result as I have everything working as I expected.

I need to connect a NRF24L01+ radio modul using the SPI however, I do not see any SPI device in /dev/spi*
I double checked the “tegra30-apalis-eval.dts” device tree and it seems that the spidev are already enabled.

        /* SPI1: Apalis SPI1 */
        spi@7000d400 {
                status = "okay";
                spi-max-frequency = <25000000>;
                spidev0: spidev@1 {
                        compatible = "spidev";
                        reg = <1>;
                        spi-max-frequency = <25000000>;
                };
        };

        /* SPI5: Apalis SPI2 */
        spi@7000dc00 {
                status = "okay";
                spi-max-frequency = <25000000>;
                spidev1: spidev@2 {
                        compatible = "spidev";
                        reg = <2>;
                        spi-max-frequency = <25000000>;
                };
        };

Can you please advise if this can be done and I can use mainline kernel on Apalis T30 and connect a SPI module to that?

I appreciate your helps…

Most likely you do not have the user space SPI dev driver enabled in your kernel configuration. Otherwise, please do post the full serial console boot-up log as a textual file for us to have a look at.

Dear @marcel.tx ,
As always, you were right. I have enabled that option in Kernel and I can see the SPI devices now.
While I am in this post, may I kindly ask you to advise me for a question regarding to the same mater?

Now that I have the SPI devices,I plan to connect my SPI module (NRF24L01+) to pin numbers as per Ixora X27 header:

8 -> SPI1_CLK
9  -> SPI1_CS
10 ->  SPI1_MISO
11 -> SSP_MOSI 

May I kindly ask you to advise if that is correct and also kindly tell me what will be the GPIO number for Apalis T30 if I want to set the pin number inside my application (MySensors Library) to recognize the SPI module?

As always, you were right. I have enabled that option in Kernel and I can see the SPI devices now. While I am in this post, may I kindly ask you to advise me for a question regarding to the same mater?

Sure.

Now that I have the SPI devices,I plan to connect my SPI module (NRF24L01+) to pin number as per Ixora X27 header:

8 -> SPI1_CLK

9 -> SPI1_CS

10 -> SPI1_MISO

11 -> SSP_MOSI

May I kindly ask you to advise if that is correct

Yes, that looks about right.

and also kindly tell me what will be the GPIO number for Apalis T30 if I want to set the pin number inside my application (MySensors Library) to recognize the SPI module?

I don’t think any GPIO number is required (what for anyway?) as /dev/spi0 will directly talk to your device hooked up to Apalis SPI1 incl. asserting its chip select SPI1_CS.

@marcel.tx
The library needs to be compiled for specific board.
For instance I have added these lines to enable the pins for Tegra as it shows it has a sample pin for Raspberry Pi:

#if defined(LINUX_ARCH_TEGRA)
// Default to Tegra, Apalis T30
const uint8_t SS   = 9;
const uint8_t MOSI = 11;
const uint8_t MISO = 10;
const uint8_t SCK  = 8;
#else
// Default to Raspberry Pi
const uint8_t SS   = 24;
const uint8_t MOSI = 19;
const uint8_t MISO = 21;
const uint8_t SCK  = 23;
#endif
....

The pin for RPi, (24,19,21,23) correspond to the physical pin on RPi header.
I have to do the same for Tegra configuration which I have added above to be able to compile the app properly.
However, I am struggling adding the right GPIO number…
Thats the place I need to configure

The library needs to be compiled for specific board. For instance I have added these lines to enable the pins for Tegra as it shows it has a sample pin for Raspberry Pi:

Not sure what exactly you are talking about, sorry.

The pin for RPi, (24,19,21,23) correspond to the physical pin on RPi header. I have to do the same for Tegra configuration which I have added above to be able to compile the app properly. However, I am struggling adding the right GPIO number… Thats the place I need to configure

For SPI usage I really don’t see why one would need to know any GPIO numbers unless it would not even use the in-kernel driver but rather do some kind of user space bit-banging.

The only related thing I could think of is e.g. libsoc where our boards recently got added which allows you directly using MXM3 resp. SODIMM pin numbers:

https://developer.toradex.com/knowledge-base/gpio-(linux)#GPIO_Libsoc

I don’t know how to explain. I only need to directly communicate via GPIO pins on header X27.
I just need to know what will be the proper GPIO pin number for MOSI, MISO, SC and SCK pins…

I don’t know how to explain.

That is usually a good indication of the whole approach being flawed.

I only need to directly communicate via GPIO pins on header X27.

But communicate what? What for? Didn’t you want to do SPI? What should that have to do with GPIOs?

I just need to know what will be the proper GPIO pin number for MOSI, MISO, SC and SCK pins…

Well, the regular MXM3 resp. SODIMM pin to in-kernel GPIO number mapping may be found here:

https://developer.toradex.com/knowledge-base/gpio-alphanumeric-to-gpio-numeric-assignment

@marcel.tx ,
Let say an example:
GPIO3 , Physical pin 15 on Ixora is : GPIO 148 in sysfs for Apalis T30

What would be for these?

8 -> SPI1_CLK
9 -> SPI1_CS
10 -> SPI1_MISO
11 -> SSP_MOSI

Finally I found it myself.
For every one else want to know , here is the way to find the proper GPIO number for physical Pin on X27 (Ixora):

Example: What is Linux Pin number to control if Ixora GPIO Pin no is 15

apalis_arm_ixora_datasheet
---------------------------
	Page: 30 -> 3.16. Extension Header (X27)
	
	15 ==> GPIO3

Then we go to : apalis_t30_datasheet
----------------------------------------------
  Page: 13 -> Table 3-1 X1 Connector
  
  GPIO3 (Apalis Signal Name) ==> 5 (X1)  

Then:
	Page: 21
	5 (X1 pin) -> GPIO-S.04 (GPIO)  ==> Which will be: S4

Then:
	URL:   https://developer.toradex.com/knowledge-base/gpio-alphanumeric-to-gpio-numeric-assignment#T20_T30_TK1
	
	"S4" in "GPIO" column will be : 148 in "Numeric Representation" column
	
	
To control that pin (148 -> Physical pin 15):    
	# echo 148 > /sys/class/gpio/export
	# echo out > /sys/class/gpio/gpio148/direction
	
	# echo 1 > /sys/class/gpio/gpio148/value
	# echo 0 > /sys/class/gpio/gpio148/value

Therefore:

    Physical 8 --> 221 (X1): SPI1_SCK ---> 189 
    Physical 9 --> 227 (X1): SPI1_SS ---> 190
    Physical 10 --> 223 (X1): SPI1_MISO ---> 191
    Physical 11 -> 225 (X1): SPI1_MOSI ---> 188