##Using the D.Gilbert gpio utils 

An in-deep explanation on how the GPIO lines work and how to manage them faster is available on:

* [Aria G25 GPIO notes by Dougg Gilbert](http://sg.danny.cz/foxg20/ag25g20_utils/ariag25_gpio.txt)
* [FOX Board G20 GPIO notes by Dougg Gilbert](http://sg.danny.cz/foxg20/foxg20_gpio.txt)


<span class="abstract">
This is a small group of Linux utilities for the Atmel AT91SAM9G25
and AT91SAM9G20 microcontroller units (MCUs). The utilities target
The Aria G25 and the FoxG20 boards from Acme Systems and will most
likely work on other boards based on the same MCUs. Some of the
utilities have the same names as those from the earlier FoxLX board
from Acme System; that board was based on the Etrax LX processor
from Axis communications.

These utilities mainly work with individual GPIO lines and may be
extended to other protocols that can be implemented by "bit banging"
GPIO lines. These include I2C (a.k.a. TWI), "one wire" (known as "w1"
by the Linux kernel) from Dallas Semiconductor (now Maxim), and the
two wire protocol for the SHT-71 .
</span>

* [Gpio utils README](http://sg.danny.cz/foxg20/ag25g20_utils-0.97r14/readme.txt)

##Compile and build the utilities

Download <b>on your board (not on your Linux workstation)</b> the latest utilities version from the D.Gilbert 
web server<br><br>

For the CPUs AT91SAMG20 and AT91SAMG25:
<pre class="minicom">
~# <b>wget http://sg.danny.cz/foxg20/ag25g20_utils-0.97r14.tgz</b>
</pre>

For the AT91SAMA5 CPUs:
<pre class="minicom">
~# <b>wget http://sg.danny.cz/foxg20/sama5d3/sama5d3_utils-0.92.tar.xz</b>
</pre>
You need to install the xz-utils for the AT91SAMA5:
<pre class="minicom">
~# <b>apt-get install xz-utils</b>
</pre>

Uncompress the .tgz / .tar.xz file

<pre class="minicom">
// for the G20 and G25:
~# <b>tar xvzf ag25g20_utils-0.97r14.tgz</b>

// for the A5:
~# <b>tar xvf sama5d3_utils-0.92.tar.xz</b>
</pre>

If necessary you need to install the tools for compiling on board (remember to have a correct date on your embedded board before installing packages or update):
<pre class="minicom">
~# <b>date -s "27 MAR 2019 11:14:00"</b>
</pre>

<pre class="minicom">
~# <b>apt-get update</b>
~# <b>apt-get install build-essential</b>
</pre>

Compile and install them

<pre class="minicom">
// for the G20 and G25:
~# <b>cd ag25g20_utils-0.97r14</b>
~/ag25g20_utils-0.97r14# <b>make</b>
~/ag25g20_utils-0.97r14# <b>make install</b>

// for the A5:
~# <b>cd sama5d3_utils-0.92</b>
~/sama5d3_utils-0.92# <b>make</b>
~/sama5d3_utils-0.92# <b>make install</b>
</pre>




##Using the utilities

Refer to the original README file to learn how to use these utilities

* [readme.txt](http://sg.danny.cz/foxg20/ag25g20_utils-0.97r14/readme.txt)

Following is a list of quick examples:

###Show the command list
 
<pre class="minicom">
~# g25gpio_status -h               
</pre>

##Get the PIO attributes on given GPIO line

<pre class="minicom">
~# <b>g25gpio_status -a -p A</b>
PA0:
  PIO status: 0 (peripheral ACTIVE)
  PIO output status: 0 (line pure input)
  input filter status: 0 (glitch filter DISabled)
  output data status: 0
  pin data status: 0
  interrupt mask: 0 (DISabled)
  multi driver status: 0 (pin driven high and low)
  pad pull-up status: 0 (ENabled)
  peripheral A function [sr1:0, sr2:0]
  input filter slow clock status: 0 (master-fast)
  pad pull down status: 1 (DISabled)
  additional interrupt modes mask: 0 (Both edges)
  edge/level status: 0 (edge detection)
  fall/rise - low/high status: 0 (falling edge or low level detection)
  locked status: 0 (not locked)
  write protect mode: WPEN: 0 (DISabled)
  schmitt trigger status: 0 (ENabled )
  IO drive: 0 (HI_DRIVE)
...
</pre>

of course it is possible to read all the other ports

<pre class="minicom">
~# <b>g25gpio_status -a -p B</b>
~# <b>g25gpio_status -a -p C</b>
</pre>

##Set the PIO attributes on given GPIO line


###Show the command list
 
<pre class="minicom">
~# <b>g25gpio_set -h</b>               
</pre>

###Disable the pull-up resistor on A/D input lines

<pre class="minicom">
~# <b>g25gpio_set -p B -b 11 -u</b>
~# <b>g25gpio_set -p B -b 12 -u</b>
~# <b>g25gpio_set -p B -b 13 -u</b>
~# <b>g25gpio_set -p B -b 14 -u</b>
</pre>

###Enable the low power Suspend To RAM feature on RoadRunner 1.1

<pre class="minicom">
~# <b>mem2io -w -i fc040018,300</b>
</pre>

Related links

* [Doug Gilbert repository](http://sg.danny.cz/foxg20/) 

