I already blogged how to blink LED connected to OLinuXino GPIO through the shell script here https://olimex.wordpress.com/2012/04/23/blinking-led-with-linux-or-hello-world-with-imx233-olinuxino/
today I did experiement to see what is the fastest GPIO toggel I can achieve with this method and this code:
echo out > /sys/class/gpio/gpio0/direction
while [ 1 -eq 1 ]
echo 1 > /sys/class/gpio/gpio0/value
echo 0 > /sys/class/gpio/gpio0/value
makes nice 400Hz square wave on oscilloscope this means 1.25mS to set GPIO high and 1.25mS to set GPIO low.
Quite OK if you do some slow IO processes like switching ON OFF relays etc but slow if you want to do something faster, so I decided to see what will happend if I make same code in C.
For this purpose I decided to use the Green LED next to PWR jack which is connected to GPIO65:
char s_out = “out”;
char s_0 = “0”;
char s_1 = “1”;
//define GPIO65 as output
printf(“GPIO65 set as output\r\n”);
This code improved the speed significant now I can see 140 kHz on GPIO65 with 3.5 uS high and 3.5 uS low time.
Although about 350 times faster than shell script this still seems slow to me, there is another approach to access the GPIOs under Linux and this is through “/dev/mem” writing directly in memory and iMX233 registers.
So what would be the speed if we write directly to the memory/registers? There is nice documentation with about 50 pages explaining how to set GPIOs :) I may find a time during the weekend to read and try to implement it.