We're no longer updating This wiki!!

Rootless GPIO access: /dev/gpiomem

/dev/gpiomem provides user with root-free access to the GPIO registers. Opening /dev/gpiomem device file and calling mmap() function will map the GPIO registers' memory map area to the user's pointer.
This driver is added in below's Ubuntu kernel versions:

  • ODROID-C2: 3.14.79-105 kernel version or later
  • ODROID-C0/C1+: 3.10.104-182 kernel version or later
  • ODROID-XU4: 4.9.x kernel version or later

How to enable gpiomem driver

/dev/gpiomem driver is included as module by default. In order to use gpiomem driver, it is necessary to configure account access permission.

$ sudo addgroup gpio
$ sudo usermod -a -G gpio odroid    
$ cat /etc/udev/rules.d/90-gpiomem.rules 
  • ODROID-C0/C1+/C2
SUBSYSTEM=="meson-gpiomem", GROUP="gpio", MODE="0660"
  • ODROID-XU4
SUBSYSTEM=="exynos-gpiomem", GROUP="gpio", MODE="0660"

Example

Hardkernel's wiringPi library which is for GPIO control uses /dev/gpiomem device file for rootless gpio control. Usage is very simple. Just open /dev/gpiomem device file instead of /dev/mem.

  // Open the master /dev/memory device
  if (access("/dev/gpiomem",0) == 0) {
    if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
      return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/gpiomem: %s\n", strerror (errno)) ;
  }
  else {
    if (geteuid () != 0)
      (void)wiringPiFailure (WPI_FATAL, "wiringPiSetup: Must be root. (Did you forget sudo?)\n") ;

    if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
      return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/mem: %s\n", strerror (errno)) ;
  }
gpiomem.txt · Last modified: 2017/02/03 10:44 by brian.kim
CC Attribution-Share Alike 3.0 Unported
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0