Skip to content

Commit 0689f37

Browse files
committed
Add support for the PYNQ-Z2 board
1 parent a232f39 commit 0689f37

File tree

8 files changed

+442
-10
lines changed

8 files changed

+442
-10
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,17 @@ repository root:
466466
fusesoc --cores-root=. run --target=synth --setup --build lowrisc:ibex:demo_system
467467
```
468468

469+
To build for other support development boards such as the NewAE CW305, NewAE CW312-A35, or the TUL PYNQ-Z2, use the command
470+
471+
```
472+
# NewAE CW305
473+
fusesoc --cores-root=. run --target=synth_cw305 --setup --build lowrisc:ibex:demo_system
474+
# NewAE CW312-A35
475+
fusesoc --cores-root=. run --target=synth_cw312a35 --setup --build lowrisc:ibex:demo_system
476+
# TUL PYNQ-Z2
477+
fusesoc --cores-root=. run --target=synth_pynqz2 --setup --build lowrisc:ibex:demo_system
478+
```
479+
469480
## Programming FPGA
470481

471482
To program the FPGA, either use FuseSoC again
@@ -504,6 +515,14 @@ In this case, you may try using `sudo`.
504515

505516
To exit from the `screen` command, you should press control and a together, then release these two keys and press d.
506517

518+
### Note on UART connection for the PYNQ-Z2 development board
519+
520+
There is no direct connection between the FTDI chip and the programming logic (PL) side of the Zynq 7020 SOC used in the PYNQ-Z2 development board. However, we may attach a 2.54mm pin header to J13 (pin 1: UART RX, pin 2: UART TX) on the board, route the UART signals to any available I/O pins, and make a connection using jumper wires.
521+
522+
The following image shows a one-way connection between the TX pin of the Ibex and the RX pin of the FTDI chip.
523+
524+
![PYNQ-Z2 UART jumper wire connection](doc/PynqZ2UARTConnection.jpg)
525+
507526
## Debugging an application
508527

509528
Either load an application and halt (see above) or start a new OpenOCD instance

data/pins_pynqz2.xdc

Lines changed: 194 additions & 0 deletions
Large diffs are not rendered by default.

doc/PynqZ2UARTConnection.jpg

482 KB
Loading

ibex_demo_system.core

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ filesets:
3333
- rtl/fpga/top_cw312a35.sv
3434
file_type: systemVerilogSource
3535

36+
files_xilinx_pynqz2:
37+
depend:
38+
- lowrisc:ibex:rv_timer
39+
- lowrisc:ibex:fpga_xilinx_shared
40+
files:
41+
- rtl/fpga/top_pynqz2.sv
42+
- rtl/fpga/clkgen_pynqz2.sv
43+
file_type: systemVerilogSource
44+
3645
files_verilator:
3746
depend:
3847
- lowrisc:ibex:sim_shared
@@ -60,6 +69,10 @@ filesets:
6069
- data/pins_cw312a35.xdc
6170
file_type: xdc
6271

72+
files_constraints_pynqz2:
73+
files:
74+
- data/pins_pynqz2.xdc
75+
file_type: xdc
6376

6477

6578
parameters:
@@ -125,6 +138,19 @@ targets:
125138
parameters:
126139
- SRAMInitFile
127140
- PRIM_DEFAULT_IMPL=prim_pkg::ImplXilinx
141+
synth_pynqz2:
142+
<<: *default_target
143+
default_tool: vivado
144+
filesets_append:
145+
- files_xilinx_pynqz2
146+
- files_constraints_pynqz2
147+
toplevel: top_pynqz2
148+
tools:
149+
vivado:
150+
part: "xc7z020clg400-1"
151+
parameters:
152+
- SRAMInitFile
153+
- PRIM_DEFAULT_IMPL=prim_pkg::ImplXilinx
128154

129155
sim:
130156
<<: *default_target

rtl/fpga/clkgen_pynqz2.sv

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright lowRISC contributors.
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
module clkgen_pynqz2 (
6+
input IO_CLK,
7+
input IO_RST_N,
8+
output clk_sys,
9+
output rst_sys_n
10+
);
11+
logic locked_pll;
12+
logic io_clk_buf;
13+
logic clk_50_buf;
14+
logic clk_50_unbuf;
15+
logic clk_fb_buf;
16+
logic clk_fb_unbuf;
17+
18+
// input buffer
19+
IBUF io_clk_ibuf(
20+
.I (IO_CLK),
21+
.O (io_clk_buf)
22+
);
23+
24+
PLLE2_ADV #(
25+
.BANDWIDTH ("OPTIMIZED"),
26+
.COMPENSATION ("ZHOLD"),
27+
.STARTUP_WAIT ("FALSE"),
28+
.DIVCLK_DIVIDE (5),
29+
.CLKFBOUT_MULT (34),
30+
.CLKFBOUT_PHASE (0.000),
31+
.CLKOUT0_DIVIDE (17),
32+
.CLKOUT0_PHASE (0.000),
33+
.CLKOUT0_DUTY_CYCLE (0.500),
34+
.CLKIN1_PERIOD (8.000)
35+
) pll (
36+
.CLKFBOUT (clk_fb_unbuf),
37+
.CLKOUT0 (clk_50_unbuf),
38+
.CLKOUT1 (),
39+
.CLKOUT2 (),
40+
.CLKOUT3 (),
41+
.CLKOUT4 (),
42+
.CLKOUT5 (),
43+
// Input clock control
44+
.CLKFBIN (clk_fb_buf),
45+
.CLKIN1 (io_clk_buf),
46+
.CLKIN2 (1'b0),
47+
// Tied to always select the primary input clock
48+
.CLKINSEL (1'b1),
49+
// Ports for dynamic reconfiguration
50+
.DADDR (7'h0),
51+
.DCLK (1'b0),
52+
.DEN (1'b0),
53+
.DI (16'h0),
54+
.DO (),
55+
.DRDY (),
56+
.DWE (1'b0),
57+
// Other control and status signals
58+
.LOCKED (locked_pll),
59+
.PWRDWN (1'b0),
60+
// Do not reset PLL on external reset, otherwise ILA disconnects at a reset
61+
.RST (1'b0));
62+
63+
// output buffering
64+
BUFG clk_fb_bufg (
65+
.I (clk_fb_unbuf),
66+
.O (clk_fb_buf)
67+
);
68+
69+
BUFG clk_50_bufg (
70+
.I (clk_50_unbuf),
71+
.O (clk_50_buf)
72+
);
73+
74+
// outputs
75+
// clock
76+
assign clk_sys = clk_50_buf;
77+
78+
// reset
79+
assign rst_sys_n = locked_pll & IO_RST_N;
80+
endmodule

rtl/fpga/top_pynqz2.sv

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright lowRISC contributors.
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
// This is the top level SystemVerilog file that connects the IO on the board to the Ibex Demo System.
6+
module top_pynqz2 (
7+
// These inputs are defined in data/pins_pynqz2.xdc
8+
input IO_CLK,
9+
input IO_RST,
10+
input [1:0] SW,
11+
input [2:0] BTN,
12+
output [3:0] LED,
13+
output [3:0] GPIOS,
14+
output [5:0] RGB_LED,
15+
input UART_RX,
16+
output UART_TX,
17+
input SPI_RX,
18+
output SPI_TX,
19+
output SPI_SCK
20+
);
21+
parameter SRAMInitFile = "";
22+
23+
logic clk_sys, rst_sys_n;
24+
25+
// Instantiating the Ibex Demo System.
26+
ibex_demo_system #(
27+
.GpiWidth(5),
28+
.GpoWidth(8),
29+
.PwmWidth(6),
30+
.SRAMInitFile(SRAMInitFile)
31+
) u_ibex_demo_system (
32+
//input
33+
.clk_sys_i(clk_sys),
34+
.rst_sys_ni(rst_sys_n),
35+
.gp_i({SW, BTN}),
36+
.uart_rx_i(UART_RX),
37+
38+
//output
39+
.gp_o({LED, GPIOS}),
40+
.pwm_o(RGB_LED),
41+
.uart_tx_o(UART_TX),
42+
43+
.spi_rx_i(SPI_RX),
44+
.spi_tx_o(SPI_TX),
45+
.spi_sck_o(SPI_SCK)
46+
);
47+
48+
logic IO_RST_N;
49+
assign IO_RST_N = ~IO_RST;
50+
51+
// Generating the system clock and reset for the FPGA.
52+
clkgen_pynqz2 clkgen(
53+
.IO_CLK,
54+
.IO_RST_N,
55+
.clk_sys,
56+
.rst_sys_n
57+
);
58+
59+
endmodule

util/load_demo_system.sh

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,42 @@
33
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
44
# SPDX-License-Identifier: Apache-2.0
55

6-
if [ $# -ne 2 ]; then
7-
echo "Usage $0 run|halt elf_file"
6+
if [ $# -ne 3 ]; then
7+
echo "Usage $0 artya7|pynqz2 run|halt elf_file"
88
exit 1
99
fi
1010

11-
if [ ! -f $2 ]; then
12-
echo "$2 does not exist"
11+
if [ ! -f $3 ]; then
12+
echo "$3 does not exist"
1313
exit 1
1414
fi
1515

16-
if [ $1 != "halt" ] && [ $1 != "run" ]; then
17-
echo "First argument must be halt or run"
16+
if [ $2 != "halt" ] && [ $2 != "run" ]; then
17+
echo "Second argument must be halt or run"
18+
exit 1
19+
fi
20+
21+
if [ $1 != "artya7" ] && [ $1 != "pynqz2" ]; then
22+
echo "First argument must be artya7 or pynqz2"
1823
exit 1
1924
fi
2025

2126
EXIT_CMD=''
2227

23-
if [ $1 = "run" ]; then
28+
if [ $2 = "run" ]; then
2429
EXIT_CMD='-c "exit"'
2530
fi
2631

2732
SCRIPT_DIR="$(dirname "$(readlink -e "$0")")"
2833

29-
openocd -f $SCRIPT_DIR/arty-a7-openocd-cfg.tcl -c "load_image $2 0x0" \
30-
-c "verify_image $2 0x0" \
34+
if [ $1 = "artya7" ]; then
35+
SCRIPT_FILENAME="arty-a7-openocd-cfg.tcl"
36+
elif [ $1 = "pynqz2" ]; then
37+
SCRIPT_FILENAME="pynq-z2-openocd-cfg.tcl"
38+
fi
39+
40+
openocd -f $SCRIPT_DIR/$SCRIPT_FILENAME -c "load_image $3 0x0" \
41+
-c "verify_image $3 0x0" \
3142
-c "echo \"Doing reset\"" \
32-
-c "reset $1" \
43+
-c "reset $2" \
3344
$EXIT_CMD

util/pynq-z2-openocd-cfg.tcl

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright lowRISC contributors.
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
adapter driver ftdi
6+
transport select jtag
7+
8+
ftdi_device_desc "TUL"
9+
ftdi_vid_pid 0x0403 0x6010
10+
ftdi_channel 0
11+
ftdi_layout_init 0x0088 0x008b
12+
reset_config none
13+
14+
# Configure JTAG chain and the target processor
15+
set _CHIPNAME riscv
16+
17+
# Configure JTAG expected ID
18+
set _EXPECTED_ID 0x23727093
19+
20+
jtag newtap $_CHIPNAME cpu -irlen 6 -expected-id $_EXPECTED_ID -ignore-version
21+
22+
# just to avoid a warning about the auto-detected arm core
23+
# see: https://github.com/pulp-platform/riscv-dbg/blob/master/doc/debug-system.md
24+
jtag newtap arm_unused tap -irlen 4 -expected-id 0x4ba00477
25+
26+
set _TARGETNAME $_CHIPNAME.cpu
27+
target create $_TARGETNAME riscv -chain-position $_TARGETNAME
28+
29+
riscv set_ir idcode 0x09
30+
riscv set_ir dtmcs 0x22
31+
riscv set_ir dmi 0x23
32+
33+
adapter speed 10000
34+
35+
riscv set_prefer_sba on
36+
gdb_report_data_abort enable
37+
gdb_report_register_access_error enable
38+
gdb_breakpoint_override hard
39+
40+
reset_config none
41+
42+
init
43+
halt

0 commit comments

Comments
 (0)