Search by Tags

Second instance GPIO

 

Tags

Article updated at 28 Oct 2017
Compare with Revision



Several GPIOs of Marvell's PXA3xx CPUs are available on two pins. These two pins can be individually configured to Alternate Functions. In case these two pins are configured as Alternate function GPIO, then they are coupled. The two instances are named:

  • GPIOx
  • GPIOx_2
    In the Toradex GPIOConfig tool, we refer to the 2nd instance GPIOs by adding 128 to the GPIO number. E.g. GPIO3_2 -> GPIO131

If any of the two instances is configured to an alternate function other than GPIO, the other instance behaves like a regular GPIO.

If both pins are used as GPIO, you can see a special behavior:

  • GPIOx is set to output:
    Both pins, GPIOx and GPIOx_2 are output and have the level specified in the GPIO level register.
  • GPIOx is set to input:
    The level in the GPIO level register for GPIOx is a logical OR combination of the pins GPIOx and GPIOx_2.

Using second instance GPIOs

To use the second instance 'GPIOx_2', you have to follow these steps:

  • Set alternate function of the pin GPIOx_2 to GPIO in the corresponding multifunction pin register (MFP).
  • Set the direction of the GPIOx in the corresponding GPIO direction register (GPDR).
  • Now you can use the GPIO level register or edge detect registers to use the GPIOx.

Example with the Toradex GPIO library

Toradex provides several C libraries. One of them is the GPIO library. This is an example of how to use this Library to set GPIO5_2 to input and read its level.

BOOL level;
 
// initialize the GPIO library
InitGPIOLib();
 
// Set the pin GPIO5_2 to alternate function GPIO. For second instance GPIOs you have to add 128 to the GPIO number.
SetGPIOAltFn(5+128, 0, DIR_IN);
 
// Read the level of the GPIO. The GPIO has to be the logical GPIO number assigned to the pin GPIO5_2
level = GetGPIOLevel(5+128);  // The GPIOLib translates this from 5+128 to 5 and configures the correct GPIO 5
 
// Deinitialize the GPIO lib (free the virtual memory used by the lib)
DeInitGPIOLib();