GPIOs

GPIO commands allow control of the function and direction of the GPIOs.

Typically, particular GPIOs are hard-wired to components such as LEDs and buttons. Other GPIOs are configurable for input and output.

GPIOs can be used for special system functions, including (but not limited to):

GPIO Functions and Pins

In the following examples, the BGX EXP evaluation board is used to demonstrate GPIO functions.

Viewing GPIO Usage

To see the current GPIO usage, read the GPIO usage variable. The default BGX EXP usage is:

> get gp u
!  # Description
#  0 none
#  1 none
#  2 none
#  3 none
#  4 none
#  5 none
#  6 none
#  7 none

Setting GPIO Function

Use the GPIO function command to set a single GPIO to a specific function.

After using gfu , it may be necessary to save then reboot depending on the alternate function (some functions are only configured at boot up).

Use gdis command to set stdio function and direction for multiple GPIOs. See Setting and Getting Multiple STDIO GPIO Values below.

Available functions are listed in the gfu command documentation.

The gfu command fails if the GPIO is already configured for an alternate function. Disable the alternate function first by using gfu <GPIO#> none .

For example, to enable GPIO 5 to operate as stdio :

> gfu 5 stdio
Success

To use LED0 to indicate when stream mode is on:

> gfu 0 str_activity_led
Success

Setting and Getting a Single STDIO GPIO Value

To set and get the value of a single GPIO, use the gse and gge commands.

Note that to set a GPIO, the GPIO must have stdio function and the output direction. To get the value, the GPIO must have stdio function. See Setting GPIO Function .

For example, set and clear GPIO 1 to turn LED1 on and off:

> gfu 1 stdio
Success
> gdi 1 olo
Success
> gge 1
0
> gse 1 1
Success
> gge 1
1

Setting and Getting Multiple STDIO GPIO Values

To set and get multiple stdio GPIO values, use the gses and gges commands.

For example, set GPIO 0 (LED0) and GPIO 1 (LED1) as stdio open-drain outputs with no pull-ups, and GPIO 2 (BTN0) and GPIO 3 (BTN1) as stdio inputs with pull-ups.

> gdis 4400XXXX
Success

With no buttons pressed, get the values of the stdio GPIOs:

> gges
1111XXXX

Now turn the LED0 on:

> gses 0111XXXX
Success

Press both buttons and get the values of the stdio GPIOs:

> gges
0100XXXX

Version Notes

For versions previous to 1.1.1229.0 , calling 'gdis' with any value other than 6 or X for a pin configured as none results in an error. The pin must first be configured as stdio with the gfu command. The configuration sequence in the Setting and Getting Multiple STDIO GPIO Values section must be:

> gfu 0 stdio
Success
> gfu 1 stdio
Success
> gfu 2 stdio
Success
> gfu 3 stdio
Success
> gdis 4400XXXX
Success