8 Replies Latest reply on Jan 20, 2016 1:41 AM by sdssly

    Galileo Gen-2 Spidev1.0

    v0od0ochild

      Hi all,

       

      did anyone tried to write to the spi bus using a Galileo gen 2?

      I was able to do so in the first Galileo but not in Gen 2.

       

      I'm trying to light up a digital ledstrip using the IoT-devkit image.

       

      I found this link (EmutexLabs) which includes nice information about the pin mapping and tried to change the gpios following the table below:

       

      4.3 Pin configuration options for Galileo Gen 2

      Shield pin Function Linux Level Shifter GPIO
      L: dir_out
      H: dir_in
      I: *
      22k Pull-Up GPIO
      L: pulldown
      H: pullup
      I: off
      Pin Mux 1 GPIO Pin Mux 2 GPIO Interrupt modes
      L: low-level
      H:high-level
      R:rising-edge
      F:falling-edge
      B:both edges
      IO0 UART0 RX ttyS0 gpio32 gpio33 - - -
      GPIO gpio11 - - L/H/R/F
      IO1 UART0 TX ttyS0 gpio28 gpio29 gpio45 (H) - -
      GPIO gpio12 gpio45 (L) - L/H/R/F
      IO2 UART1 RX ttyS1 gpio34 gpio35 gpio77 (H) -
      GPIO gpio13 gpio77 (L) - L/H/R/F
      GPIO gpio61 - gpio77 (L) - R/F/B
      IO3 UART1 TX ttyS1 gpio16 gpio17 gpio76(H) - -
      GPIO gpio14 gpio76(L) gpio64(L) L/H/R/F
      PWM pwm1 gpio76(L) gpio64(H) -
      GPIO gpio62 - gpio76(L) gpio64(L) R/F/B
      IO4 GPIO gpio6 gpio36 gpio37 - - R/F/B
      IO5 GPIO gpio0 gpio18 gpio19 gpio66(L) - R/F/B
      PWM pwm3 gpio66(H) - -
      IO6 GPIO gpio1 gpio20 gpio21 gpio68(L) - R/F/B
      PWM pwm5 gpio68(H) - -
      IO7 GPIO gpio38 - gpio39 - - -
      IO8 GPIO gpio40 - gpio41 - - -
      IO9 GPIO gpio4 gpio22 gpio23 gpio70(L) - R/F/B
      PWM pwm7 gpio70(L) - -
      IO10 GPIO gpio10 gpio26 gpio27 gpio74(L) - L/H/R/F
      PWM pwm11 gpio74(H) - -
      IO11 GPIO gpio5 gpio24 gpio25 gpio44(L) gpio72(L) R/F/B
      SPI MOSI spidev1.0 gpio44(H) gpio72(L) -
      PWM pwm9 - gpio72(H) -
      IO12 GPIO gpio15 gpio42 gpio43 - - L/H/R/F
      SPI MISO spidev1.0 -
      IO13 GPIO gpio7 gpio30 gpio31 gpio46(L) - R/F/B
      SPI SCK spidev1.0 gpio46(H) - -
      IO14 GPIO gpio48 - gpio49 - - R/F/B
      ADC A0 in_voltage0_raw -
      IO15 GPIO gpio50 - gpio51 - - R/F/B
      ADC A1 in_voltage1_raw -
      IO16 GPIO gpio52 - gpio53 - - R/F/B
      ADC A2 in_voltage2_raw -
      IO17 GPIO gpio54 - gpio55 - - R/F/B
      ADC A3 in_voltage3_raw -
      IO18 GPIO gpio56 - gpio57 gpio60(H) gpio78(H) R/F/B
      ADC A4 in_voltage4_raw gpio60(H) gpio78(L) -
      I2C SDA i2c-0 gpio60(L) - -
      IO19 GPIO gpio58 - gpio59 gpio60(H) gpio79(H) R/F/B
      ADC A4 in_voltage5_raw gpio60(H) gpio79(L) -
      I2C SCL i2c-0 gpio60(L) - -


      Note: with the exception of the “Interrupt Modes” column, the following single-letter convention is used in the table above to indicate the state of a GPIO pin:

      “L” The GPIO is configured as an output, with output level as LOW

      “H” The GPIO is configured as an output, with output level as HIGH

      “I” The GPIO is configured as a high-impedance input

       

      So I've tried setting up the pins 10, 11, 12 and 13 for spi usage

       

      #pin10

      export gpio26

      export gpio74

      echo "out" > /sys/class/gpio/gpio26/direction

      echo "0" > /sys/class/gpio/gpio26/value

      echo "0" > /sys/class/gpio/gpio74/value

       

      #pin11 MOSI

      export gpio24

      export gpio44

      export gpio72

      echo "0" > /sys/class/gpio/gpio26/value

      echo "out" > /sys/class/gpio/gpio44/direction

      echo "1" > /sys/class/gpio/gpio44/value

      echo "0" > /sys/class/gpio/gpio72/value

       

      #pin12

      export gpio42

      echo "0" > /sys/class/gpio/gpio42/value

       

      #pin13 CLK

      export gpio30

      export gpio46

      echo "0" > /sys/class/gpio/gpio30/value

      echo "out" > /sys/class/gpio/gpio46/direction

      echo "1" > /sys/class/gpio/gpio46/value

       

      also tried to change the grub loader as refered in the article.

      4.4 Enabling chip-select line for spidev1.0

      Typically, the SPI controller driver in Linux is responsible for implicitly controlling the chip-select line for a given device. For Galileo Gen 2, GPIO #10 is intended to be used as the chip-select signal when connecting to an external SPI device via the shield I/O pins. As such, the handling of the chip-select signalling is done underneath the SPI API, transparently to client code.

      However, the Arduino library employs a different paradigm for this. Rather than assuming a dedicated chip-select line managed by the SPI controller, Arduino assumes that any GPIO output can be used for chip-select signalling and leaves the choice to the sketch application.

      This creates a conflict between the Linux and Arduino use-cases. For Linux, the SPI controller driver wants to “own” GPIO #10, but for the Arduino use-case this must be left free as a general purpose I/O line. So, the SPI controller driver is instructed on start-up by default to NOT use GPIO #10, thereby satisfying the Arduino case.

      To override this and use SPI at the Linux level (e.g. via /dev/spidev1.0) with implicit chip-select control, the user must first allow the SPI controller driver to use GPIO #10. To do this, edit the grub.conf file (i.e. /media/mmcblk0p1/boot/grub/grub.conf), append the following parameter to the kernel command line (the line beginning with ‘ kernel’ for the relevant grub entry), and reboot:
      intel_qrk_plat_galileo_Gen 2.gpio_cs=1

      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

       

      Still no success.

      Any idea what could be wrong?

       

      Thank you

        • 1. Re: Galileo Gen-2 Spidev1.0
          Intel_Alvarado

          Hi v0od0ochild,

           

          We will run some tests and let you know our results.

           

          Regards

          Sergio

          • 2. Re: Galileo Gen-2 Spidev1.0
            v0od0ochild

            Hi Sergio,

             

            apparently there were some more gpios that required changes,

            using the script below I was able to enable the spi, I'm posting it here in case anyone else needs it:

             

            #!/bin/bash -e
            # v0od0ochild
            echo "Configuring Spidev1.0 for Galileo-Gen2.."
            
            #pin10
            echo 26 > /sys/class/gpio/export || echo "gpio26 already exported"
            echo 74 > /sys/class/gpio/export || echo "gpio74 already exported"
            echo 27 > /sys/class/gpio/export || echo "gpio27 already exported"
            echo low > /sys/class/gpio/gpio26/direction || echo "Failed to set gpio26 low"
            echo low > /sys/class/gpio/gpio74/direction || echo "Failed to set gpio74 low"
            echo in > /sys/class/gpio/gpio27/direction || echo "Failed to set gpio27 direction in"
            
            #pin11
            echo 24 > /sys/class/gpio/export || echo "gpio24 already exported"
            echo 44 > /sys/class/gpio/export || echo "gpio44 already exported"
            echo 72 > /sys/class/gpio/export || echo "gpio72 already exported"
            echo 25 > /sys/class/gpio/export || echo "gpio25 already exported"
            echo low > /sys/class/gpio/gpio24/direction || echo "Failed to set gpio24 low"
            echo high > /sys/class/gpio/gpio44/direction || echo "Failed to set gpio44 high"
            echo low > /sys/class/gpio/gpio72/direction || echo "Failed to set gpio72 low"
            echo in > /sys/class/gpio/gpio25/direction || echo "Failed to set gpio25 direction in"
            
            #pin12
            echo 42 > /sys/class/gpio/export || echo "gpio42 already exported"
            echo 43 > /sys/class/gpio/export || echo "gpio43 already exported"
            echo low > /sys/class/gpio/gpio42/direction || echo "Failed to set gpio42 low"
            echo in > /sys/class/gpio/gpio43/direction || echo "Failed to set gpio43 direction in"
            
            #pin13
            echo 30 > /sys/class/gpio/export || echo "gpio30 alreay exported"
            echo 46 > /sys/class/gpio/export || echo "gpio46 already exported"
            echo 31 > /sys/class/gpio/export || echo "gpio31 already exported"
            echo low > /sys/class/gpio/gpio30/direction || "Failed to set gpio30 low"
            echo high > /sys/class/gpio/gpio46/direction || "Failed to set gpio46 high"
            echo in > /sys/class/gpio/gpio31/direction || "Failed to set gpio31 direction in"
            echo "Spi ready"
            

             

            Thank you,

            Miguel

            1 of 1 people found this helpful
            • 3. Re: Galileo Gen-2 Spidev1.0
              shaka

              Hi, Miguel

               

              When I tring to execute the shell script you pasted, there are some errors happended to me.

               

              The files: /sys/class/gpio/gpio72/direction and /sys/class/gpio/gpio74/direction don't exist. Did you meet the same issue? 72 and 74 are exported and the directories "gpio72/" and "gpio74" exist indeed.

               

              Thanks,

              Weining

              • 4. Re: Galileo Gen-2 Spidev1.0
                v0od0ochild

                Hi Weining,

                 

                the same thing happened to me. I believe it happened because the GPIOs were already exported. That's why I'm using the OR condition in the config script, so if it fails one GPIO it will try to configure the next ones instead of aborting the whole process.

                 

                Best regards,

                Miguel

                • 5. Re: Galileo Gen-2 Spidev1.0
                  Nilesh.kadivar

                  Hi Miguel,

                   

                  For running SPI on Galileo gen2 i followed script you posted. I am OK with this but echo 10 > /sys/class/gpio/export didn't give me any error. also my SPI not works properly so i have doubt that my io10 (chipselect) pin is configured as chip select or not. I did necessary change as they mentioned in grub.conf. Any idea regarding conformation that my pin 10 is configured as chip select?

                   

                  thanks,

                  Nilesh

                  • 6. Re: Galileo Gen-2 Spidev1.0
                    Nilesh.kadivar

                    Hi,

                     

                    Now i am able to select IO10 of Galileo Gen 2 board as chip select. Problem was due to addition of intel_qrk_plat_galileo_Gen 2.gpio_cs=1 in grub.conf but it should be intel_qrk_plat_galileo_gen 2.gpio_cs=1. The problem was due to naming convention of Gen2 which is gen2 in my case. You can verify chip select status from below command

                    cat /sys/module/intel_qrk_plat_galileo_gen2/parameters/gpio_cs


                    Now currently i am able to generate clock, write data and making chip select low but i can not read data. MISO line always remains HIGH. I ran script for SPI as given in above post. If any one have solution please help me.

                     

                    Thanks,

                    Nilesh

                    • 7. Re: Galileo Gen-2 Spidev1.0
                      arfoll

                      I'd really recommend using libmraa instead of bothering doing all of this just to use Spi correctly... The hard work has been done for you already!

                      • 8. Re: Galileo Gen-2 Spidev1.0
                        sdssly

                        For the PIN12 MISO  direction config: echo low > /sys/class/gpio/gpio42/direction || echo "Failed to set gpio42 low" 

                         

                        Since it is a master input pin, it seems that the GPIO42 should be high