Just a quick and dirty non-tutorial solution on how to use the multiplexed I/Os (MIO/GPIO) to wire the BTN4 button on the ZYBO board (MIO50, the right one) to the LD4 LED (MIO7). Both are connected directly to the processing system and cannot be controlled from the fabric.
#include "platform.h" #include "xparameters.h" #include "xgpiops.h" #include "xstatus.h" #define GPIO_DEVICE_ID XPAR_XGPIOPS_0_DEVICE_ID #define OUTPUT_PIN 7 /* MIO7, pin connected to LED */ #define INPUT_PIN 50 /* MIO50, pin connected to button */ int main() { int Status; XGpioPs Gpio; XGpioPs_Config *ConfigPtr; // Initialize the system init_platform(); // initialize the GPIO driver. ConfigPtr = XGpioPs_LookupConfig(GPIO_DEVICE_ID); Status = XGpioPs_CfgInitialize(&Gpio, ConfigPtr, ConfigPtr->BaseAddr); if (Status != XST_SUCCESS) { return XST_FAILURE; } // configure the LED pin as output // status checks skipped for readability XGpioPs_SetDirectionPin(&Gpio, OUTPUT_PIN, 1); XGpioPs_SetOutputEnablePin(&Gpio, OUTPUT_PIN, 1); // configure the button pin as input XGpioPs_SetDirectionPin(&Gpio, INPUT_PIN, 0); // wire the button to the LED (inverted) while(1) { u32 data = XGpioPs_ReadPin(&Gpio, INPUT_PIN); XGpioPs_WritePin(&Gpio, OUTPUT_PIN, !data); } return 0; }
Note that when you open the system.mss
file in SDK, you’ll find the ps7_gpio_0
entry under the Peripheral Drivers section. Click “Example” there to find more information.