Information on using GPIO's on ARM Cortex A8

Discussion in 'Embedded Systems and Microcontrollers' started by dl324, Jun 21, 2016.

  1. dl324

    Thread Starter Distinguished Member

    Mar 30, 2015
    3,242
    619
    I've started experimenting with the $9 C.H.I.P. computer based on this processor and am looking for information regarding where to get libraries to access the GPIO's.

    The makers of CHIP (Next Thing Co), provided examples accessing the GPIO's from the shell using a sysfs interface. I'm looking for something more direct, hoping it will be faster. The fastest I can toggle the I/O's using the sysfs interface from C is about 2KHz and that won't be fast enough for the applications I have in mind.

    Thanks in advance for any replies.
     
  2. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,907
    2,165
    The ioctl interface is slow with all the abstraction layers from userland to kernel code and scheduling.. I haven't looked at the hardware details of the C.H.I.P. but with root access you should able to do direct register programming of GPIO similar to this.
    http://elinux.org/RPi_GPIO_Code_Samples#Direct_register_access

    With a Linux kernel module you can directly access memory mapped registers via the MMU with a ioremap instead of /dev/mem.
    Code (Text):
    1.  
    2. dev->iobase = GPIO_BASE; /* bcm iobase */
    3. /*
    4. * dev->mmio is a void pointer with 8bit pointer indexing,
    5. * we need 32bit indexing so mmio is casted to a (__iomem uint32_t*)
    6. * pointer for GPIO R/W operations
    7. */
    8. dev->mmio = ioremap(dev->iobase, SZ_16K);
    9. if (!dev->mmio) {
    10. dev_err(dev->class_dev, "invalid gpio io base address!\n");
    11. return -EINVAL;
    12. }
    13.  
    http://www.makelinux.net/ldd3/chp-9-sect-4

    https://bbs.nextthing.co/t/solved-gpio-direct-access/2971/3
    The details are here somewhere.
    https://github.com/NextThingCo/
     
    Last edited: Jun 22, 2016
  3. dl324

    Thread Starter Distinguished Member

    Mar 30, 2015
    3,242
    619
    Thanks for the info.

    It turns out that the GPIO's NTC "advertised" are on a separate chip that the processor communicates with over I2C, which makes them slow. If I use some of the IO's on the processor itself, they toggle at about 200kHz using the sysfs interface; that's sufficient for the projects I had in mind.
     
  4. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,907
    2,165
    Much better, 2KHz sounded very low even for the slowest direct processor ioctl based toggles.
     
Loading...