1 2 Previous Next 20 Replies Latest reply on Nov 1, 2015 2:51 AM by xbolshe

    what's the max speed of galileo SPI ?

    六笔的阳

      what's the max speed of galileo SPI ?

        • 1. Re: what's the max speed of galileo SPI ?
          BillyCW

          Based on some of my testing with a logic analyzer, the speed really depends on how you make use of the SPI interface.

           

          From my timing measurements, each time a chip select (CS) pin is cycled (low and high), this requires 10 ms. Although the actual clock rate is much higher, the bottleneck is not the clock line itself but the chip select pin. The less often you need to cycle the chip select pin, the higher the data rate.

           

          The SPI interface for the Galileo board has an internal buffer of 4096 bytes which means you can hold down the CS pin and clock in up to 4096 bytes before having to read the buffer off to something else. Under this scenario, it takes about 11.5 ms to fill the 4096 byte buffer.

           

          To transfer a large block of data via SPI using the above method, you should use the following function:

          SPI.transferBuffer( pInputByteArray, pOutputByteArray, numberOfBytes )

           

          Where pInputByteArray/pOutputByteArray is a pointer to a byte array and numberOfBytes is a unsigned integer from 1 to 4096.

           

          In my tests, it takes 0.8 ms to copy 4096 bytes off the SPI buffer and onto some other internal read buffer. So for example, if you were to read 40960 bytes, it takes 130 ms. This works out to be about 307 kB/s or 315000 bytes per second using SPI_CLOCK_DIV2.

           

          In contrast, if you had to cycle your CS pin after reading each byte, it takes about 7 seconds to read 1024 bytes.

           

          In summary, if you can operate by minimizing the cycling the CS pin, you will be able to hit a theoretical max of close to 333 kB/s with a clock divider of 2 for the SPI clock divider setting.

          • 2. Re: what's the max speed of galileo SPI ?
            Intel_Jesus

            Greetings,

             

            Take a look at the Datasheet found here: https://communities.intel.com/docs/DOC-21835. The SPI speed is mentioned in the first page:

             

            ·         SPI

            o   Defaults to 4MHz to support Arduino Uno shields. Programmable up to 25MHz.

             

            Regards,

            Intel_Jesus

            • 3. Re: what's the max speed of galileo SPI ?
              ClDoppler

              You can use Fast Modes of Pin 2 or 3 to increas CS Speed.

              More info about fast mode can be found here:

               

              https://communities.intel.com/thread/45267

              • 4. Re: what's the max speed of galileo SPI ?
                BillyCW

                Thanks for the suggestion on the fast GPIO mode.

                 

                I've done some additional tests with the logic analyzer.

                 

                I was able to generate the 2.93 MHz waveform using:

                 

                void loop()
                {
                     fastGpioDigitalWriteDestructive(0x0);
                     fastGpioDigitalWriteDestructive(0xff);
                }
                

                 

                Alternatively, I was also able to generate the 683 kHz waveform using:

                 

                void loop()
                {
                     fastGpioDigitalWrite(GPIO_FAST_IO3,LOW);
                     fastGpioDigitalWrite(GPIO_FAST_IO3,HIGH);
                }
                

                 

                The intent on the above two tests is to see if I can use it as my SPI chip select. As such, I did two additional tests using the following SPI settings:

                 

                void setup()
                {
                     pinMode(3, OUTPUT_FAST);
                
                     SPI.begin();
                     SPI.setBitOrder(MSBFIRST);
                     SPI.setClockDivider(SPI_CLOCK_DIV2);
                     SPI.setDataMode(SPI_MODE0);
                }
                

                 

                The two test is as follows:

                 

                void loop()
                {
                     fastGpioDigitalWriteDestructive(0x0);
                     SPI.transfer(0x00);
                     fastGpioDigitalWriteDestructive(0xff);
                }
                

                 

                and

                 

                void loop()
                {
                     fastGpioDigitalWrite(GPIO_FAST_IO3,0x0);
                     SPI.transfer(0x00);
                     fastGpioDigitalWrite(GPIO_FAST_IO3,HIGH);
                }
                

                 

                Once I added the SPI.transfer(0x00) line, I noticed that there is a delay of 0.54 and 0.56 ms between Pin3 going from LOW and back to HIGH. As such, it suggests the delay is not due to the slow GPIO being used as a chip select but rather the SPI.transfer() and SPI.transferBuffer() for that matter.

                 

                I did two other follow on test to verify that it is indeed the SPI.transfer() and SPI.transferBuffer() functions that cause the delay  by using:

                 

                void loop()
                {
                     SPI.transfer(0x00);
                }
                

                 

                and

                 

                void loop()
                {
                     SPI.transferBuffer(theBuffer, NULL, 1); // where theBuffer consists of: byte theBuffer[1]; theBuffer[0] = 0;
                }
                

                 

                The result of the above two tests resulted in a 0.54 and 0.55 ms delay between each byte transfer on the SPI clock line. This pretty much confirms that the vast majority of the delay (~0.54 ms) is caused by the SPI.transfer() and SPI.transferBuffer() functions.

                 

                Based on the timing diagram from my logic analyzer, from the time I pull the chip select pin down using Fast GPIO to the first clock of the SPI, it takes about 30 ms. From the last clock of the SPI transfer to the chip select pin going back up, there is an additional 25 ms.

                 

                Does anyone know if there is a way to reduce the delay caused by the SPI.transfer()?

                • 5. Re: what's the max speed of galileo SPI ?
                  dferyance

                  Your findings are consistent with some less-scientific speed tests I did. Always use transferBuffer instead of transfer. In some Arduino code I have ported, I changed it to always buffer up the data first to have to make a few transferBuffer calls. It can take significant modifications but it makes all the difference for speed.

                   

                  Instead of using the fast-io to toggle the CS pin, try using the SPI driver. The SPI driver can do this even though the Arduino samples don't use it. By default, the SPI driver will use GPIO-10 for the CS line. The mux just has to be configured right and it should on IO-10. I expect this is faster -- but I haven't timed it. I use the driver CS support in my code to handle multi-threading scenarios rather than for speed.

                   

                  I have done a lot of digging into the SPI support. The transferBuffer call sends the request to a Linux driver to handle the SPI data. This request is placed in a queue where a kernel thread reads from it and streams it out. I expect that most of the overhead is OS overhead. I don't know of a way to avoid this without resorting to writing your code in a kernel module. At least buffering the data and using the driver CS support can keep this overhead to a minimum.

                  • 6. Re: what's the max speed of galileo SPI ?
                    ClDoppler

                    Just for Completeness, I did some measurements with my scope using pinMode(OUTPUT_FAST) and fastGpioDigitalWrite():

                    void loop() {
                      register int x = HIGH;
                      fastGpioDigitalWrite(GPIO_FAST_IO3, !x);
                      SPI.transfer(0b010100000);
                      fastGpioDigitalWrite(GPIO_FAST_IO3, x);
                    
                    }
                    
                    

                     

                    As I figured out, the Major delay is caused by SPI.tranfer() whereas GPIOs are already pretty fast this way. Delay is about 118us between SS and MOSI/SCK

                    SPI_SSdelay.bmp

                    Can this be a Problem for an SPI device? Is there a specification for the delay between SS and MOSI/SCK start?

                    • 7. Re: what's the max speed of galileo SPI ?
                      ClDoppler

                      Did I get it wrong? but I thougth, PIN 10 is just for SS for incoming SPI traffic - so as the Arduino is the SLAVE, which is not supported by SPI lib. Thats why I thought just to set it as Ouput so there cant be any conflict.

                      • 8. Re: Re: what's the max speed of galileo SPI ?
                        John_Brady

                        Hello Guys,

                         

                        I'm trying to get the 2.7 inch e-ink display from Pervasive displays working the Galileo. We used the demo Arduino code available from their Wiki page: http://www.seeedstudio.com/wiki/Small_e-Paper_Shield

                         

                        The performance of the display is poor as it takes very long to refresh.We tried using using transferBuffer() as suggested above but if did not significantly improve.

                         

                        We would be grateful if somebody could explain the underlying issue here. Why is there a long delay between each SPI transfer for the Galileo SPI driver? Could anybody suggest a suitable workaround or solution please? Is the reason because the "arduino sketch" on a galileo runs in user mode with a linux kernel,  so I/O incurs significant overhead? . In the SPI library for Galileo, the core of transfer function is actually calling ioctl(…) of the kernel module.

                         

                        Alternatively we came across this post: https://communities.intel.com/message/231542#231542

                         

                        This project uses the same display from Pervasive displays but usb instead? Could anybody comment on the performance of the display using this method? Can you use Ardunio sketches on the yocto image?

                         

                        Many thanks

                        John

                        • 9. Re: what's the max speed of galileo SPI ?
                          John_Brady

                          Hi Guys,

                           

                          Any input on the above would be welcome

                           

                          Thanks

                          John

                          • 10. Re: what's the max speed of galileo SPI ?
                            SpiderKenny
                            Why is there a long delay between each SPI transfer for the Galileo SPI driver?


                            I suspect that the SPI Arduino library is having to configure the MUX pins for every transfer.

                            I successfully used SPI from User-mode in Linux on Galileo to drive my LED Matrix. I kept pushing the speed up so far that the skew rate (rise time) of the pins was becoming the issue, not the speed of the SPI. It was too fast for either my 100 Mhz scope or my Logic analyser to read it properly, but I suspect it was in excess of 25 Mhz, with as little as 200 uS between transfers. (0.2 milliseconds)

                            • 11. Re: what's the max speed of galileo SPI ?
                              John_Brady

                              Hi SpiderKenny,

                               

                              That's interesting, nicely done!

                               

                              A bit of an open question, but in your opinion do you think that it would be possible to use SPI from User-mode in Linux on Galileo to power the this e-ink display. I have it working using SPI in an arduino sketch but it too slow to refresh.

                               

                              Buy Small e-paper Shield [SLD00200P] | Seeedstudio

                               

                              2.7" E-INK bistable Display | Raspberry Pi | Raspbian OS | SPI + I2C + PWM - YouTube

                               

                              Would you know of any online examples of how to do this?

                               

                              Thanks

                              John

                              • 12. Re: what's the max speed of galileo SPI ?
                                SpiderKenny

                                I'd cautiously say yes :-)

                                However it's just my gut feeling from looking at the display spec.

                                I think it could work, but I don't have any links for you I'm afraid.

                                • 13. Re: what's the max speed of galileo SPI ?
                                  John_Brady

                                  No problem, thanks! Will you be posting instructions on your blog for your screen?

                                  • 14. Re: what's the max speed of galileo SPI ?
                                    SpiderKenny

                                    Yes - I will :-) I hope to do it quite soon.

                                    1 2 Previous Next