# GPIO setup on x86



## Phishfry (May 6, 2016)

Howdy, I am wanting to learn GPIO's on FreeBSD and I need advice on hardware.
I have 3 platforms that have advertised GPIO's for I/O use. MinnowboardMax Turbot, Advantech PCM9362 and Nexcom VTC1000. None seem to have a working GPIO found.
I have searched the forum here and looked at the docs here.
https://wiki.freebsd.org/FreeBSD/GPIO
But I need the basic primer.
Do all GPIO's just work or are only some supported? I looked through my dmesg.boot log for any GPIO devices and see none and no directories in the dev/gpio area. So `gpioctl -lv` does nothing.

I tried `kldload gpiobus` and `kldload gpioc` with no results.

I also used this page to compile in gpio:
https://www.freebsd.org/cgi/man.cgi?query=gpio&sektion=4

Looking at this line on the wiki I think I may have picked three non-supported models?
*on attaching HW driver should add gpioc and gpiobus as its children.*


Thanks for any advice.


----------



## Phishfry (May 9, 2016)

I decided to stick with the Beaglebone Black for GPIO. It will do all I need.


----------



## Phishfry (May 13, 2016)

I have LED's  blinking and relays turning on test lights and I couldn't be happier.
How do I get the GPIO pin positions to remain constant through reboots?
Are the default pin positions located in the Flat Device Tree Overlay or am I stuck with the default postition?(0 or 1) Or maybe I have to set them via a startup script? I noticed that GPIO's fire up early in the boot process.

**edit I do see what I need in the board dts file.


----------



## j4ck (Sep 8, 2016)

Hi
I'm trying to work with gpio(4) but GPIO devices are not listed in dev directory. I compiled kernel with following the configuration:

`device          gpio`

I must mention that I also tried to compile kernel with following configuration:

`device          gpio
device          gpioc
device          gpioiic
device        gpioled`

But I get the following error: 

`config: Error: device "gpioc" is unknown
config: 1 errors
*** [buildkernel] Error code 1

make[1]: stopped in /usr/src
1 error

make[1]: stopped in /usr/src
*** [buildkernel] Error code 2

make: stopped in /usr/src
1 error

make: stopped in /usr/src`

I removed `gpioc` from configuration file but I get the following error:

`linking kernel.debug
gpioiic.o:(.data+0x108): undefined reference to `iicbb_driver'
gpioiic.o:(.data+0x110): undefined reference to `iicbb_devclass'
gpioiic.o:(.rodata+0x30): undefined reference to `iicbb_callback_desc'
gpioiic.o:(.rodata+0x40): undefined reference to `iicbb_setsda_desc'
gpioiic.o:(.rodata+0x50): undefined reference to `iicbb_setscl_desc'
gpioiic.o:(.rodata+0x60): undefined reference to `iicbb_getsda_desc'
gpioiic.o:(.rodata+0x70): undefined reference to `iicbb_getscl_desc'
gpioiic.o:(.rodata+0x80): undefined reference to `iicbb_reset_desc'
*** [kernel.debug] Error code 1

make[2]: stopped in /usr/obj/usr/src/sys/GENERIC
1 error

make[2]: stopped in /usr/obj/usr/src/sys/GENERIC
*** [buildkernel] Error code 2

make[1]: stopped in /usr/src
1 error

make[1]: stopped in /usr/src
*** [buildkernel] Error code 2

make: stopped in /usr/src
1 error

make: stopped in /usr/src`

More information:

`root@FBSD101:~ # uname -a
FreeBSD FBSD101 10.1-RELEASE FreeBSD 10.1-RELEASE #1`

Any suggestions?


----------



## Phishfry (Sep 8, 2016)

Have you tried to `kldload` the modules?

You should use a up to date FreeBSD version as GPIO is a Work in Progress.


----------



## Phishfry (Sep 8, 2016)

If you read this thread you will note that GPIO is not supported on X86/AMD64 except for 2 firewall appliances with patches available.

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=207405
https://people.freebsd.org/~gonzo/patches/soekris-gpio.diff

What platform are you trying to use? I suggest any ARM board with a FreeBSD image.


----------



## ronaldlees (Sep 9, 2016)

Phishfry said:


> If you read this thread you will note that GPIO is not supported on X86/AMD64 except for 2 firewall appliances with patches available.
> 
> https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=207405
> https://people.freebsd.org/~gonzo/patches/soekris-gpio.diff
> ...



It does seem like he's working with the i386/AMD64 version.  For doing GPIO from an AMD64, I found a nifty little_ USB-to-GPIO_ board for about 15 crackers.  It has about a dozen regular GPIO, I2C, SPI, and a UART on it.  I can blink lights already, but am still working on the i2C stuff.


----------



## Phishfry (Sep 10, 2016)

ronaldlees said:


> I found a nifty little_ USB-to-GPIO_ board


Are you able to control pins with `gpioctl`? What driver is it using?
Can you post a link to the device please.


----------



## ronaldlees (Sep 10, 2016)

Phishfry said:


> Are you able to control pins with `gpioctl`? What driver is it using?
> Can you post a link to the device please.



Not so far.   I've been using the HK supplied software, which AFAIK does not incorporate gpioctl.  To be truthful, I haven't done much with the device yet, but bought it because I want to have at least one x86 arch computer in my nRF24 net (which needs SPI for control).   I don't think I'm supposed to put direct links on this forum, but it's the HardKernel USB-GPIO unit.  Really cheap, but I don't yet know how good     There are some posts on their forum about it.

The software uses the standard USB driver of the OS, so is very portable (thru libusb).  My tinkering thus far has been on Linux tho :-(


----------



## Juha Nurmela (Sep 10, 2016)

The VGA connector suddenly became a very convenient I2C port, with the "new" graphics systems. A drawback is that you must poll everything, but with one 8574 collecting eight /INTs, it's not bad, for some definition of bad.

Juha


----------



## Phishfry (Sep 10, 2016)

Does your USB to GPIO board use a PIC18F45K50? I think I found it on HardKernel site.


----------



## ronaldlees (Sep 10, 2016)

Phishfry said:


> Does your USB to GPIO board use a PIC18F45K50? I think I found it on HardKernel site.



Yes, that's the chip on the board.


----------



## ronaldlees (Sep 10, 2016)

Some of my very incomplete experiments are on https://programmingmiscellany.wordp...ndom/homebrewing-a-board-for-the-mcp3426-adc/

That post was really about hooking up a 16 bit MCP3426 ADC chip more than about the USB-GPIO board, but some of the libraries are mentioned.


----------

