In my previous post https://olimex.wordpress.com/2012/09/07/imx233-olinuxino-working-with-gpios/ 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 🙂 : http://tech.groups.yahoo.com/group/olinuxino/message/2022
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_map();
gpio_output(2,1); //bank 2 bit 1 = GPIO65 the LED on board
while (1) {
GPIO_WRITE_PIN(65,1);
GPIO_WRITE_PIN(65,0);
}
}
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: https://github.com/OLIMEX/OLINUXINO/tree/master/SOFTWARE/iMX233/gpio-mmap.h
Sep 11, 2012 @ 16:45:39
I already have a handy cross reference for all gpio pins:
https://docs.google.com/spreadsheet/ccc?key=0AspkrcYcY5bWdFB6WC1xRlp5bFRjc1hwVnlQZDVmeUE
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.
Sep 11, 2012 @ 16:46:32
perfect! I’ll prepare one for MAXI too!
Dec 05, 2012 @ 03:28:04
Does this also work for A13-WIFI or can you please prepare it for A13-WIFI?
Sep 19, 2012 @ 18:31:31
Using this mmap GPIO code I managed software SPI at over 3MHz.
Great stuff & very easy.
Sep 20, 2012 @ 08:34:28
yes, we did same to interface MOD-LCD3310 via bit bang SPI and prepare some demos
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.
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 ?
Jan 01, 2014 @ 18:58:58
Based on https://pypi.python.org/pypi/iMX233_GPIO/0.1.0 and references from this post I made _working_ Python(3) module for iMX233-OLinuXino GPIO. You can find it here: https://github.com/droid4control/iMX233_GPIO
Jan 02, 2014 @ 10:44:20
How fast is it? Have you test test it…..
Jan 04, 2014 @ 01:08:56
I get around 11.5kHz. Not too fast but usable for LED blinking 😉
Aug 09, 2017 @ 16:44:08
Can we imagine the same for A20 boards ? and with a python wrapper?