Jump to content

Fast GPIO access


sgjava

Recommended Posts

After working with sysfs and libgpiod as cross platform solutions I was wondering if there was a faster way using /dev/mem or mmio? I know this gets more bare metal and SBC specific, but for some things you may want absolute speed. https://opensource.com/life/16/4/bulldog-gpio-library for instance claims 1 MHz GPIO writes in Java. However it only supports 3 SBCs as you can see from https://github.com/SilverThings/bulldog. Is there a more generic way to do this and not lose performance? Using my generated JNA wrappers for libgpiod I get about 2K writes per second. In Python I think it's about 70K using libgpiod Python bindings. I realize you may not always need 1 MHz GPIO writes, but it would be neat to offer this in a more generic way.

Link to comment
Share on other sites

OK, so no answers :) Well as usual I pressed on. My first mistake was using JNA generation (but it was easy), so I researched JNI. Well JNI is very cumbersome to do by hand, so I looked for a JNI code generator and found one call HawtJNI. Of course it wouldn't work with Java 11 which is the Java LTS version, so I created a fork. Use the JDK11 branch if you want to play with it because I don't know if the PR will be accepted. I started wrapping c-periphery since it now supports the new /dev/gpiochip way of accessing the GPIO chips. I ran a performance test (I validated on a scope) and I'm getting ~235 KHz on a v1 Nano Pi Duo! That's over 500K writes per second compared to 2K using JNA and libgpiod. Even python-periphery yields ~37 KHz which is a pure Python version.

 

Any ways exciting news for bit bangers of the world or anyone needing high performance GPIO. Once I have the GPIO code working I'll post on my Github site and announce. Since Bulldog only supports three boards this is good news for Armbian folks with a wider array of supported boards. I still need to test ARMv8 64 bit.

Link to comment
Share on other sites

https://en.wikipedia.org/wiki/Bit_banging where you write you own protocols in software without the need for I2C, UART, SPI, etc. https://calcium3000.wordpress.com/2016/08/19/i2c-bit-banging-tutorial-part-i Thus with two GPIO pins I can simulate I2C. With the slower speeds, not so much. You can also do square wave 1 bit PCM sound too. I'm going to date myself, but I was doing this on a C64 in the 1980s. https://github.com/sgjava/garage/blob/master/commodore/c64/digisound/src/digisnd.asm Then you only need a simple piezoelectric speaker.

 

There are probably a bunch of other uses, but this should give you an idea. Just the fact that I'm half the speed of Bulldog with many more platforms is a good thing. I was shooting for a generic high performance solution instead of coding directly to the GPIO chip like Bulldog.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines