Skip to content

Commit ad63b31

Browse files
committed
lots of updates, easier to utilize main module
1 parent 5e2bb6b commit ad63b31

14 files changed

+5410
-728
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
UPduino Video Example Makefile Project
1+
UPduino Video VGA Text Project Example
22

33
SPDX short identifier: MIT-0
44

Makefile

+19-24
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ PACKAGE := sg48
5050
# Verilog source directories
5151
VPATH := $(SRCDIR)
5252

53-
# Verilog source files for design (with TOP module first and no TBTOP)
54-
SRC := $(SRCDIR)/$(TOP).sv $(filter-out $(SRCDIR)/$(TBTOP).sv,$(filter-out $(SRCDIR)/$(TOP).sv,$(wildcard $(SRCDIR)/*.sv)))
53+
# Verilog source files for design (with no TOP or TBTOP module)
54+
SRC := $(filter-out $(SRCDIR)/$(TBTOP).sv,$(filter-out $(SRCDIR)/$(TOP).sv,$(wildcard $(SRCDIR)/*.sv)))
5555

5656
# Verilog include files for design
5757
INC := $(wildcard $(SRCDIR)/*.svh)
@@ -73,9 +73,7 @@ endif
7373

7474
# Yosys synthesis options
7575
# ("ultraplus" device, enable DSP inferrence and explicitly set top module name)
76-
YOSYS_SYNTH_OPTS := -device u -dsp -top $(TOP)
77-
# NOTE: Options that can often produce a more "optimal" size/speed for design, but slower:
78-
# YOSYS_SYNTH_ARGS := -device u -dsp -abc9 -top $(TOP)
76+
YOSYS_SYNTH_ARGS := -device u -dsp -abc9 -top $(TOP)
7977

8078
# Invokes yosys-config to find the proper path to the iCE40 simulation library
8179
TECH_LIB := $(shell $(YOSYS_CONFIG) --datdir/ice40/cells_sim.v)
@@ -126,7 +124,7 @@ info:
126124
@echo " make clean - clean most files that can be rebuilt"
127125

128126
# defult target is to make FPGA bitstream for design
129-
all: isim bin
127+
all: isim vsim bin
130128

131129
# synthesize FPGA bitstream for design
132130
bin: $(OUTDIR)/$(OUTNAME).bin
@@ -138,22 +136,22 @@ prog: $(OUTDIR)/$(OUTNAME).bin
138136
$(ICEPROG) -d i:0x0403:0x6014 $(OUTDIR)/$(OUTNAME).bin
139137

140138
# run Yosys with "noflatten", which will produce a resource count per module
141-
count: $(SRC) $(INC) $(FONTFILES) $(MAKEFILE_LIST)
139+
count: $(SRCDIR)/$(TOP).sv $(SRC) $(INC) $(FONTFILES) $(MAKEFILE_LIST)
142140
@echo === Couting Design Resources Used ===
143141
@mkdir -p $(LOGS)
144-
$(YOSYS) -l $(LOGS)/$(OUTNAME)_yosys_count.log -w ".*" -q -p 'verilog_defines $(DEFINES) ; read_verilog -I$(SRCDIR) -sv $(SRC) $(FLOW3) ; synth_ice40 $(YOSYS_SYNTH_ARGS) -noflatten'
142+
$(YOSYS) -l $(LOGS)/$(OUTNAME)_yosys_count.log -w ".*" -q -p 'verilog_defines $(DEFINES) ; read_verilog -I$(SRCDIR) -sv $(SRCDIR)/$(TOP).sv $(SRC) $(FLOW3) ; synth_ice40 $(YOSYS_SYNTH_ARGS) -noflatten'
145143
@sed -n '/Printing statistics/,/Executing CHECK pass/p' $(LOGS)/$(OUTNAME)_yosys_count.log | sed '$$d'
146144
@echo === See $(LOGS)/$(OUTNAME)_yosys_count.log for resource use details ===
147145

148146
# use Icarus Verilog to build and run simulation executable
149-
isim: $(OUTDIR)/$(TBOUTNAME) $(TBTOP).sv $(SRC) $(MAKEFILE_LIST)
150-
@echo === Simulation files built, use \"make irun\" to run ===
147+
isim: $(OUTDIR)/$(TBOUTNAME) $(SRCDIR)/$(TBTOP).sv $(SRC) $(MAKEFILE_LIST)
148+
@echo === Icarus Verilog files built, use \"make irun\" to run ===
151149

152150
# use Icarus Verilog to run simulation executable
153151
irun: $(OUTDIR)/$(TBOUTNAME) $(MAKEFILE_LIST)
154152
@echo === Running simulation ===
155153
$(VVP) $(OUTDIR)/$(TBOUTNAME) -fst
156-
@echo === Simulation done, use "gtkwave logs/$(TBTOP).fst" to view waveforms ===
154+
@echo === Icarus Verilog simulation done, use "gtkwave logs/$(TBTOP).fst" to view waveforms ===
157155

158156
# build native simulation executable
159157
vsim: obj_dir/V$(VTOP) $(MAKEFILE_LIST)
@@ -173,25 +171,27 @@ $(OUTDIR)/$(TBOUTNAME): $(TBTOP).sv $(SRC) $(MAKEFILE_LIST)
173171
$(IVERILOG) $(IVERILOG_ARGS) $(DEFINES) -o $@ $(TBTOP).sv $(SRC)
174172

175173
# use Verilator to build native simulation executable
176-
obj_dir/V$(VTOP): $(CSRC) $(INC) $(SRC) $(MAKEFILE_LIST)
177-
$(VERILATOR) $(VERILATOR_ARGS) --cc --exe --trace $(DEFINES) -DEXT_CLK $(CFLAGS) $(LDFLAGS) --top-module $(VTOP) $(TECH_LIB) $(SRC) $(CSRC)
174+
obj_dir/V$(VTOP): $(CSRC) $(INC) $(SRCDIR)/$(TOP).sv $(SRC) $(MAKEFILE_LIST)
175+
$(VERILATOR) $(VERILATOR_ARGS) --cc --exe --trace $(DEFINES) -DEXT_CLK $(CFLAGS) $(LDFLAGS) --top-module $(VTOP) $(TECH_LIB) $(SRCDIR)/$(TOP).sv $(SRC) $(CSRC)
178176
cd obj_dir && make -f V$(VTOP).mk
179177

180178
# synthesize SystemVerilog and create json description
181-
$(OUTDIR)/$(OUTNAME).json: $(SRC) $(INC) $(MAKEFILE_LIST)
179+
$(OUTDIR)/$(OUTNAME).json: $(SRCDIR)/$(TOP).sv $(SRC) $(INC) $(MAKEFILE_LIST)
182180
@echo === Synthesizing design ===
183181
@rm -f $@
184182
@mkdir -p $(OUTDIR)
185183
@mkdir -p $(LOGS)
186-
$(VERILATOR) $(VERILATOR_ARGS) --lint-only $(DEFINES) --top-module $(TOP) $(TECH_LIB) $(SRC) 2>&1 | tee $(LOGS)/$(OUTNAME)_verilator.log
187-
$(YOSYS) -l $(LOGS)/$(OUTNAME)_yosys.log -w ".*" -q -p 'verilog_defines $(DEFINES) ; read_verilog -I$(SRCDIR) -sv $(SRC) $(FLOW3) ; synth_ice40 $(YOSYS_SYNTH_ARGS) -json $@'
184+
$(VERILATOR) $(VERILATOR_ARGS) --lint-only $(DEFINES) --top-module $(TOP) $(TECH_LIB) $(SRCDIR)/$(TOP).sv $(SRC) 2>&1 | tee $(LOGS)/$(OUTNAME)_verilator.log
185+
$(YOSYS) -l $(LOGS)/$(OUTNAME)_yosys.log -w ".*" -q -p 'verilog_defines $(DEFINES) ; read_verilog -I$(SRCDIR) -sv $(SRCDIR)/$(TOP).sv $(SRC) $(FLOW3) ; synth_ice40 $(YOSYS_SYNTH_ARGS) -json $@'
188186

189187
# make ASCII bitstream from JSON description and device parameters
190-
$(OUTDIR)/$(OUTNAME).asc: $(OUTDIR)/$(OUTNAME).json $(PIN_DEF) $(MAKEFILE_LIST)
188+
$(OUTDIR)/$(OUTNAME).bin: $(OUTDIR)/$(OUTNAME).json $(PIN_DEF) $(MAKEFILE_LIST)
191189
@rm -f $@
192190
@mkdir -p $(LOGS)
193191
@mkdir -p $(OUTDIR)
194-
$(NEXTPNR) -l $(LOGS)/$(OUTNAME)_nextpnr.log -q $(NEXTPNR_ARGS) --$(DEVICE) --package $(PACKAGE) --json $< --pcf $(PIN_DEF) --asc $@
192+
$(NEXTPNR) -l $(LOGS)/$(OUTNAME)_nextpnr.log -q $(NEXTPNR_ARGS) --$(DEVICE) --package $(PACKAGE) --json $< --pcf $(PIN_DEF) --asc $(OUTDIR)/$(OUTNAME).asc
193+
$(ICEPACK) $(OUTDIR)/$(OUTNAME).asc $@
194+
@rm $(OUTDIR)/$(OUTNAME).asc
195195
@echo === Synthesis stats for $(OUTNAME) on $(DEVICE) === | tee $(LOGS)/$(OUTNAME)_stats.txt
196196
@-tabbyadm version | grep "Package" | tee -a $(LOGS)/$(OUTNAME)_stats.txt
197197
@$(YOSYS) -V 2>&1 | tee -a $(LOGS)/$(OUTNAME)_stats.txt
@@ -200,11 +200,6 @@ $(OUTDIR)/$(OUTNAME).asc: $(OUTDIR)/$(OUTNAME).json $(PIN_DEF) $(MAKEFILE_LIST)
200200
@grep "Max frequency" $(LOGS)/$(OUTNAME)_nextpnr.log | tail -1 | tee -a $(LOGS)/$(OUTNAME)_stats.txt
201201
@echo
202202

203-
# make binary bitstream from ASCII bitstream
204-
$(OUTDIR)/$(OUTNAME).bin: $(OUTDIR)/$(OUTNAME).asc $(MAKEFILE_LIST)
205-
@rm -f $@
206-
$(ICEPACK) $< $@
207-
208203
# delete all targets that will be re-generated
209204
clean:
210205
rm -f $(OUTDIR)/$(OUTNAME).bin $(OUTDIR)/$(OUTNAME).json $(OUTDIR)/$(OUTNAME).asc $(OUTDIR)/$(TBOUTNAME) $(wildcard obj_dir/*)
@@ -213,4 +208,4 @@ clean:
213208
.SECONDARY:
214209

215210
# inform make about "phony" convenience targets
216-
.PHONY: info all bin prog lint isim irun count clean
211+
.PHONY: all bin prog isim irun vsim vrun count clean

README.md

+15-5
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ example for the UPduino FPGA board using open source tools.
77

88
This example is MIT-0 licensed. This means you are pretty much free to do as
99
you wish with it, including putting your name on it, applying a different
10-
license, modifying it or putting it in your own project.
10+
license, modifying it and/or putting it in your own project.
1111

12-
Supports 640x480, 848x480 (wide screen 480p) and 800x600, with an 8x8 character
13-
set and 1x to 8x pixel repeat. Shown below is 40x20 text (640x480 with H 2x and
14-
V 3x). There is an included "hex" font (showing character number in hex) and
15-
the "retro" Ohio Scientific font with graphic characters (as shown).
12+
This project supports 640x480, 848x480 (wide screen 480p) and 800x600, with an
13+
8x8 character set and 1x to 8x pixel repeat. Shown below is 40x20 text (640x480
14+
with H 2x and V 3x). There is an included "hex" font (showing character number
15+
in hex) and a "retro" Ohio Scientific font with graphic characters (as shown).
1616

1717
![UPduino generating 640x480 8 color display](pics/upduino_video_breadboard.jpg
1818
"Picture of VGA monitor showing character set")
@@ -54,4 +54,14 @@ not mislabelled GND, as the silkscreen is incorrect on some boards - check for
5454
\-----------------/
5555
```
5656

57+
The breadboard pictured is using an
58+
[inexpensive VGA breakout board from Tindie](https://www.tindie.com/products/matzelectronics/vga-adapter-for-raspberry-pi-pico-esp32-etc/)
59+
with 5-bit RGB (hooking up the two high bits of each color to get more
60+
brightness). Any breakout designed for 3.3v should be suitable (FPGA PMOD,
61+
Parallax Propeller etc.).
62+
63+
You can also construct your own VGA breakout with 270 ohm resistors on the red,
64+
green and blue pins (as shown at
65+
[www.fpga4fun.com/PongGame.html](http://www.fpga4fun.com/PongGame.html)).
66+
5767
-Xark <https://hackaday.io/Xark>

0 commit comments

Comments
 (0)