import pynq-z1 to vivado, create new project
add processor, leds, buttons
auto connect, rename leds (rgb), buttons (btns)
create HDL wrapper
add constraints file, check copy constraints file to project
##Buttons
set_property -dict { PACKAGE_PIN D19 IOSTANDARD LVCMOS33 } [get_ports { btns[0] }]; #IO_L4P_T0_35 Sch=btn[0]
set_property -dict { PACKAGE_PIN D20 IOSTANDARD LVCMOS33 } [get_ports { btns[1] }]; #IO_L4N_T0_35 Sch=btn[1]
set_property -dict { PACKAGE_PIN L20 IOSTANDARD LVCMOS33 } [get_ports { btns[2] }]; #IO_L9N_T1_DQS_AD3N_35 Sch=btn[2]
set_property -dict { PACKAGE_PIN L19 IOSTANDARD LVCMOS33 } [get_ports { btns[3] }]; #IO_L9P_T1_DQS_AD3P_35 Sch=btn[3]
##Switches
set_property -dict { PACKAGE_PIN M20 IOSTANDARD LVCMOS33 } [get_ports { sw[0] }]; #IO_L7N_T1_AD2N_35 Sch=sw[0]
set_property -dict { PACKAGE_PIN M19 IOSTANDARD LVCMOS33 } [get_ports { sw[1] }]; #IO_L7P_T1_AD2P_35 Sch=sw[1]
##RGB LEDs
set_property -dict { PACKAGE_PIN L15 IOSTANDARD LVCMOS33 } [get_ports { rgb[0] }]; #IO_L22N_T3_AD7N_35 Sch=led4_b
set_property -dict { PACKAGE_PIN G17 IOSTANDARD LVCMOS33 } [get_ports { rgb[1] }]; #IO_L16P_T2_35 Sch=led4_g
set_property -dict { PACKAGE_PIN N15 IOSTANDARD LVCMOS33 } [get_ports { rgb[2] }]; #IO_L21P_T3_DQS_AD14P_35 Sch=led4_r
set_property -dict { PACKAGE_PIN G14 IOSTANDARD LVCMOS33 } [get_ports { led[3] }]; #IO_0_35 Sch=led5_b
set_property -dict { PACKAGE_PIN L14 IOSTANDARD LVCMOS33 } [get_ports { led[4] }]; #IO_L22P_T3_AD7P_35 Sch=led5_g
set_property -dict { PACKAGE_PIN M15 IOSTANDARD LVCMOS33 } [get_ports { led[5] }]; #IO_L23N_T3_35 Sch=led5_r
generate bitstream, wait to finish
export hardware, include bitstream
tools -> launch vitis ide
create platform project
browse xsa file in project directory
right click -> build project
file -> new -> application project
select platform project -> next
name platform project -> next
select hello world
//hello world.c#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "xparameters.h"
#include "xgpio.h"
#include "sleep.h"
#define R 0x04
#define G 0x02
#define B 0x03
XGpio gpio;
void driverInit() {
int status;
status = XGpio_Initialize(&gpio, XPAR_AXI_GPIO_0_DEVICE_ID);
if (status != XST_SUCCESS) {
print("Err: Gpio initalization failed\n\r");
} else {
print("Info: Gpio Initialization successful\n\r");
}
}
void configGpio() {
XGpio_SetDataDirection(&gpio, 1, 0);
XGpio_SetDataDirection(&gpio, 2, 1);
XGpio_DiscreteSet(&gpio, 1, 0);
}
void runProject() {
int button;
while (1) {
button = XGpio_DiscreteRead(&gpio, 2);
switch (button) {
case 1:
xil_printf("%d: ",button);
XGpio_DiscreteWrite(&gpio, 1, R);
print("\tRED\n\r");
break;
case 2:
xil_printf("%d: ",button);
XGpio_DiscreteWrite(&gpio, 1, G);
print("\tGREEN\n\r");
break;
case 4:
xil_printf("%d: ",button);
XGpio_DiscreteWrite(&gpio, 1, B);
print("\tBLUE\n\r");
break;
case 8:
xil_printf("%d: ", button);
print("\tRGB\n\r");
XGpio_DiscreteWrite(&gpio, 1, R);
sleep(1);
XGpio_DiscreteClear(&gpio, 1, R);
sleep(1);
XGpio_DiscreteWrite(&gpio, 1, G);
sleep(1);
XGpio_DiscreteClear(&gpio, 1, G);
sleep(1);
XGpio_DiscreteWrite(&gpio, 1, B);
sleep(1);
XGpio_DiscreteClear(&gpio, 1, B);
sleep(1);
break;
default:
XGpio_DiscreteClear(&gpio, 1, R);
XGpio_DiscreteClear(&gpio, 1, G);
XGpio_DiscreteClear(&gpio, 1, B);
break;
}
}
}
int main() {
init_platform();
print("Hello World\n\r");
driverInit();
configGpio();
runProject();
cleanup_platform();
return 0;
}
right click -> build project
window -> show view -> add terminal
click button in terminal -> select serial port
right click project -> run as -> hardware
reference:
import board files to vivado
pynq-z1 board file and constraints file
No comments:
Post a Comment