6 Replies Latest reply on Apr 12, 2016 11:53 PM by BhoomsC

    Intel Galileo Gen 2 board SPI access

    D08

      Hi,

      I am working with Intel Galileo Gen 2 board and I want access on board spi.I have following the steps of pin mapping to access SPI-MOSI, MISO, and CLK as given in below given link.

       

      http://www.emutexlabs.com/component/content/article?id=203:getting-started-with-intel-galileo-gen-2

       

      but what is the pin mapping steps to get SPI-CS pin?

      I have changed in grub.conf file as described below.

      ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

      default 0

      timeout 5

       

      title IDP for Intel Quark-based Platform - MMC

          root (hd0,0)

          kernel /bzImage intel_qrk_plat_galileo_Gen 2.gpio_cs=1 console=ttyS1,115200n8 root=/dev/mmcblk0p2 ro rootwait reboot=efi,warm

      ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

       

      To verify this, the following command should return an error since the GPIO is now reserved by the SPI driver:

      echo 10 > /sys/class/gpio/export


      but i am not getting any error.


      So, any suggestion.


      Thank You.

        • 1. Re: Intel Galileo Gen 2 board SPI access
          Intel_Alvarado

          Hi,

           

          When connecting a SPI device to the SPI bus of the Galileo, any GPIO can work as the SPI-CS. The SPI bus is composed of the MOSI, MISO and CLK. The CS can be toggled as a regular GPIO, this means that you can select the SPI device with any GPIO if configured correctly. If you are going to connect multiple devices then you would need to set more GPIOs as CS to select the SPI device.


          Sergio

          • 2. Re: Intel Galileo Gen 2 board SPI access
            D08

            Hi,

            As per above link, echo 10 > /sys/class/gpio/export should return an error after modifying gurb.conf file in boot directory, but in our case after successful getting linux console when we run this command

            echo 10 > /sys/class/gpio/export  

            not give any error. So, is that GPIO10 is configured as CS pin? Also if it is configured when we execute below code, do i need to any change related to CS pin while data transferring as per below code or it does automatically when IOCTL command is executed.

             

            #include <stdio.h>

            #include <sys/types.h>

            #include <sys/stat.h>

            #include <fcntl.h>

            #include <unistd.h>

            #include <sys/ioctl.h>

            #include <linux/types.h>

            #include <linux/spi/spidev.h>

            #include <stdint.h>

            #include <stdio.h>

            #include <string.h>

            #include <errno.h>

             

            int main(int argc, char **argv)

            {

            char *name;

            int fd;

            struct spi_ioc_transfer xfer[2];

            unsigned char buf[32], *bp;

            int len, status;

             

            name = "/dev/spidev1.0";

            fd = open(name, O_RDWR);

            if (fd < 0) {

            perror("open");

            return 1;

            }

             

            memset(xfer, 0, sizeof xfer);

            memset(buf, 0, sizeof buf);

            len = sizeof buf;

             

             

            buf[0] = 0x80;

            buf[1] = 0x04;

            len = 6;

            xfer[0].tx_buf = (unsigned long)buf;

            xfer[0].len = 2;

             

            xfer[1].rx_buf = (unsigned long) buf;

            xfer[1].len = 6;

             

            status = ioctl(fd, SPI_IOC_MESSAGE(2), xfer);

            if (status < 0) {

            perror("SPI_IOC_MESSAGE");

            return 1;

            }

            printf("response(%d): ", status);

            for (bp = buf; len; len--)

            printf("%02x ", *bp++);

            printf("\n");

             

            buf[0] = 0x00;

            len = 6;

            xfer[0].tx_buf = (unsigned long)buf;

            xfer[0].len = 1;

             

            xfer[1].rx_buf = (unsigned long) buf;

            xfer[1].len = 6;

             

            status = ioctl(fd, SPI_IOC_MESSAGE(2), xfer);

            if (status < 0) {

            perror("SPI_IOC_MESSAGE");

            return 1;

            }

            printf("response(%d): ", status);

            for (bp = buf; len; len--)

            printf("Data %02x ", *bp++);

            printf("\n");

            }

             

            Thank You.

            • 3. Re: Intel Galileo Gen 2 board SPI access
              Intel_Alvarado

              Hi,

               

              According to EmutexLabs you need to edit the grub.conf file in /media/mmcblk0p1/boot/grub/grub.conf and add the parameter you listed. But in your original post right after you added that line I can see /dev/mmcblk0p2, does it make a difference if you change mmcblk0p2 for mmcblk0p1. Remember you have to reboot in order for this changes to apply.

               

              Sergio

              • 4. Re: Intel Galileo Gen 2 board SPI access
                Nilesh.kadivar

                Hi Sergio,

                 

                /dev/mmcblk0p2 it boots properly. As per you suggestion when i make it to /dev/mmcblk0p1 then it not boots properly. Do you have any other solution to work SPI on galileo gen2 board?

                 

                thanks,

                Nilesh

                • 5. Re: Intel Galileo Gen 2 board SPI access
                  Intel_Alvarado

                  Hi Nilesh.kadivar,

                   

                  Use the path that correctly boots the board in your case /dev/mmcblk0p2. Take a look at Re: Galileo Gen-2 Spidev1.0 . The correct answer from this post uploaded a script that enables the SPI for the Gen 2.

                   

                  If this doesn’t work then there is probably some older configurations giving you trouble. You can try installing the latest image Intel® Galileo Boards and Kits — Software Downloads in a recently formatted SD card.

                   

                  Sergio

                  • 6. Re: Intel Galileo Gen 2 board SPI access
                    BhoomsC

                    Hi D08

                    Should edit like "intel_qrk_plat_galileo_gen2.gpio_cs=1" not "intel_qrk_plat_galileo_Gen 2.gpio_cs=1".

                    Then after, echo 10 > /sys/class/gpio/export give me an error like " Device/Resource is busy". I have check the singal level of Slave select pin with digital oscilloscope during execution of SPI test app.

                    Clock is also generated as expected but end sensor doesn't respond me at all.


                    And one more point I want add,

                    the default configuration of PIN#11 and PIN#13 are inline with SPI function.

                    For PIN#11 -> the gpio44 is HIGH and gpio72 is LOW. So, it is expected.

                    For PIN#13 -> the gpio46 is HIGH. So, it is expected.


                    But problem is only while data transfer.