7 Replies Latest reply on Dec 17, 2014 9:32 AM by KurtE

    Fast GPIO Arduino board to logical IO pins on Breakout board?

    KurtE

      I know that I have asked similar questions as parts of other questions in different threads, but don't remember seeing any answers about is there any faster methods for updating the external GPIO addresses associated with the Arduino breakout board.

       

      Example the tristate pin (214)

      The Output Enable pins:

      static unsigned int outputen[] = {248,249,250,251,252,253,254,255,256,257,258,259,260,261,232,233,234,235,236,237};

       

      The External Pull ups

      static unsigned int pullup_map[] = {216,217,218,219,220,221,222,223,224,225,226,227,228,229,208,209,210,211,212,213};

       

      I am quite sure that can not be accessed through the PCI memory map.

       

      In the Arduino code base I see several different files with fast_gpio in their name including
      fast_gpio_pci.h(c) - This is the one used for the memory mapped access to actual pins in Edison module

      fast_gpio_nc.h(c) - ???? No reference to it in any other files

      fast_gpio_sc.h(c) - ??? No reference to these in any other files...

       

      Also in the case of the fast_gpio_pci.c - There is memory mapped access for reading/clearing/setting the value of the device.  Is there fast access to any other capabilities of these pins? (direction, edge, ...)

       

      Thanks

      Kurt

        • 1. Re: Fast GPIO Arduino board to logical IO pins on Breakout board?
          Intel_Peter

          Hello KurtE,

           

          We will investigate about this and we'll get back to you as soon as we get some information about it.

           

          Regards,

                      Pedro.

          • 2. Re: Fast GPIO Arduino board to logical IO pins on Breakout board?
            Intel_Peter

            Hello KurtE,

             

            We measured the IO speed with an Arduino test sketch, the resulting speed was 1.4 MHz.

            What speed are you trying to achieve?

             

            Regards,

                        Peter

            • 3. Re: Fast GPIO Arduino board to logical IO pins on Breakout board?
              KurtE

              Thanks Peter,

               

              Yes I have been able to do writes to an IO port through the memory mapped access in about that speed you mention, which is doing OK,

               

              But what I am trying to understand is can I make switching the state of the pins fast enough to support certain devices.  Probably the simplest of these is the old Ping sensor, where you switch the IO pin to Output, do a high pulse, switch back to input and wait for the ping device to generate a pulse back. Example:

              unsigned long ulDRStart, ulDeltaDr;
              unsigned long ulDeltaSum = 0;
              unsigned long ulCnt = 0;
              unsigned long DoPing(  mraa_gpio_context gpio) {
                  mraa_gpio_dir(gpio, MRAA_GPIO_OUT);
                  mraa_gpio_write(gpioDBG, HIGH);
                  mraa_gpio_write(gpio, HIGH);
                  usleep(STARTDELAY);
                  mraa_gpio_write(gpio, LOW);
                  mraa_gpio_write(gpioDBG, LOW);
              
                  ulDRStart = micros2();
                  mraa_gpio_dir(gpio, MRAA_GPIO_IN);
                  ulDeltaDr = micros2() - ulDRStart;
              
                  while (mraa_gpio_read(gpio) == LOW)
                      ; //pthread_yield();
                  time_s = micros2();
                  mraa_gpio_write(gpioDBG, HIGH);
              
                  while (mraa_gpio_read(gpio) == HIGH)
                      ; //pthread_yield();
                  time_e = micros2();
                  mraa_gpio_write(gpioDBG, LOW);
              
                  ulDeltaSum += ulDeltaDr;
                  ulCnt++;
                  cout << "dt dir: " << ulDeltaDr << "(" << (ulDeltaSum/ulCnt) <<" ): ";
              
                  return time_e - time_s;
              }
              
              

               

              The critical timing was in the call mraa_gpio_dir(gpio, GPIO_IN);

              I have made some pretty good progress on speeding things up.  Example in MRAA, started off with a time of about: 2.7ms, to now somewhere near: 1.1ms

              More details and timing shown in the thread: https://communities.intel.com/message/267710?tstart=0#267710

              The speed ups, are because I have cached objects with file handles to, the different objects needed to change from Output to Input.  So it basically does:

              a) write 0 to tristate (214)  - Writes are done by seek back to 0 and then write

              b) write 0 to OUTPUTEN (250) ...

              c) write to direction of 128 (actual IO pin)

              d) write 1 to tristate (214) -

               

              I may have mistyped or missed a step here, but all of these interactions are through the file system.  So what I was wondering is are there faster access like memory mapped for those IOs (214, 250), that are controlled over I2C.

               

              Hope that makes sense

               

              thanks again

              • 4. Re: Fast GPIO Arduino board to logical IO pins on Breakout board?
                Intel_Peter

                Hello KurtE,

                 

                The I2C speed by default is on Fast mode (with data rates up to 400 KHz) if the sensor can communicate at a frequency of 400 KHz or more then it should work, if the sensor needs slower or faster speeds you need to modify and rebuild the kernel. Take a look at this post Changing the I2C Frequency, Zahid provided details on how to configure the kernel. 90 Hz is the maximum toggling on a pin from Input/Output.

                 

                Regards,

                            Peter.

                • 5. Re: Fast GPIO Arduino board to logical IO pins on Breakout board?
                  KurtE

                  Thanks, I will for sure keep that post book marked.

                   

                  Sorry I am probably not asking this right.  But on the Arduino breakout board there are several devices that are shown in figure 1 of the Edison kit for Arduino Hardware guide, that are controlled by I2C.  These hardware components are used as part of each logical IO pin.  Example (Port Expander), used to control the level shifters, muxs...  These currently are all controlled through file system calls mainly into: /sys/class/gpio and /sys/kernel/debug/...

                   

                  As I mentioned above to change a logical Arduino pin from Input to Output, or to Enable Pull UP/Down, ... You have to set/clear several of these external physical objects.

                  Example the logical object: /sys/class/gpio/gpio214 (tristate) has to be cleared, other stuff down then set back to 1... These are all through calls to the file system.  It is my strong guess, is that than some device handler handles this file IO, which in turn generates the appropriate I2C messages.  So the real question is, is there a faster way to manipulate these.  Like: memory mapped, or direct calls to output the appropriate stuff on the I2C buffer.

                   

                  Again sorry if I am not being overly clear here. 

                  • 6. Re: Fast GPIO Arduino board to logical IO pins on Breakout board?
                    Intel_Peter

                    Hello KurtE,

                     

                    I'm sorry KurtE, I did some research, and apparently there is no faster way to manipulate the GPIO.

                     

                    Regards,

                                Peter.

                    • 7. Re: Fast GPIO Arduino board to logical IO pins on Breakout board?
                      KurtE

                      Thanks,

                       

                      wish list - Not sure how much faster it would be to either document an I2C interface to interact or a memory mapped call....

                       

                      But until then....