iMX233-OLinuXino GPIOs FASTER and FASTER :)


In my previous post I experimented with GPIOs trying to see how fast they could be changed and had in my TODO list to access them via /dev/mem directly writing to the registers, David Whittaker made this before me 🙂 :

He made this wonderful tool gpio-mmap.h where he define several useful functions:

gpio_map(); // this function should be called to initialize and map the GPIOs to the /dev/mem

gpio_output( bank, pin); // initialize GPIO as output you can see which GPIO correspond to bank/pin in IMX233 user manual, I prepare cross reference for all GPIOs which will post soon here on the blog

GPIO_WRITE_PIN(pin,value); //this writes to the GPIO pin#

the quick code I did you try gpio-mmap.h tool was:

#include “gpio-mmap.h”

int main() {
gpio_output(2,1); //bank 2 bit 1 = GPIO65 the LED on board
while (1) {

the oscolloscope connected to the GREEN LED show nice square with 175 nS period, i.e. the direct memory register write can achieve as high as 5.7 MHz wow 🙂

note that this code was running without other codes to interrupt it, in Linux which is multitasking OS you can run many processes, for instance if I add in background the led_blink script from the previous blog post, I can see with the oscilloscope LED glitch on ever second when the scrip toggle the LED, i.e. now I have 5.7Mhz frequency distrubed from time to time with the 1Hz led_blink script, so the more processed you run on iMX233 the less determinant will be this frequency and will slow down, this is like on your desktop when you run video for instance and start several other tasks like opening open office or copy some big file on the disk the video may freeze for a second when the video buffer goes empty and other tasks keep the CPU busy as this moment.

Nevermind gpio-mmap.h is one very useful tool, now we can implement software SPI with bit-banging as SPI is broken in imx233 kernel 2.6.35 and 5Mhz is pretty decent clock speed for most of the tasks, so we can now make some good code examples for our SPI UEXT modules.

You can download gpio-mmap.h source from GitHub:

13 Comments (+add yours?)

  1. David Whittaker
    Sep 11, 2012 @ 16:45:39

    I already have a handy cross reference for all gpio pins:

    Just look at the gpio columns. Red means you might break something else if you use it (usb, debug UART), and blue means it the physical pin is used in multiple places. To get the bank/pin numbers from the gpio number, divide by 32. The integer part is the bank, and the remainder is the pin. I.e. 65/32 = 2 remainder 1 — bank 2, pin 1.


  2. Kean
    Sep 19, 2012 @ 18:31:31

    Using this mmap GPIO code I managed software SPI at over 3MHz.
    Great stuff & very easy.


  3. Adem
    Sep 23, 2012 @ 12:00:41

    I want to output or input data from PIN9-PIN17(8bit) from olinuxino-maxi in gcc .With not SET or CLR pins command.How can i do that.


  4. the_real_maniac
    Sep 23, 2012 @ 12:00:42

    You could try a software spi using a simple char device and high resolution timer.
    A hr_timer has a resolution of 1ns which means it can give you a simple delay of 100ns or 10Mhz SPI (GPIO toggle) theoretically; it has to be tested though 🙂
    Check if you have hr_timer available with `cat /proc/timer_list` and see if you find a line “.resolution: 1 nsecs” 🙂 As i don’t have iMX233 i can’t test it. But i have a iMX287/283 around, if i have time and willingness I could write such kind of driver and test it , will see. I’m not sure there is a need of such driver , or is there ?


  5. Trackback: A13-OLinuXino playing with GPIOs « olimex
  6. Trackback: Implementing fast software SPI | Hacking Light
  7. Cougar
    Jan 01, 2014 @ 18:58:58

    Based on and references from this post I made _working_ Python(3) module for iMX233-OLinuXino GPIO. You can find it here:


  8. dnaura
    Aug 09, 2017 @ 16:44:08

    Can we imagine the same for A20 boards ? and with a python wrapper?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: