Configuring MIO Pins

Configure MIO pushbuttons and inputs and RGB LEDs as outputs


Configuring MIO pins for GPIO

The ZYNQ device on the Blackboard has 54 externally connected I/O pins that are driven from the MIO (or Multiplexed I/O) interface. The MIO interface allows the ARM to access external pins without routing signals through the FPGA. All the on-board peripheral devices and bus controllers use MIO pins to connect to external devices and connectors, and as the name implies, the pins are multiplexed so the designer can choose which of the 54 pins connect to which devices. Each of the 54 MIO pins has a configuration register that defines pin properties like voltage level, slew rate, pull-up or pull-down, etc. Two additional registers define MIO pins as inputs or outputs, and for those pins defined as outputs, two more registers enable the outputs. The figure below shows the MIO system and the two pins on the Blackboard that are connected to pushbuttons (MIO pins 51 and 51), and the three pins that drive the RGB LED (MIO pins 16, 17, and 18).

This document describes how to configure MIO pins as General Purpose Input/Output pins (GPIOs). The “Configuring the GIC for GPIO Interrupts” document describes how to use interrupts with the GPIO inputs.

Several registers are are used to configre the MIO pins. These registers are shown in the C-language statements immediately below the figure, and they are described in the following text.

Figure 1. ZYNQ MIO System
Figure 1. ZYNQ MIO System
#define MIO_PIN_16 0xF8000740
#define MIO_PIN_17 0xF8000744
#define MIO_PIN_18 0xF8000748
#define MIO_PIN_50 0xF80007C8
#define MIO_PIN_51 0xF80007CC
#define GPIO_DIRM_0 0xE000A204 // Direction mode bank 0
#define GPIO_OUTE_0 0xE000A208 // Output enable bank 0
#define GPIO_DIRM_1 0xE000A244 // Direction mode bank 1

The schematic below is taken from Blackboard’s schematic, and shows the locations of the LED and pushbuttons. The LED uses three physical pins A19, E14, and B18, and these are connected to MIO pins 16, 17, 18; the push buttons use two physical pins B13 and B9, and these are connected to MIO pins 50 and 51.

Figure 2. ARM Registers
Figure 2. ARM Registers

These MIO pins can be configured using the MIO pin configuration registers starting at location 0xF8000700 (see the Programmers Reference “MIO Pin Control” section). All five pins must have:

  • the lower 8 bits set to ‘0’ to define the pins as GPIOs with tri-states disabled;
  • bit 9 set to ‘0’ to define slow edges (in general, slow edges should be selected unless you know fast edges are required);
  • bits 11:9 set to ‘011’ to select LVCMOS33;
  • bit 12 set to ‘0’ to disable pull-up resistors;
  • bit 13 set to ‘1’ to disable the HSTL buffers for pins that will be set as outputs.

The statements below set the MIO_PIN registers properly.

 * Write unlock code to enable writing
 * into System Level Control Unlock Register
*((uint32_t *) 0xF8000000+0x8/4) = 0x0000DF0D;                           
// Configure MIO pins
*((uint32_t*) MIO_PIN_50) = 0x00000600; // BTN4
*((uint32_t*) MIO_PIN_51) = 0x00000600; // BTN5
*((uint32_t*) MIO_PIN_16) = 0x00001600; // RGB_LED_B
*((uint32_t*) MIO_PIN_17) = 0x00001600; // RGB_LED_R
*((uint32_t*) MIO_PIN_18) = 0x00001600; // RGB_LED_G

There will be no actual need to place the MIO configuration lines of code into your rest of the code because the pins are already configured accordingly within the .hdf, but it would be helpful to understand how these configuration registers works. This also gives you availability to reconfigure items that are already configured within the hardware if necessary. Once the pins have been correctly configured, they can be defined as inputs or outputs. The LED-connected pins can be set as outputs using the GPIO_DIRM_0 register at 0xE000A204 (see the Programmers Reference “General Purpose I/O Module” section), and have their outputs enabled using the GPIO_OUTE_0 register at 0XE000A208 (see the Programmers Reference “General Purpose I/O Module” section). The following two lines accomplish this.

*((uint32_t*) GPIO_DIRM_0) = 0x00070000;
*((uint32_t*) GPIO_OUTE_0) = 0x00070000;

The pushbutton-connected pins can be set as inputs using the DIRM_1 register at 0xE000A244 (see the Programmers Reference “General Purpose I/O Module” section).

*((uint32_t*) GPIO_DIRM_1) = 0x00000000;

Including these statements in your C program will setup the MIO GPIOs for use in this project. You might consider putting these statements in their own “configureMIOpins” subroutine for better readability.