OpenWrt Forum Archive

Topic: SPI over GPIO speed

The content of this topic has been archived on 27 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi,

I managed to connect a ILI9341 TFT to a openwrt router based on AR9331 chip (400 MHz), THe commands and video data is sent over emulated GPIO SPI but I the refresh rate is not that great.
I did some measurements and the spi-gpio speed does not exceed 1 MHz. For tests I also tried to setup a SPI device using spi-gpio-custom driver and send some random stuff and I couldn't get over 1 MHz barrier.
Is it possible to push the speed up to at least 5 MHz ?

I found this comment in the spi-gpio.c source code but I can't figure out how exactly to take advantage of what it is saying:

 /*
 57  * Because the overhead of going through four GPIO procedure calls
 58  * per transferred bit can make performance a problem, this code
 59  * is set up so that you can use it in either of two ways:
 60  *
 61  *   - The slow generic way:  set up platform_data to hold the GPIO
 62  *     numbers used for MISO/MOSI/SCK, and issue procedure calls for
 63  *     each of them.  This driver can handle several such busses.
 64  *
 65  *   - The quicker inlined way:  only helps with platform GPIO code
 66  *     that inlines operations for constant GPIOs.  This can give
 67  *     you tight (fast!) inner loops, but each such bus needs a
 68  *     new driver.  You'll define a new C file, with Makefile and
 69  *     Kconfig support; the C code can be a total of six lines:
 70  *
 71  *              #define DRIVER_NAME     "myboard_spi2"
 72  *              #define SPI_MISO_GPIO   119
 73  *              #define SPI_MOSI_GPIO   120
 74  *              #define SPI_SCK_GPIO    121
 75  *              #define SPI_N_CHIPSEL   4
 76  *              #include "spi-gpio.c"
 77  */

Under the second method, the kernel bit-banging routine won't need to look up and manipulate the pin numbers to use before and during every transfer, because they will be hard-coded and compiled into the core code.  I doubt you'll get a 5x improvement but it should be faster.

I would think it would work to just put the defines in the top of spi-gpio.c and recompile but then it is less obvious what you did than the suggested method of using another file to make basically a custom version for your hardware without modifying the default version.

(Last edited by mk24 on 21 Feb 2015, 00:16)

I did some modifications: hardcoded the SPI pins in defines like described by mk24 and modified the setsck setmosi getmiso functions from spi-gpio.c to write directly to gpio registers.
This got the SPI speed up to 4 - 3.5 MHz which is not bad at all.
One more question ... at the moment my router has a lot of kernel and user space modules that I will not use(like usb core and other usb stuff, ethernet interface (I need only wifi interface) and some bunch of user space apps). Do you think that by removing some of these features may prevent preemption when I need to send larger amounts of data, for example video buffers ?

bogdanul2003,
   Depending on what you are trying to accomplish, you may be starting with the wrong equipment. Used Android-based smartphones (which can be had for ~$20) already have very robust video controllers, and wifi cards; and significantly more storage than any wifi router..
   It'd be great, if you are just using this as a lab experiment, or a learning tool; but essentially, you are trying to turn a tractor into a race car.

V/r,
Conjur

Conjur,
   What Android-based board for 20$ are you talking about ?

Hi Bogdan! What router and display model are you using?
PS I have successfully connected my 3.2 TFT with touch XPT2046 to rbp2 and next is router tft project smile

The discussion might have continued from here.