element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
RoadTests & Reviews
  • Products
  • More
RoadTests & Reviews
Blog Maaxboard roadtest: direct GPIO
  • Blog
  • RoadTest Forum
  • Documents
  • Events
  • RoadTests
  • Reviews
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Related
Recommended

Maaxboard roadtest: direct GPIO

pmansvelder
pmansvelder
20 Apr 2020

GPIO

GPIO pins are 'general purpose input/output pins', configurable as both input and outputs where needed. These pins form the most common interface to hook up your own hardware.

According to the hardware description, the maaxboard has no less than 5 x 32 = 160 GPIO pins. This is also visible to the linux system, when you look at the /sys/class/gpio directory:

# ls -lia /sys/class/gpio/

totaal 0

1946 drwxr-xr-x  2 root root    0 apr 20 16:53 .

  10 drwxr-xr-x 64 root root    0 apr 20 16:53 ..

1947 --w-------  1 root root 4096 apr 20 16:46 export

6176 lrwxrwxrwx  1 root root    0 apr 20 16:53 gpiochip0 -> ../../devices/platform/30200000.gpio/gpio/gpiochip0

7192 lrwxrwxrwx  1 root root    0 apr 20 16:53 gpiochip128 -> ../../devices/platform/30240000.gpio/gpio/gpiochip128

6430 lrwxrwxrwx  1 root root    0 apr 20 16:53 gpiochip32 -> ../../devices/platform/30210000.gpio/gpio/gpiochip32

6684 lrwxrwxrwx  1 root root    0 apr 20 16:53 gpiochip64 -> ../../devices/platform/30220000.gpio/gpio/gpiochip64

6938 lrwxrwxrwx  1 root root    0 apr 20 16:53 gpiochip96 -> ../../devices/platform/30230000.gpio/gpio/gpiochip96

1948 --w-------  1 root root 4096 apr 20 16:46 unexport

Each chip is shown by its base address, so gpiochip0 is for gpio's 9 through 31, gpiochip32 for 32 to 63, etc.

As far as I could tell, only 2 chips are connected to the GPIO header with a couple of pins, these are named 'GPIO1' (for gpiochip0) and 'GPIO3' (for gpiochip64).

 

From the avnet hardware manual, I deducted the GPIO pin addressing; although the general layout of the 40-pin GPIO header follows the raspberry pi numbering, the internal numbers are quite different:

 

GPIO PinPin nameInternal GPIO numberGPIO chip/sys/class/gpio/gpio<xx>Test result as outputTest result as input
7GPIO3_IO1616380OKOK
11GPIO3_IO1717381OKOK
13GPIO3_IO088372NOT OKNOT OK
15GPIO3_IO099373NOT OKNOT OK
19GPIO3_IO066370reported as busyreported as busy
21GPIO3_IO077371reported as busyreported as busy
22GPIO3_IO1515379OKOK
23GPIO3_IO000364NOT OKNOT OK
24GPIO3_IO011365NOT OKNOT OK
26GPIO3_IO022366OKOK
29GPIO3_IO055369OKOK
31GPIO3_IO1010374OKOK
32GPIO1_IO1515115OKOK
33GPIO1_IO1313113OKOK
36GPIO1_IO03313OKOK
37GPIO3_IO1111375OKOK

 

I tested the GPIO bus #1 with the standard way of addressing gpios through the /sys/class interface:

  • export the pin number to /sys/class/gpio/export
  • now the gpio pin becomes available under /sys/class/gpio/gpio + pin number
  • make the gpio pin an output by writing 'out' to /sys/class/gpio/gpioXX/direction
  • now you can write values of 1 or 0 into '/sys/class/gpio/gpioXX/value
  • clear the pin again by writing the pin number to /sys/class/gpio/unexport

Example for pin 13:

# ls -1 --color /sys/class/gpio

export

gpiochip0

gpiochip128

gpiochip32

gpiochip64

gpiochip96

unexport

# echo 13 > /sys/class/gpio/export

# ls -1 --color /sys/class/gpio

export

gpio13

gpiochip0

gpiochip128

gpiochip32

gpiochip64

gpiochip96

unexport

# echo out > /sys/class/gpio/gpio13/direction

# echo 0 > /sys/class/gpio/gpio13/value

# echo 1 > /sys/class/gpio/gpio13/value

# echo 13 > /sys/class/gpio/unexport

# ls -1 --color /sys/class/gpio

export

gpiochip0

gpiochip128

gpiochip32

gpiochip64

gpiochip96

unexport

In this way, I tested all three GPIO pins of the GPIO1 controller, and they all worked as expected.

The GPIO3 pins could also be used, by calculating the gpio number as follows:

gpio_number = (chip_number -1) * 32 + gpio port

For example, GPIO port 11 on gpio3 is: (3-1)*32 +11 = 75.

To test the GPIO as in input, the procedure is similar:

  • export the pin number to /sys/class/gpio/export
  • now the gpio pin becomes available under /sys/class/gpio/gpio + pin number
  • make the gpio pin an input by writing 'in' to /sys/class/gpio/gpioXX/direction
  • now you can read the value from '/sys/class/gpio/gpioXX/value, this should be an 0 or an 1, depending how the input is connected.
  • To test whether it functions, connect the input either to GND (it should read 0) or to 3.3V (it should read 1).
  • clear the pin again by writing the pin number to /sys/class/gpio/unexport

Not all GPIO pins were accessible this way, this is probably due to some drivers interfering.

 

So, except for these 6 pins (13, 15, 19, 21, 23 and 24), there are 10 GPIO pins usable from the 40-pin header, both as outputs (to drive LEDs or relays) and inputs. According to the hardware manual, there are 2 more pins available on the camera connector, but I lacked the cabling to be able to test those.

Unlike the raspberry pi, the 'other' GPIO pins, which are all mapped to other functions like i2c and uarts and such, cannot be easily identified in this way; it would be nice to be able to use those if you do not need them for other things. I counted 12 of them, so in theory you could have 22 to 28 GPIO pins available, if both the unusable pins and the 'mapped' pins could be configured.

Conclusion

With the exception of the 6 mysterious pins and the 12 'mapped' pins, all the GPIO pins worked as I expected, and had fun figuring out how to address them and test them. In practice, I hardly use more than a few pins anyway, and prefer to use i2c or other means if I really need more pins. So for me, the maaxboard's GPIO capability is perfectly acceptable.

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2023 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube