# Introduction

GPIO means General Purporse Input/Output and is the generic name for all the pins of the AVR32UC3A microcontroller. Every pin of the microcontroller is a GPIO pin except for the power supply pins, the pin that resets the processor and the USB JTAG signal connections. This includes the connections to the SDRAM and every other input or output signal.
Each of the GPIO pins can be programmed to have one of three functions, and the three functions are different for every pin. When the Mizar32 is turned on, it is deaf and blind and the first thing that the on-board software must do is to program the correct function for each of the GPIO pins that are necessary for it to be able to talk to the rest of the world.
For example, Hempl does the following when it starts up:
* it programs the pins that are connected to the oscillator crystals to function as oscillator inputs. This increases its processing speed from 115kHz (its internal oscillator) to 66MHz (the external oscillator). It also programs the pins connected to the 32768Hz crystal as oscillator inputs so that it can measure time accurately;
* it programs the LCDpins connected to the SDRAM memory to work as SDRAM memory pins so that, as well as the 64Kbyte (Models A and B) or 32Kbyte (Model C) internal RAM, it can also access the 32Mbyte SDRAM memory chip;
* if you have configured the Hempl console to be on the serial port, it programs UART0's RX and TX pins to talk RS232;
* if your Hempl firmware includes MMC/SD card support, the pins of the second SPI port, SPI1, are programmed to talk the MMC/SD card.
The GPIO pins for all other devices are programmed to perform their function the first time you call them from Lua. If you are not using some device you are free to use its GPIO pins as simple input/output pins: see the PIO section for further details on how to do this.

# Pin functions

On the Mizar32, the following functions are assigned to the GPIO pins:
Legend:
* X = Pin is not connected to anything
* Foo/Bar = signal is used for more than one thing
Port A :
| PIN | SIGNAL | Description | Bus pin |
| PA00 | UART0_RX | Right bus serial port | BUS4 pin 3 |
| PA01 | UART0_TX | Right bus serial port | BUS4 pin 4 |
| PA02 | GPIO2 | Bus GPIO, 4mA max, VGA SRAM /HOLD pin | BUS5 pin 11 |
| PA03 | UART0_RTS | Right bus serial port | BUS4 pin 5 |
| PA04 | UART0_CTS | Right bus serial port | BUS4 pin 6 |
| PA05 | UART1_RX | Left bus serial port | BUS3 pin 3 |
| PA06 | UART1_TX | Left bus serial port | BUS3 pin 4 |
| PA07 | GPIO7 | Bus GPIO, 4mA max | BUS5 pin 12 |
| PA08 | UART1_RTS | Left bus serial port | BUS3 pin 10 |
| PA09 | UART1_CTS | Left bus serial port | BUS3 pin 9 |
| PA10 | SPI0_CS0 | Left bus SPI | BUS1 pin 12 |
| PA11 | SPI0_MISO | Left bus SPI | BUS1 pin 13 |
| PA12 | SPI0_MOSI | Left bus SPI | BUS1 pin 14 |
| PA13 | SPI0_SCK | Left bus SPI | BUS1 pin 15 |
| PA14 | SPI1_CS0 | SD card chip select | None |
| PA15 | SPI1_SCK | Right bus SPI/SD card clock | BUS4 pin 9 |
| PA16 | SPI1_MOSI | Right bus SPI/SD card data in (host->card) | BUS4 pin 10 |
| PA17 | SPI1_MISO | Right bus SPI/SD card data out (card->host) | BUS4 pin 11 |
| PA18 | SPI1_CS1 | "FREE" | None |
| PA19 | SPI1_CS2 | Right bus SPI chip select | BUS4 pin 12 |
| PA20 | EXT_INT | ? | BUS5 pin 13 |
| PA21 | ADC0 | ADC | BUS5 pin 5 |
| PA22 | ADC1 | ADC | BUS5 pin 6 |
| PA23 | ADC2 | ADC | BUS5 pin 7 |
| PA24 | ETHERNET | Ethernet interrupt | BUS2 pin 3 |
| PA25 | ADC4 | ADC | BUS6 pin 4 |
| PA26 | ADC5 | ADC | BUS6 pin 5 |
| PA27 | ADC6 | ADC | BUS6 pin 6 |
| PA28 | ADC7 | ADC | BUS6 pin 7 |
| PA29 | SDA | I2C | BUS2 pin 10 |
| PA30 | SCL | I2C | BUS2 pin 11 |
Port B :
| PIN | SIGNAL | Description | Bus pin |
| PB00 | REF_CLK | Ethernet | BUS1 pin 3 |
| PB01 | TX_EN | Ethernet | BUS1 pin 4 |
| PB02 | TX0 | Ethernet | BUS1 pin 5 |
| PB03 | TX1 | Ethernet | BUS1 pin 6 |
| PB04 | X | Ethernet | None |
| PB05 | RX0 | Ethernet | BUS2 pin 5 |
| PB06 | RX1 | Ethernet | BUS2 pin 6 |
| PB07 | RX_ER | Ethernet | BUS2 pin 7 |
| PB08 | MDC | Ethernet | BUS2 pin 4 |
| PB09 | MDIO | Ethernet | BUS2 pin 8 |
| PB10 | SDCK | SDRAM | None |
| PB11 | SDCKE | SDRAM | None |
| PB12 | RASn | SDRAM | None |
| PB13 | CASn | SDRAM | None |
| PB14 | SDWEn | SDRAM | None |
| PB15 | RX_DV | Ethernet | BUS1 pin 7 |
| PB16 | SDA10 | SDRAM A10 | None |
| PB17 | GPIO49 | Bus GPIO, 4mA max | BUS5 pin 8 |
| PB18 | GPIO50/PWM6 | Bus GPIO, 4mA max/PWM channel 6 | BUS5 pin 9 |
| PB19 | PWM0 | PWM | BUS4 pin 7 |
| PB20 | PWM1 | PWM | BUS4 pin 8 |
| PB21 | PWM2 | PWM | None |
| PB22 | PWM3 | PWM | BUS6 pin 1 |
| PB23 | UART1_DCD | Left bus serial port | BUS3 pin 5 |
| PB24 | UART1_DSR | Left bus serial port | BUS3 pin 6 |
| PB25 | UART1_DTR | Left bus serial port | BUS3 pin 7 |
| PB26 | UART1_RI | Left bus serial port | BUS3 pin 8 |
| PB27 | PWM4 | PWM channel 4 | BUS6 pin 2 |
| PB28 | PWM5 | PWM channel 4 | BUS6 pin 3 |
| PB29 | GPIO61/LED | On-board LED (0=lit) | None |
| PB30 | GPIO62 | Bus GPIO, 4mA max | BUS6 pin 9 |
| PB31 | GPIO63 | Bus GPIO, 4mA max | BUS6 pin 10 |
Port C :
| PIN | SIGNAL | Description |
| PC00 | Xin32 | 32768Hz crystal "X2" (*) |
| PC01 | Xout32 | 32768Hz crystal "X2" (*) |
| PC02 | Xin0 | 12MHz crystal "X1" |
| PC03 | Xout0 | 12MHz crystal "X1" |
| PC04 | Xin1 | Not used |
| PC05 | Xout1 | Not used |
* ) On circuit pads C47 before Mizar32 v1.3.2
Port X :
| PIN | SIGNAL | Description | Bus pin |
| PX00 | D10 | SDRAM | None |
| PX01 | D9 | SDRAM | None |
| PX02 | D8 | SDRAM | None |
| PX03 | D7 | SDRAM | None |
| PX04 | D6 | SDRAM | None |
| PX05 | D5 | SDRAM | None |
| PX06 | D4 | SDRAM | None |
| PX07 | D3 | SDRAM | None |
| PX08 | D2 | SDRAM | None |
| PX09 | D1 | SDRAM | None |
| PX10 | D0 | SDRAM | None |
| PX11 | DQM1 | SDRAM | None |
| PX12 | X | SDRAM | None |
| PX13 | X | SDRAM | None |
| PX14 | CS1n | SDRAM | None |
| PX15 | X | SDRAM | None |
| PX16 | GPIO88/BUTTON | Bus GPIO/Push button on main board (low when pressed) | BUS6 pin 13 |
| PX17 | A17 | SDRAM BA1 | None |
| PX18 | A16 | SDRAM BA0 | None |
| PX19 | GPIO85 | Bus GPIO, 4mA max | BUS6 pin 12 |
| PX20 | A14 | SDRAM A12 | None |
| PX21 | A13 | SDRAM A11 | None |
| PX22 | GPIO82 | Bus GPIO, 4mA max (SDRAM A10 is on PB16) | BUS6 pin 11 |
| PX23 | A11 | SDRAM A9 | None |
| PX24 | A10 | SDRAM A8 | None |
| PX25 | A9 | SDRAM A7 | None |
| PX26 | A8 | SDRAM A6 | None |
| PX27 | A7 | SDRAM A5 | None |
| PX28 | A6 | SDRAM A4 | None |
| PX29 | A5 | SDRAM A3 | None |
| PX30 | A4 | SDRAM A2 | None |
| PX31 | A3 | SDRAM A1 | None |
| PX32 | A2 | SDRAM A0 | None |
| PX33 | GPIO71 | Bus GPIO, 4mA max | BUS5 pin 10 |
| PX34 | DQM0 | SDRAM | None |
| PX35 | D15 | SDRAM | None |
| PX36 | D14 | SDRAM | None |
| PX37 | D13 | SDRAM | None |
| PX38 | D12 | SDRAM | None |
| PX39 | D11 | SDRAM | None |
Bus renaming: In Mizar32 v1.3.2, the bus connectors were renamed
| Old | New | Also known as |
| P3 | BUS1 | BUS_HALF_LEFT_UP |
| P4 | BUS2 | BUS_HALF_LEFT_DOWN |
| P2 | BUS3 | BUS_HALF_LEFT_EXT |
| P5 | BUS4 | BUS_HALF_RIGHT_UP |
| P6 | BUS5 | BUS_HALF_RIGHT_DOWN |
| P7 | BUS6 | BUS_HALF_RIGHT_EXT |

# Further reading

* The PIO section explains further how these pins are used.
* There is a summary table of the possible functions that can be assigned to each GPIO pin in the Atmel AVR32UC3A Datasheet, section 12.7 "Peripherals: Peripheral Multiplexing on I/O lines", table 12-9.
* The last part of the file in the AVR32 GNU toolchain /usr/avr32/include/avr32/uc3a0128.h gives a complete definition of what functions can be assigned to each pin.