This lesson is about using Vivado/Vitis 2023.2 to blink an LED.
First, open Vivado 2023.2 to design the hardware of the project. To create a new project, follow the stages below.
Stage 1:1. Follow File -> Project -> New. Then in the New Project window press Next.
2. Enter Project name and Project location. Then press Next.
3. To specify the project type, select RTL Project and tick the box "Do not specify sources at this time" as follows. Then press Next.
4. To choose a board for your project, in the Boards tab search for zedboard in the Search field and the press Refresh button. Install zedboard by pressing the install icon in Status column.
5. Select "ZedBoard Zynq..." with the vendor avent.com and Version 1.4. Then press Next.
6. The summary of the new project is shown as follows. then press Finish.
After finishing the previous part, you can see your selected name for the project in the title bar.
1. In Flow Navigator part, in IP INTEGRATOR, click on "Create Block Design", enter a Design name, and press OK.
2. In Diagram window click the plus (+) icon to Add IP. Search for "ZYNQ7 Processing System", then press enter to place it in Diagram window.
3. Since you've selected a board (ZedBoard) not just an FPGA, the "Run Block Automation" will be appeared on green narrow. Click Run Block Automation: tick Apply Board Preset and Disable both "Cross Trigger In" and "Cross Trigger Out".
After applying, the processing system can be seen as follows,
4. Validate Design by pressing F6 or its icon. You have to see Validation successful. If the error "There was one error message while validating the design" is appeared, wire M_AXI_GP0_ACLK to FCLK_CLK0 as follows, then validate the design again to see Validation successful.
5. Double click ZYNQ7 Processing System to Re-customize IP.In Peripheral I/O Pins tab add UART0 for 14-15 MIO pins. (UART1 is already added) and add I2C0 for MIO 10-11. (For this less we only need to active GPIO MIO and UART1 but we will use I2C0 and UART0 in next lessons.)
Press OK, then Validate Design to see Validation successful message. Press Ctrl+S to save block design.
6. To determine the target language before generating output product and exporting the hardware platform using in Vitis, click Setting in PROJECT MANAGER, then select VHDL or Verilog in drop down menu of Target Language as shown below,
7. To create HDL Wrapper, in BLOCK DESIGN window, Source tab, right click on the name of Block Design, and select "Create HDL Wrapper...".
(Follow BLOCK DESIGN ->Source -> Design Source -> zedboard name.db -> right click -> Create HDL Wrapper... )
Then, in Create HDL Wrapper window, select "Let Vivado manage wrapper and auto-update", and press OK.
8. Click on Generate Block Design in Flow Navigator -> IP INTEGRATOR. To speed up the generation, select Global in Synthesis options in Generate Output Products window. Finally press Generate.
You must see the following generation successful message.
9. Final step in this stage, is exporting the hardware. Follow File -> Export -> Export Hardware. Then press Next. Select Pre-synthesis and press OK. Enter XSA file name and the directory. Then press Next.
(If you have been chosen VHDL as target language, select include bitstream instead.)
Finally, to export the platform, click Finish.
At the end of the above stages in Vivado, a .xsa file is created to use in Vitis.
Launch Vitis 2023.2 from Tools -> Lanch Vitis IDE or double click on its icon.
Stage 3: Creating Platform1. Click Create Platform Component in Embedded Development in Welcome tab. Enter component name and the location. It is recommended to create a folder with the name of vitis in the directory of Vivado Project. Then browse and select this folder. Press Next.
2. Browse the .xsa file from Vivado project. Then press Next.
3. Here, you should select OS and Processor. The selections of Operating system are standalone, freertos and linux. Select standalone and press Next.
4. The summary of platform is shown. Press Finish.
5. After Finishing, Build the platform to see the message "Generate PlatformName platform finished successfully."
6. To see details and documentations of the generated platform, open the drop-down menu of the created platform, open settings and then click vitis-comp.json:
Follow PlatformName -> ps7_cortexa9_0 -> standalone_ps7_cortexa9_0 -> Board Support Package to see drivers, details and other useful documents as the following,
1. You can create an application by clicking on Create Embedded Applocation in Embedded Development part or using Examples from Welcome tab.
2. Click on Hello World in Embedded Software Examples, then press "Create Application Component from Template".
3. Enter component name and location, then press Next.
4. Select platform from the created platforms, then press Next.
5. Select Domain, then press Next.
6. After seeing the summary of the application press Finish.
Consider LED9 of the ZedBoard which is connected to MIO7 which blinks every 1 second.
1. Open drop-down menu of the project (named LED_blinking) in VITIS, open Source, then click helloworld.c. (As Hello World template is used to create this application, its name is helloworld.c.)
2.1. Add header files:
#include "xgpiops.h"
#include "xparameters.h"
#include "sleep.h"
xgpiops.h provides gpio drivers.
xparameters.h contains the processor’s address space and the device IDs.
sleep.h is used for delay.
2.2. Create a structure with the desired name (e.g. gpio):
XGpioPs gpio;
2.3. Define a function to initialize gpio:
void gpioInit()
{
XGpioPs_Config *gpioConfig;
gpioConfig = XGpioPs_LookupConfig(XPAR_GPIO0_BASEADDR);
if(gpioConfig==NULL) xil_printf("GPIO Config Error...");
int status =XGpioPs_CfgInitialize(&gpio, gpioConfig, gpioConfig->BaseAddr);
if (status==XST_SUCCESS) xil_printf("GPIO initialization Successful...\r\n");
XGpioPs_SetDirectionPin(&gpio, 7, 1);
XGpioPs_SetOutputEnablePin(&gpio, 7, 1);
}
2.4. Main function:
int main()
{
gpioInit();
while(1)
{
XGpioPs_WritePin(&gpio, 7, 1);
sleep(1);
XGpioPs_WritePin(&gpio, 7, 0);
sleep(1);
}
return 0;
}
2.5. The whole.c file is as follows,
#include <stdio.h>
#include <xstatus.h>
#include "platform.h"
#include "xil_printf.h"
#include "xgpiops.h"
#include "xparameters.h"
#include "sleep.h"
XGpioPs gpio;
void gpioInit()
{
XGpioPs_Config *gpioConfig;
gpioConfig = XGpioPs_LookupConfig(XPAR_GPIO0_BASEADDR);
if(gpioConfig==NULL) xil_printf("GPIO Config Error...");
int status =XGpioPs_CfgInitialize(&gpio, gpioConfig, gpioConfig->BaseAddr);
if (status==XST_SUCCESS) xil_printf("GPIO initialization Successful...\r\n");
XGpioPs_SetDirectionPin(&gpio, 7, 1);
XGpioPs_SetOutputEnablePin(&gpio, 7, 1);
}
int main()
{
gpio_init();
while(1)
{
XGpioPs_WritePin(&gpio, 7, 1);
sleep(1);
XGpioPs_WritePin(&gpio, 7, 0);
sleep(1);
}
return 0;
}
Stage 6: Running the program1. Connect Programmer to the board.
2. Build the program.
3. After building completed, Run will be active. Click Run.
It the following error message appeared, press Prog button on the board and then Run again.
4. Now, LED9 is blinking.
Comments