From 65640e7dcc3022a5dfbe006ad5b7cf1fa1a95676 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Fri, 10 Aug 2018 19:40:24 -0400 Subject: [PATCH 01/34] uart: Rework Makefile Most of the changes are documented in the makefile itself. top.v was renamed so we could use a pattern rule for it. This is further documented in the makefile. --- uart_transmission/Makefile | 88 +++++++++++++++++++++-------- uart_transmission/{top.v => uart.v} | 4 +- 2 files changed, 67 insertions(+), 25 deletions(-) rename uart_transmission/{top.v => uart.v} (98%) diff --git a/uart_transmission/Makefile b/uart_transmission/Makefile index dd86769..4db926c 100644 --- a/uart_transmission/Makefile +++ b/uart_transmission/Makefile @@ -1,34 +1,76 @@ -# Project setup -PROJ = uart -BUILD = ./build -DEVICE = 1k -#DEVICE = 8k +# Use := where you can, as it only gets evaluated once +BUILD := build +# ?= allows the user to pass in a device on the command line +DEVICE ?= 1k +#DEVICE ?= 8k ifeq (8k,$(DEVICE)) -FOOTPRINT = ct256 +FOOTPRINT := ct256 else -FOOTPRINT = tq144 +FOOTPRINT := tq144 endif -# Files -FILES = top.v -FILES += uart_trx.v +# VSRC holds verilog sources +VSRC := uart.v uart_trx.v +# SRC holds all source files +SRC := $(VSRC) pinmap_ct256.pcf pinmap_tq144.pcf -.PHONY: all clean burn +.PHONY: all clean burn FORCE -all:$(BUILD)/$(PROJ).bin +all: $(BUILD)/uart.bin -$(BUILD)/$(PROJ).bin: $(FILES) Makefile - # if build folder doesn't exist, create it +# Because our sources/pinmaps depend on the makefile +# all targets will get rebuilt every time the makefile changes +$(SRC): Makefile + touch $@ + +$(BUILD): mkdir -p $(BUILD) - # synthesize using Yosys - yosys -p "synth_ice40 -top top -blif $(BUILD)/$(PROJ).blif" $(FILES) - # Place and route using arachne - arachne-pnr -d $(DEVICE) -P $(FOOTPRINT) -o $(BUILD)/$(PROJ).asc -p pinmap_$(FOOTPRINT).pcf $(BUILD)/$(PROJ).blif - # Convert to bitstream using IcePack - icepack $(BUILD)/$(PROJ).asc $(BUILD)/$(PROJ).bin - -burn: $(BUILD)/$(PROJ).bin + +# First pattern rule creates a .blif from a .v +# We also have an order-only prerequisite on the build dir +# This means it must be created first, but make doesn't care if it's out-of-date +# The timestamp of a directory changes whenever a file within it is created +# So if we didn't ignore it, we would build everything three times +# Quick introduction to make variables: +# $@ current target, what goes to the left of a make rule +# $< First dependency +# $^ all non-order-only dependencies +# $* the stem of an implicit rule -- what % matches in %.blif +$(BUILD)/%.blif: %.v | $(BUILD) + yosys -p "synth_ice40 -top $* -blif $@" $^ + +# We need to add the other source to our main blif +# Otherwise it would never be included +# Since we are only building one target, we could instead not use a pattern rule +# But this would prevent make from figuring out that %.blif is an implicit target +# We could make this .IMPLICIT, but it is useful to keep it so we don't have to recompile on DEVICE change +$(BUILD)/uart.blif: $(VSRC) + +# .PHONY causes targets to be rebuilt every make, and built even if there is an up-to-date file +# Depending on a .PHONY target will cause the rule to be run every time +# but make will pay attention to timestamps and not run further dependencies if the target doesn't get updated +FORCE: + +# We are going to exploit that here to make sure we rebuild if the user changes the value of DEVICE +# We compare the current value of the variable to what is in env +# If they are different, we update the file +# If they are the same we don't +# Anything which depends on $(BUILD)/DEVICE.var will only update if DEVICE changes +$(BUILD)/%.var: FORCE + echo $($*) | cmp - $@ || echo $($*) > $@ + +# Keep .var file around even though they are intermediate targets +.PRECIOUS: $(BUILD)/%.var + +# Note that yosys does not run if you only change DEVICE, just things from here down +%.asc: %.blif pinmap_$(FOOTPRINT).pcf $(BUILD)/DEVICE.var $(BUILD)/FOOTPRINT.var + arachne-pnr -d $(DEVICE) -P $(FOOTPRINT) -o $@ -p pinmap_$(FOOTPRINT).pcf $< + +%.bin: %.asc + icepack $< $@ + +burn: $(BUILD)/uart.bin iceprog $< clean: - rm -f build/* + rm -rf $(BUILD) diff --git a/uart_transmission/top.v b/uart_transmission/uart.v similarity index 98% rename from uart_transmission/top.v rename to uart_transmission/uart.v index 6560154..d50841d 100644 --- a/uart_transmission/top.v +++ b/uart_transmission/uart.v @@ -1,5 +1,5 @@ /* Top level module for keypad + UART demo */ -module top ( +module uart ( // input hardware clock (12 MHz) hwclk, // all LEDs @@ -86,4 +86,4 @@ module top ( end end -endmodule \ No newline at end of file +endmodule From 8576d6d4bbd0eddbb50e96326e3b2cdc34355b9e Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Fri, 10 Aug 2018 20:54:31 -0400 Subject: [PATCH 02/34] Rename port files This allows us to use the correct port file via an implicit rule. They both need to be named using the same prefix as the .bin file. There doesn't seem to be a way around this. --- uart_transmission/Makefile | 9 ++++++--- uart_transmission/{pinmap_ct256.pcf => uart_ct256.pcf} | 0 uart_transmission/{pinmap_tq144.pcf => uart_tq144.pcf} | 0 3 files changed, 6 insertions(+), 3 deletions(-) rename uart_transmission/{pinmap_ct256.pcf => uart_ct256.pcf} (100%) rename uart_transmission/{pinmap_tq144.pcf => uart_tq144.pcf} (100%) diff --git a/uart_transmission/Makefile b/uart_transmission/Makefile index 4db926c..68e459e 100644 --- a/uart_transmission/Makefile +++ b/uart_transmission/Makefile @@ -12,7 +12,7 @@ endif # VSRC holds verilog sources VSRC := uart.v uart_trx.v # SRC holds all source files -SRC := $(VSRC) pinmap_ct256.pcf pinmap_tq144.pcf +SRC := $(VSRC) uart_ct256.pcf uart_tq144.pcf .PHONY: all clean burn FORCE @@ -62,9 +62,12 @@ $(BUILD)/%.var: FORCE # Keep .var file around even though they are intermediate targets .PRECIOUS: $(BUILD)/%.var +$(BUILD)/%: % + cp -f $< $@ + # Note that yosys does not run if you only change DEVICE, just things from here down -%.asc: %.blif pinmap_$(FOOTPRINT).pcf $(BUILD)/DEVICE.var $(BUILD)/FOOTPRINT.var - arachne-pnr -d $(DEVICE) -P $(FOOTPRINT) -o $@ -p pinmap_$(FOOTPRINT).pcf $< +%.asc: %.blif %_$(FOOTPRINT).pcf $(BUILD)/DEVICE.var $(BUILD)/FOOTPRINT.var + arachne-pnr -d $(DEVICE) -P $(FOOTPRINT) -o $@ -p $*_$(FOOTPRINT).pcf $< %.bin: %.asc icepack $< $@ diff --git a/uart_transmission/pinmap_ct256.pcf b/uart_transmission/uart_ct256.pcf similarity index 100% rename from uart_transmission/pinmap_ct256.pcf rename to uart_transmission/uart_ct256.pcf diff --git a/uart_transmission/pinmap_tq144.pcf b/uart_transmission/uart_tq144.pcf similarity index 100% rename from uart_transmission/pinmap_tq144.pcf rename to uart_transmission/uart_tq144.pcf From b71339d14b2992f281bc9c989d7af5d966b5199c Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Fri, 10 Aug 2018 21:06:48 -0400 Subject: [PATCH 03/34] Create a top-level makefile Most of the functionality in each project is the same. We can get away with some pattern rules and modifying a few variables in each subproject. --- Makefile | 74 +++++++++++++++++++++++++++++++++ uart_transmission/Makefile | 83 +++++--------------------------------- 2 files changed, 84 insertions(+), 73 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1b96fef --- /dev/null +++ b/Makefile @@ -0,0 +1,74 @@ +# Use := where you can, as it only gets evaluated once +BUILD := build +# ?= allows the user to pass in a device on the command line +DEVICE ?= 1k +#DEVICE ?= 8k +ifeq (8k,$(DEVICE)) +FOOTPRINT := ct256 +else +FOOTPRINT := tq144 +endif + +MODULES := uart_transmission + +# SRC holds all source files +SRC := + +.PHONY: all clean burn-% FORCE + +all: $(MODULES) + +# Because our sources/pinmaps depend on the makefile +# all targets will get rebuilt every time the makefile changes +$(SRC): Makefile + touch $@ + +$(BUILD): + mkdir -p $(BUILD) + +# First pattern rule creates a .blif from a .v +# We also have an order-only prerequisite on the build dir +# This means it must be created first, but make doesn't care if it's out-of-date +# The timestamp of a directory changes whenever a file within it is created +# So if we didn't ignore it, we would build everything three times +# Quick introduction to make variables: +# $@ current target, what goes to the left of a make rule +# $< First dependency +# $^ all non-order-only dependencies +# $* the stem of an implicit rule -- what % matches in %.blif +$(BUILD)/%.blif: %.v | $(BUILD) + yosys -p "synth_ice40 -top $* -blif $@" $^ + +# .PHONY causes targets to be rebuilt every make, and built even if there is an up-to-date file +# Depending on a .PHONY target will cause the rule to be run every time +# but make will pay attention to timestamps and not run further dependencies if the target doesn't get updated +FORCE: + +# We are going to exploit that here to make sure we rebuild if the user changes the value of DEVICE +# We compare the current value of the variable to what is in env +# If they are different, we update the file +# If they are the same we don't +# Anything which depends on $(BUILD)/DEVICE.var will only update if DEVICE changes +$(BUILD)/%.var: FORCE + echo $($*) | cmp - $@ || echo $($*) > $@ + +# Keep .var file around even though they are intermediate targets +.PRECIOUS: $(BUILD)/%.var + +$(BUILD)/%: % + cp -f $< $@ + +# Note that yosys does not run if you only change DEVICE, just things from here down +%.asc: %.blif %_$(FOOTPRINT).pcf $(BUILD)/DEVICE.var $(BUILD)/FOOTPRINT.var + arachne-pnr -d $(DEVICE) -P $(FOOTPRINT) -o $@ -p $*_$(FOOTPRINT).pcf $< + +%.bin: %.asc + icepack $< $@ + +burn-%: $(BUILD)/%.bin + iceprog $< + +clean: + rm -rf $(BUILD) + +include $(addsuffix /Makefile,$(MODULES)) diff --git a/uart_transmission/Makefile b/uart_transmission/Makefile index 68e459e..ec1e3c9 100644 --- a/uart_transmission/Makefile +++ b/uart_transmission/Makefile @@ -1,79 +1,16 @@ -# Use := where you can, as it only gets evaluated once -BUILD := build -# ?= allows the user to pass in a device on the command line -DEVICE ?= 1k -#DEVICE ?= 8k -ifeq (8k,$(DEVICE)) -FOOTPRINT := ct256 -else -FOOTPRINT := tq144 -endif +UART := uart_transmission -# VSRC holds verilog sources -VSRC := uart.v uart_trx.v -# SRC holds all source files -SRC := $(VSRC) uart_ct256.pcf uart_tq144.pcf +VPATH += $(UART) -.PHONY: all clean burn FORCE +UART_VSRC := $(addprefix $(UART)/,uart.v uart_trx.v) +UART_SRC := $(UART_VSRC) $(addprefix $(UART)/,uart_ct256.pcf uart_tq144.pcf) +SRC += $(UART_SRC) -all: $(BUILD)/uart.bin +.PHONY: $(UART) -# Because our sources/pinmaps depend on the makefile -# all targets will get rebuilt every time the makefile changes -$(SRC): Makefile - touch $@ - -$(BUILD): - mkdir -p $(BUILD) - -# First pattern rule creates a .blif from a .v -# We also have an order-only prerequisite on the build dir -# This means it must be created first, but make doesn't care if it's out-of-date -# The timestamp of a directory changes whenever a file within it is created -# So if we didn't ignore it, we would build everything three times -# Quick introduction to make variables: -# $@ current target, what goes to the left of a make rule -# $< First dependency -# $^ all non-order-only dependencies -# $* the stem of an implicit rule -- what % matches in %.blif -$(BUILD)/%.blif: %.v | $(BUILD) - yosys -p "synth_ice40 -top $* -blif $@" $^ - -# We need to add the other source to our main blif -# Otherwise it would never be included -# Since we are only building one target, we could instead not use a pattern rule -# But this would prevent make from figuring out that %.blif is an implicit target -# We could make this .IMPLICIT, but it is useful to keep it so we don't have to recompile on DEVICE change -$(BUILD)/uart.blif: $(VSRC) - -# .PHONY causes targets to be rebuilt every make, and built even if there is an up-to-date file -# Depending on a .PHONY target will cause the rule to be run every time -# but make will pay attention to timestamps and not run further dependencies if the target doesn't get updated -FORCE: - -# We are going to exploit that here to make sure we rebuild if the user changes the value of DEVICE -# We compare the current value of the variable to what is in env -# If they are different, we update the file -# If they are the same we don't -# Anything which depends on $(BUILD)/DEVICE.var will only update if DEVICE changes -$(BUILD)/%.var: FORCE - echo $($*) | cmp - $@ || echo $($*) > $@ +$(UART): $(BUILD)/uart.bin -# Keep .var file around even though they are intermediate targets -.PRECIOUS: $(BUILD)/%.var - -$(BUILD)/%: % - cp -f $< $@ - -# Note that yosys does not run if you only change DEVICE, just things from here down -%.asc: %.blif %_$(FOOTPRINT).pcf $(BUILD)/DEVICE.var $(BUILD)/FOOTPRINT.var - arachne-pnr -d $(DEVICE) -P $(FOOTPRINT) -o $@ -p $*_$(FOOTPRINT).pcf $< - -%.bin: %.asc - icepack $< $@ - -burn: $(BUILD)/uart.bin - iceprog $< +$(UART_SRC): $(UART)/Makefile + touch $@ -clean: - rm -rf $(BUILD) +$(BUILD)/uart.blif: $(UART_VSRC) From 86dabb976712870f4f5e30de575d15bbad5cf4e5 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Fri, 10 Aug 2018 23:18:46 -0400 Subject: [PATCH 04/34] Change default device to 8k Most of the other projects have only 8k pinmaps --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 1b96fef..8dde143 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,7 @@ # Use := where you can, as it only gets evaluated once BUILD := build # ?= allows the user to pass in a device on the command line -DEVICE ?= 1k -#DEVICE ?= 8k +DEVICE ?= 8k ifeq (8k,$(DEVICE)) FOOTPRINT := ct256 else From 069082aabddfd0a208f09554c569159554881cf4 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Fri, 10 Aug 2018 23:24:33 -0400 Subject: [PATCH 05/34] blank: Use top-level makefile --- Makefile | 2 +- blank/Makefile | 32 +++++++++------------------ blank/{top.v => blank.v} | 2 +- blank/{pinmap.pcf => blank_ct256.pcf} | 0 4 files changed, 13 insertions(+), 23 deletions(-) rename blank/{top.v => blank.v} (76%) rename blank/{pinmap.pcf => blank_ct256.pcf} (100%) diff --git a/Makefile b/Makefile index 8dde143..5b1bd11 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ else FOOTPRINT := tq144 endif -MODULES := uart_transmission +MODULES := uart_transmission blank # SRC holds all source files SRC := diff --git a/blank/Makefile b/blank/Makefile index 8a1f8ac..0060ebe 100644 --- a/blank/Makefile +++ b/blank/Makefile @@ -1,26 +1,16 @@ -# Project setup -PROJ = blank -BUILD = ./build -DEVICE = 8k -FOOTPRINT = ct256 +BLANK := blank -# Files -FILES = top.v +VPATH += blank -.PHONY: all clean burn +BLANK_VSRC := $(addprefix $(BLANK)/,$(BLANK).v) +BLANK_SRC := $(BLANK_VSRC) $(addprefix $(BLANK)/,$(BLANK)_ct256.pcf) +SRC += $(BLANK_SRC) -all: - # if build folder doesn't exist, create it - mkdir -p $(BUILD) - # synthesize using Yosys - yosys -p "synth_ice40 -top top -blif $(BUILD)/$(PROJ).blif" $(FILES) - # Place and route using arachne - arachne-pnr -d $(DEVICE) -P $(FOOTPRINT) -o $(BUILD)/$(PROJ).asc -p pinmap.pcf $(BUILD)/$(PROJ).blif - # Convert to bitstream using IcePack - icepack $(BUILD)/$(PROJ).asc $(BUILD)/$(PROJ).bin +.PHONY: $(BLANK) -burn: - iceprog $(BUILD)/$(PROJ).bin +blank: $(BUILD)/$(BLANK).bin -clean: - rm build/* +$(BLANK_SRC): $(BLANK)/Makefile + touch $@ + +$(BUILD)/$(BLANK).blif: $(BLANK_VSRC) diff --git a/blank/top.v b/blank/blank.v similarity index 76% rename from blank/top.v rename to blank/blank.v index 130b3da..69cc3e1 100644 --- a/blank/top.v +++ b/blank/blank.v @@ -1,6 +1,6 @@ // Blink an LED provided an input clock /* module */ -module top (hwclk, led1, led2, led3, led4, led5, led6, led7, led8 ); +module blank (hwclk, led1, led2, led3, led4, led5, led6, led7, led8 ); /* I/O */ input hwclk; output led1; diff --git a/blank/pinmap.pcf b/blank/blank_ct256.pcf similarity index 100% rename from blank/pinmap.pcf rename to blank/blank_ct256.pcf From e919c073977782643e6a6e0ba520d96adb848550 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Fri, 10 Aug 2018 23:28:05 -0400 Subject: [PATCH 06/34] blinky: Use top-level makefile --- Makefile | 2 +- blinky/Makefile | 30 ++++++++----------------- blinky/{top.v => blinky.v} | 4 ++-- blinky/{pinmap.pcf => blinky_ct256.pcf} | 0 4 files changed, 12 insertions(+), 24 deletions(-) rename blinky/{top.v => blinky.v} (88%) rename blinky/{pinmap.pcf => blinky_ct256.pcf} (100%) diff --git a/Makefile b/Makefile index 5b1bd11..be91d74 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ else FOOTPRINT := tq144 endif -MODULES := uart_transmission blank +MODULES := uart_transmission blank blinky # SRC holds all source files SRC := diff --git a/blinky/Makefile b/blinky/Makefile index 4f906f7..756f89e 100644 --- a/blinky/Makefile +++ b/blinky/Makefile @@ -1,26 +1,14 @@ -# Project setup -PROJ = blinky -BUILD = ./build -DEVICE = 8k -FOOTPRINT = ct256 +VPATH += blinky -# Files -FILES = top.v +BLINKY_VSRC := blinky/blinky.v +BLINKY_SRC := $(BLINKY_VSRC) blinky/blinky_ct256.pcf +SRC += $(BLINKY_SRC) -.PHONY: all clean burn +.PHONY: blinky -all: - # if build folder doesn't exist, create it - mkdir -p $(BUILD) - # synthesize using Yosys - yosys -p "synth_ice40 -top top -blif $(BUILD)/$(PROJ).blif" $(FILES) - # Place and route using arachne - arachne-pnr -d $(DEVICE) -P $(FOOTPRINT) -o $(BUILD)/$(PROJ).asc -p pinmap.pcf $(BUILD)/$(PROJ).blif - # Convert to bitstream using IcePack - icepack $(BUILD)/$(PROJ).asc $(BUILD)/$(PROJ).bin +blinky: $(BUILD)/blinky.bin -burn: - iceprog $(BUILD)/$(PROJ).bin +$(BLINKY_SRC): blinky/Makefile + touch $@ -clean: - rm build/* +$(BUILD)/blinky.blif: $(BLINKY_VSRC) diff --git a/blinky/top.v b/blinky/blinky.v similarity index 88% rename from blinky/top.v rename to blinky/blinky.v index f4e8585..b1e537f 100644 --- a/blinky/top.v +++ b/blinky/blinky.v @@ -1,6 +1,6 @@ // Blink an LED provided an input clock /* module */ -module top (hwclk, led1, led2, led3, led4, led5, led6, led7, led8 ); +module blinky (hwclk, led1, led2, led3, led4, led5, led6, led7, led8 ); /* I/O */ input hwclk; output led1; @@ -30,4 +30,4 @@ module top (hwclk, led1, led2, led3, led4, led5, led6, led7, led8 ); counter <= counter + 1; end -endmodule \ No newline at end of file +endmodule diff --git a/blinky/pinmap.pcf b/blinky/blinky_ct256.pcf similarity index 100% rename from blinky/pinmap.pcf rename to blinky/blinky_ct256.pcf From ce2b234d3ee503410304a5fcb948cd5fd955bdc1 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Fri, 10 Aug 2018 23:39:27 -0400 Subject: [PATCH 07/34] buttons_bounce: Use top-level makefile --- Makefile | 2 +- buttons_bounce/Makefile | 32 +++++++------------ buttons_bounce/{top.v => buttons_bounce.v} | 4 +-- .../{pinmap.pcf => buttons_bounce_ct256.pcf} | 0 4 files changed, 14 insertions(+), 24 deletions(-) rename buttons_bounce/{top.v => buttons_bounce.v} (96%) rename buttons_bounce/{pinmap.pcf => buttons_bounce_ct256.pcf} (100%) diff --git a/Makefile b/Makefile index be91d74..e389c9d 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ else FOOTPRINT := tq144 endif -MODULES := uart_transmission blank blinky +MODULES := uart_transmission blank blinky buttons_bounce # SRC holds all source files SRC := diff --git a/buttons_bounce/Makefile b/buttons_bounce/Makefile index 894e38f..52a2f0e 100644 --- a/buttons_bounce/Makefile +++ b/buttons_bounce/Makefile @@ -1,26 +1,16 @@ -# Project setup -PROJ = buttons -BUILD = ./build -DEVICE = 8k -FOOTPRINT = ct256 +BBOUNCE := buttons_bounce -# Files -FILES = top.v +VPATH += $(BBOUNCE) -.PHONY: all clean burn +BBOUNCE_VSRC := $(BBOUNCE)/$(BBOUNCE).v +BBOUNCE_SRC := $(BBOUNCE_VSRC) $(BBOUNCE)/$(BBOUNCE)_ct256.pcf +SRC += $(BBOUNCE_SRC) -all: - # if build folder doesn't exist, create it - mkdir -p $(BUILD) - # synthesize using Yosys - yosys -p "synth_ice40 -top top -blif $(BUILD)/$(PROJ).blif" $(FILES) - # Place and route using arachne - arachne-pnr -d $(DEVICE) -P $(FOOTPRINT) -o $(BUILD)/$(PROJ).asc -p pinmap.pcf $(BUILD)/$(PROJ).blif - # Convert to bitstream using IcePack - icepack $(BUILD)/$(PROJ).asc $(BUILD)/$(PROJ).bin +.PHONY: $(BBOUNCE) -burn: - iceprog $(BUILD)/$(PROJ).bin +$(BBOUNCE): $(BUILD)/$(BBOUNCE).bin -clean: - rm build/* +$(BBOUNCE_SRC): $(BBOUNCE)/Makefile + touch $@ + +$(BUILD)/$(BBOUNCE).blif: $(BBOUNCE_VSRC) diff --git a/buttons_bounce/top.v b/buttons_bounce/buttons_bounce.v similarity index 96% rename from buttons_bounce/top.v rename to buttons_bounce/buttons_bounce.v index 640e6f0..7c19207 100644 --- a/buttons_bounce/top.v +++ b/buttons_bounce/buttons_bounce.v @@ -2,7 +2,7 @@ (not a good way of doing things!) This uses button 1 of the keypad when installed correctly. */ -module top ( +module buttons_bounce ( // input hardware clock (12 MHz) hwclk, // LED @@ -49,4 +49,4 @@ module top ( end -endmodule \ No newline at end of file +endmodule diff --git a/buttons_bounce/pinmap.pcf b/buttons_bounce/buttons_bounce_ct256.pcf similarity index 100% rename from buttons_bounce/pinmap.pcf rename to buttons_bounce/buttons_bounce_ct256.pcf From fc0e52b0de4edbbc17a52dddbb97f77db595c97d Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Fri, 10 Aug 2018 23:47:53 -0400 Subject: [PATCH 08/34] buttons_debounce: Use top-level makefile --- Makefile | 2 +- buttons_debounce/Makefile | 32 +++++++------------ .../{top.v => buttons_debounce.v} | 4 +-- ...{pinmap.pcf => buttons_debounce_ct256.pcf} | 0 4 files changed, 14 insertions(+), 24 deletions(-) rename buttons_debounce/{top.v => buttons_debounce.v} (98%) rename buttons_debounce/{pinmap.pcf => buttons_debounce_ct256.pcf} (100%) diff --git a/Makefile b/Makefile index e389c9d..1f997f4 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ else FOOTPRINT := tq144 endif -MODULES := uart_transmission blank blinky buttons_bounce +MODULES := uart_transmission blank blinky buttons_bounce buttons_debounce # SRC holds all source files SRC := diff --git a/buttons_debounce/Makefile b/buttons_debounce/Makefile index 894e38f..f9a1566 100644 --- a/buttons_debounce/Makefile +++ b/buttons_debounce/Makefile @@ -1,26 +1,16 @@ -# Project setup -PROJ = buttons -BUILD = ./build -DEVICE = 8k -FOOTPRINT = ct256 +BDEBOUNCE := buttons_debounce -# Files -FILES = top.v +VPATH += $(BDEBOUNCE) -.PHONY: all clean burn +BDEBOUNCE_VSRC := $(BDEBOUNCE)/$(BDEBOUNCE).v +BDEBOUNCE_SRC := $(BDEBOUNCE_VSRC) $(BDEBOUNCE)/$(BDEBOUNCE)_ct256.pcf +SRC += $(BDEBOUNCE_SRC) -all: - # if build folder doesn't exist, create it - mkdir -p $(BUILD) - # synthesize using Yosys - yosys -p "synth_ice40 -top top -blif $(BUILD)/$(PROJ).blif" $(FILES) - # Place and route using arachne - arachne-pnr -d $(DEVICE) -P $(FOOTPRINT) -o $(BUILD)/$(PROJ).asc -p pinmap.pcf $(BUILD)/$(PROJ).blif - # Convert to bitstream using IcePack - icepack $(BUILD)/$(PROJ).asc $(BUILD)/$(PROJ).bin +.PHONY: $(BDEBOUNCE) -burn: - iceprog $(BUILD)/$(PROJ).bin +$(BDEBOUNCE): $(BUILD)/$(BDEBOUNCE).bin -clean: - rm build/* +$(BDEBOUNCE_SRC): $(BDEBOUNCE)/Makefile + touch $@ + +$(BUILD)/$(BDEBOUNCE).blif: $(BDEBOUNCE_VSRC) diff --git a/buttons_debounce/top.v b/buttons_debounce/buttons_debounce.v similarity index 98% rename from buttons_debounce/top.v rename to buttons_debounce/buttons_debounce.v index d00fe0d..08b7bc6 100644 --- a/buttons_debounce/top.v +++ b/buttons_debounce/buttons_debounce.v @@ -1,7 +1,7 @@ /* Top level module for button demo WITH debouncing This uses button 1 of the keypad when installed correctly. */ -module top ( +module buttons_debounce ( // input hardware clock (12 MHz) hwclk, // LED @@ -67,4 +67,4 @@ module top ( end -endmodule \ No newline at end of file +endmodule diff --git a/buttons_debounce/pinmap.pcf b/buttons_debounce/buttons_debounce_ct256.pcf similarity index 100% rename from buttons_debounce/pinmap.pcf rename to buttons_debounce/buttons_debounce_ct256.pcf From c41cda41cd4c56b3337f640d7cbd499ba80bb973 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Fri, 10 Aug 2018 23:53:27 -0400 Subject: [PATCH 09/34] buttons_nopullup: Use top-level makefile --- Makefile | 2 +- buttons_nopullup/Makefile | 32 +++++++------------ .../{top.v => buttons_nopullup.v} | 4 +-- ...{pinmap.pcf => buttons_nopullup_ct256.pcf} | 0 4 files changed, 14 insertions(+), 24 deletions(-) rename buttons_nopullup/{top.v => buttons_nopullup.v} (95%) rename buttons_nopullup/{pinmap.pcf => buttons_nopullup_ct256.pcf} (100%) diff --git a/Makefile b/Makefile index 1f997f4..8e88002 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ else FOOTPRINT := tq144 endif -MODULES := uart_transmission blank blinky buttons_bounce buttons_debounce +MODULES := uart_transmission blank blinky buttons_bounce buttons_debounce buttons_nopullup # SRC holds all source files SRC := diff --git a/buttons_nopullup/Makefile b/buttons_nopullup/Makefile index 894e38f..9107db3 100644 --- a/buttons_nopullup/Makefile +++ b/buttons_nopullup/Makefile @@ -1,26 +1,16 @@ -# Project setup -PROJ = buttons -BUILD = ./build -DEVICE = 8k -FOOTPRINT = ct256 +BNOPULLUP := buttons_nopullup -# Files -FILES = top.v +VPATH += $(BNOPULLUP) -.PHONY: all clean burn +BNOPULLUP_VSRC := $(BNOPULLUP)/$(BNOPULLUP).v +BNOPULLUP_SRC := $(BNOPULLUP_VSRC) $(BNOPULLUP)/$(BNOPULLUP)_ct256.pcf +SRC += $(BNOPULLUP_SRC) -all: - # if build folder doesn't exist, create it - mkdir -p $(BUILD) - # synthesize using Yosys - yosys -p "synth_ice40 -top top -blif $(BUILD)/$(PROJ).blif" $(FILES) - # Place and route using arachne - arachne-pnr -d $(DEVICE) -P $(FOOTPRINT) -o $(BUILD)/$(PROJ).asc -p pinmap.pcf $(BUILD)/$(PROJ).blif - # Convert to bitstream using IcePack - icepack $(BUILD)/$(PROJ).asc $(BUILD)/$(PROJ).bin +.PHONY: $(BNOPULLUP) -burn: - iceprog $(BUILD)/$(PROJ).bin +$(BNOPULLUP): $(BUILD)/$(BNOPULLUP).bin -clean: - rm build/* +$(BNOPULLUP_SRC): $(BNOPULLUP)/Makefile + touch $@ + +$(BUILD)/$(BNOPULLUP).blif: $(BNOPULLUP_VSRC) diff --git a/buttons_nopullup/top.v b/buttons_nopullup/buttons_nopullup.v similarity index 95% rename from buttons_nopullup/top.v rename to buttons_nopullup/buttons_nopullup.v index e6cc188..d2a16b7 100644 --- a/buttons_nopullup/top.v +++ b/buttons_nopullup/buttons_nopullup.v @@ -1,7 +1,7 @@ /* Top level module for button demo without debouncing and with no pull-up resistor (not a good way of doing things!) */ -module top ( +module buttons_nopullup ( // input hardware clock (12 MHz) hwclk, // LED @@ -37,4 +37,4 @@ module top ( end -endmodule \ No newline at end of file +endmodule diff --git a/buttons_nopullup/pinmap.pcf b/buttons_nopullup/buttons_nopullup_ct256.pcf similarity index 100% rename from buttons_nopullup/pinmap.pcf rename to buttons_nopullup/buttons_nopullup_ct256.pcf From c4f08205b4ef14478e142a8c317b06cca9f1c20c Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Fri, 10 Aug 2018 23:59:39 -0400 Subject: [PATCH 10/34] fsm_simple: Use top-level makefile --- Makefile | 2 +- fsm_simple/Makefile | 33 ++++++++---------------- fsm_simple/{top.v => fsm.v} | 4 +-- fsm_simple/{pinmap.pcf => fsm_ct256.pcf} | 0 4 files changed, 14 insertions(+), 25 deletions(-) rename fsm_simple/{top.v => fsm.v} (99%) rename fsm_simple/{pinmap.pcf => fsm_ct256.pcf} (100%) diff --git a/Makefile b/Makefile index 8e88002..60e05b2 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ else FOOTPRINT := tq144 endif -MODULES := uart_transmission blank blinky buttons_bounce buttons_debounce buttons_nopullup +MODULES := uart_transmission blank blinky buttons_bounce buttons_debounce buttons_nopullup fsm_simple # SRC holds all source files SRC := diff --git a/fsm_simple/Makefile b/fsm_simple/Makefile index 8320eb9..8021c43 100644 --- a/fsm_simple/Makefile +++ b/fsm_simple/Makefile @@ -1,27 +1,16 @@ -# Project setup -PROJ = fsm -BUILD = ./build -DEVICE = 8k -FOOTPRINT = ct256 +FSM := fsm_simple -# Files -FILES = top.v -FILES += button.v +VPATH += $(FSM) -.PHONY: all clean burn +FSM_VSRC := $(addprefix $(FSM)/,fsm.v button.v) +FSM_SRC := $(FSM_VSRC) $(FSM)/fsm_ct256.pcf +SRC += $(FSM_SRC) -all: - # if build folder doesn't exist, create it - mkdir -p $(BUILD) - # synthesize using Yosys - yosys -p "synth_ice40 -top top -blif $(BUILD)/$(PROJ).blif" $(FILES) - # Place and route using arachne - arachne-pnr -d $(DEVICE) -P $(FOOTPRINT) -o $(BUILD)/$(PROJ).asc -p pinmap.pcf $(BUILD)/$(PROJ).blif - # Convert to bitstream using IcePack - icepack $(BUILD)/$(PROJ).asc $(BUILD)/$(PROJ).bin +.PHONY: $(FSM) -burn: - iceprog $(BUILD)/$(PROJ).bin +$(FSM): $(BUILD)/fsm.bin -clean: - rm build/* +$(FSM_SRC): $(FSM)/Makefile + touch $@ + +$(BUILD)/fsm.blif: $(FSM_VSRC) diff --git a/fsm_simple/top.v b/fsm_simple/fsm.v similarity index 99% rename from fsm_simple/top.v rename to fsm_simple/fsm.v index 38bc28a..81699f4 100644 --- a/fsm_simple/top.v +++ b/fsm_simple/fsm.v @@ -1,7 +1,7 @@ /* Top level module for button demo WITH debouncing This uses button 1 of the keypad when installed correctly. */ -module top ( +module fsm ( // input hardware clock (12 MHz) hwclk, // LED @@ -116,4 +116,4 @@ module top ( endcase end -endmodule \ No newline at end of file +endmodule diff --git a/fsm_simple/pinmap.pcf b/fsm_simple/fsm_ct256.pcf similarity index 100% rename from fsm_simple/pinmap.pcf rename to fsm_simple/fsm_ct256.pcf From 8b410d54889caffbc0c3345afa89a6c3f7ae55e7 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Sat, 11 Aug 2018 00:01:05 -0400 Subject: [PATCH 11/34] Remove unneeded .gitignores --- .gitignore | 2 ++ blank/.gitignore | 1 - blinky/.gitignore | 1 - buttons_bounce/.gitignore | 1 - buttons_debounce/.gitignore | 1 - buttons_nopullup/.gitignore | 1 - fsm_simple/.gitignore | 1 - uart_transmission/.gitignore | 1 - 8 files changed, 2 insertions(+), 7 deletions(-) delete mode 100644 blank/.gitignore delete mode 100644 blinky/.gitignore delete mode 100644 buttons_bounce/.gitignore delete mode 100644 buttons_debounce/.gitignore delete mode 100644 buttons_nopullup/.gitignore delete mode 100644 fsm_simple/.gitignore delete mode 100644 uart_transmission/.gitignore diff --git a/.gitignore b/.gitignore index b419f14..9fc29cf 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,5 @@ # matlab storage files *.mat + +build diff --git a/blank/.gitignore b/blank/.gitignore deleted file mode 100644 index a007fea..0000000 --- a/blank/.gitignore +++ /dev/null @@ -1 +0,0 @@ -build/* diff --git a/blinky/.gitignore b/blinky/.gitignore deleted file mode 100644 index a007fea..0000000 --- a/blinky/.gitignore +++ /dev/null @@ -1 +0,0 @@ -build/* diff --git a/buttons_bounce/.gitignore b/buttons_bounce/.gitignore deleted file mode 100644 index a007fea..0000000 --- a/buttons_bounce/.gitignore +++ /dev/null @@ -1 +0,0 @@ -build/* diff --git a/buttons_debounce/.gitignore b/buttons_debounce/.gitignore deleted file mode 100644 index a007fea..0000000 --- a/buttons_debounce/.gitignore +++ /dev/null @@ -1 +0,0 @@ -build/* diff --git a/buttons_nopullup/.gitignore b/buttons_nopullup/.gitignore deleted file mode 100644 index a007fea..0000000 --- a/buttons_nopullup/.gitignore +++ /dev/null @@ -1 +0,0 @@ -build/* diff --git a/fsm_simple/.gitignore b/fsm_simple/.gitignore deleted file mode 100644 index a007fea..0000000 --- a/fsm_simple/.gitignore +++ /dev/null @@ -1 +0,0 @@ -build/* diff --git a/uart_transmission/.gitignore b/uart_transmission/.gitignore deleted file mode 100644 index a007fea..0000000 --- a/uart_transmission/.gitignore +++ /dev/null @@ -1 +0,0 @@ -build/* From 8848a684653b9603f6a7ad7035d06358d9568bfb Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Sat, 11 Aug 2018 00:18:49 -0400 Subject: [PATCH 12/34] Allow makefiles to be run in the same directory Previously you could only build from the base directory. Now we just run make on the top-level makefile if a sub-makefile gets used directly. --- blank/Makefile | 13 +++++++++++++ blinky/Makefile | 13 +++++++++++++ buttons_bounce/Makefile | 13 +++++++++++++ buttons_debounce/Makefile | 13 +++++++++++++ buttons_nopullup/Makefile | 13 +++++++++++++ fsm_simple/Makefile | 13 +++++++++++++ uart_transmission/Makefile | 13 +++++++++++++ 7 files changed, 91 insertions(+) diff --git a/blank/Makefile b/blank/Makefile index 0060ebe..1a9844d 100644 --- a/blank/Makefile +++ b/blank/Makefile @@ -1,5 +1,18 @@ BLANK := blank +ifndef BUILD +.PHONY: all burn clean + +all: + $(MAKE) -C .. $(BLANK) + +burn: + $(MAKE) -C .. burn-$(BLANK) + +clean: + $(MAKE) -C .. $@ +endif + VPATH += blank BLANK_VSRC := $(addprefix $(BLANK)/,$(BLANK).v) diff --git a/blinky/Makefile b/blinky/Makefile index 756f89e..1d413e2 100644 --- a/blinky/Makefile +++ b/blinky/Makefile @@ -1,3 +1,16 @@ +ifndef BUILD +.PHONY: all burn clean + +all: + $(MAKE) -C .. blinky + +burn: + $(MAKE) -C .. burn-blinky + +clean: + $(MAKE) -C .. $@ +endif + VPATH += blinky BLINKY_VSRC := blinky/blinky.v diff --git a/buttons_bounce/Makefile b/buttons_bounce/Makefile index 52a2f0e..6224db5 100644 --- a/buttons_bounce/Makefile +++ b/buttons_bounce/Makefile @@ -1,5 +1,18 @@ BBOUNCE := buttons_bounce +ifndef BUILD +.PHONY: all burn clean + +all: + $(MAKE) -C .. $(BBOUNCE) + +burn: + $(MAKE) -C .. burn-$(BBOUNCE) + +clean: + $(MAKE) -C .. $@ +endif + VPATH += $(BBOUNCE) BBOUNCE_VSRC := $(BBOUNCE)/$(BBOUNCE).v diff --git a/buttons_debounce/Makefile b/buttons_debounce/Makefile index f9a1566..4398b69 100644 --- a/buttons_debounce/Makefile +++ b/buttons_debounce/Makefile @@ -1,5 +1,18 @@ BDEBOUNCE := buttons_debounce +ifndef BUILD +.PHONY: all burn clean + +all: + $(MAKE) -C .. $(BDEBOUNCE) + +burn: + $(MAKE) -C .. burn-$(BDEBOUNCE) + +clean: + $(MAKE) -C .. $@ +endif + VPATH += $(BDEBOUNCE) BDEBOUNCE_VSRC := $(BDEBOUNCE)/$(BDEBOUNCE).v diff --git a/buttons_nopullup/Makefile b/buttons_nopullup/Makefile index 9107db3..b1f43f8 100644 --- a/buttons_nopullup/Makefile +++ b/buttons_nopullup/Makefile @@ -1,5 +1,18 @@ BNOPULLUP := buttons_nopullup +ifndef BUILD +.PHONY: all burn clean + +all: + $(MAKE) -C .. $(BNOPULLUP) + +burn: + $(MAKE) -C .. burn-$(BNOPULLUP) + +clean: + $(MAKE) -C .. $@ +endif + VPATH += $(BNOPULLUP) BNOPULLUP_VSRC := $(BNOPULLUP)/$(BNOPULLUP).v diff --git a/fsm_simple/Makefile b/fsm_simple/Makefile index 8021c43..fd29915 100644 --- a/fsm_simple/Makefile +++ b/fsm_simple/Makefile @@ -1,5 +1,18 @@ FSM := fsm_simple +ifndef BUILD +.PHONY: all burn clean + +all: + $(MAKE) -C .. $(FSM) + +burn: + $(MAKE) -C .. burn-fsm + +clean: + $(MAKE) -C .. $@ +endif + VPATH += $(FSM) FSM_VSRC := $(addprefix $(FSM)/,fsm.v button.v) diff --git a/uart_transmission/Makefile b/uart_transmission/Makefile index ec1e3c9..12c1f9f 100644 --- a/uart_transmission/Makefile +++ b/uart_transmission/Makefile @@ -1,5 +1,18 @@ UART := uart_transmission +ifndef BUILD +.PHONY: all burn clean + +all: + $(MAKE) -C .. $(UART) + +burn: + $(MAKE) -C .. burn-uart + +clean: + $(MAKE) -C .. $@ +endif + VPATH += $(UART) UART_VSRC := $(addprefix $(UART)/,uart.v uart_trx.v) From d0be3e16df7378fc16b6267b84231f96bd973c7a Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Sat, 11 Aug 2018 00:41:37 -0400 Subject: [PATCH 13/34] Update readme to reflect build system changes --- README.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index aa3b044..ace3cb6 100644 --- a/README.md +++ b/README.md @@ -112,14 +112,15 @@ https://www.dropbox.com/s/3qgiq0j6qj3910f/keypad_instructions.pdf?dl=0 ## Downloading, compiling, and programming the example projects In order to download this repository, type `git clone https://github.com/nesl/ice40_examples.git ice40_examples` on the command line. Within the repository you will find a GPL license file, this readme, and several different example project folders such as "blinky." Within a given project folder, you will see: -* top.v -- the highest level Verilog file, including all pin inputs (e.g. clocks and button lines) and outputs (e.g. LEDs) -* (other modules.v) -- any other required modules (e.g. UART transmitters) referenced in top.v -* pinmap.pcf -- the pin map file relating variable names referenced in top.v to physical I/O pins on the ICE40 HX8K. The syntax here is `set_io `. You can add the `--warn-no-port` option if you'd like the compiler to warn you if a specified pin does not exist on a given device. -* Makefile -- this is a typical Unix Makefile that dictates the synthesis and programming flow. For the example projects, this file provides two commands of interest: `make` and `make burn`. `make` will compile your verilog project into a binary bitstream, and `make burn` will download this bitstream onto your FPGA device through USB. -* build/ -- this is a folder where all intermediate build files are stored -- e.g. netlists, ascii bitstream, binary bistream. +* `.v` -- the highest level Verilog file, including all pin inputs (e.g. clocks and button lines) and outputs (e.g. LEDs) +* (`other_modules.v`) -- any other required modules (e.g. UART transmitters) referenced in `.v` +* `_.pcf` -- the pin map file relating variable names referenced in `.v` to physical I/O pins on the ICE40 HX8K. The syntax here is `set_io `. You can add the `--warn-no-port` option if you'd like the compiler to warn you if a specified pin does not exist on a given device. +* `Makefile` -- this is a sub-makefile which is included by the top-level makefile, but can also be used on its own. For the example projects, this file provides two commands of interest: `make` and `make burn`. `make` will compile your verilog project into a binary bitstream, and `make burn` will download this bitstream onto your FPGA device through USB. In order to compile an example project, navigate to that directory on your terminal. Type `make` to compile the project. When this finishes, type `make burn` to load the compiled binary onto your FPGA, provided it's connected over USB. +You can also type `make` in the top directory to compile all projects. To load a project onto your FPGA, use `make burn-`. + Note for OSX: If you are having difficulties programming a project onto the FPGA with `make burn`, see the section below on UART transmission under the UART project. ## Example Projects List @@ -160,12 +161,12 @@ If on a Windows machine (for viewing purposes only--i.e. this does not apply if ## Project Design Process: In order to create your own project, start by copying the template provided in the blank project folder. The general design process looks like this: -1. Write your top-level Verilog code in top.v. Any additional Verilog files required can be placed at the same level as top.v (in the project folder). +1. Write your top-level Verilog code in `.v`. Any additional Verilog files required can be placed at the same level as `.v` (in the project folder). -2. Modify your Makefile: change `PROJ` to be your project name, and if any additional Verilog files are required, they should follow the `FILES = top.v` line, using the format `FILES += newfile.v` where `newfile.v` is the name of any additional Verilog file you have written. You can use this syntax for however many files you need. +2. Modify your Makefile: change all `BLANK` and `BLANK_*` variables to some project prefix. If any additional Verilog files are required, they should be added to `_VSRC`. Remember to separate each file with spaces. -3. Modify pinmap.pcf. If any pins are required other than the input clock and LEDs, add a line to the pinmap.pcf file using the format `set_io --warn-no-port `. +3. Modify `_.pcf`. `` should be the package for your chip which is passed do `arachne-pnr`. The iCE40-HX8K-CT256 uses `ct256`, and the iCE40-HX1K-TQ144 uses `tq144`. For a full list of supported packages, see [the icestorm documentation](http://www.clifford.at/icestorm/#flags). If any pins are required other than the input clock and LEDs, add a line to the file using the format `set_io --warn-no-port `. -4. Compile your project by running `make` from the project directory +4. Compile your project by running `make` from either the project or top-level directory. -5. If your project successfully compiles, connect your FPGA over USB and type `make burn` to program the binary to your FPGA. +5. If your project successfully compiles, connect your FPGA over USB and type `make burn` from the project directory, or `make burn-` from the top-level directory to program the binary to your FPGA. From bb7606e77589c78a7374b386366b020ce68675f2 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Sun, 27 Jan 2019 12:43:26 -0500 Subject: [PATCH 14/34] Fix targets not being rebuilt on makefile change --- Makefile | 10 +++++----- blank/Makefile | 1 - blinky/Makefile | 1 - buttons_bounce/Makefile | 1 - buttons_debounce/Makefile | 1 - buttons_nopullup/Makefile | 1 - fsm_simple/Makefile | 1 - uart_transmission/Makefile | 1 - 8 files changed, 5 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 60e05b2..643f97c 100644 --- a/Makefile +++ b/Makefile @@ -17,11 +17,6 @@ SRC := all: $(MODULES) -# Because our sources/pinmaps depend on the makefile -# all targets will get rebuilt every time the makefile changes -$(SRC): Makefile - touch $@ - $(BUILD): mkdir -p $(BUILD) @@ -71,3 +66,8 @@ clean: rm -rf $(BUILD) include $(addsuffix /Makefile,$(MODULES)) + +# Because our sources/pinmaps depend on the makefile +# all targets will get rebuilt every time the makefile changes +$(SRC): Makefile + touch $@ diff --git a/blank/Makefile b/blank/Makefile index 1a9844d..1f68066 100644 --- a/blank/Makefile +++ b/blank/Makefile @@ -24,6 +24,5 @@ SRC += $(BLANK_SRC) blank: $(BUILD)/$(BLANK).bin $(BLANK_SRC): $(BLANK)/Makefile - touch $@ $(BUILD)/$(BLANK).blif: $(BLANK_VSRC) diff --git a/blinky/Makefile b/blinky/Makefile index 1d413e2..14954ad 100644 --- a/blinky/Makefile +++ b/blinky/Makefile @@ -22,6 +22,5 @@ SRC += $(BLINKY_SRC) blinky: $(BUILD)/blinky.bin $(BLINKY_SRC): blinky/Makefile - touch $@ $(BUILD)/blinky.blif: $(BLINKY_VSRC) diff --git a/buttons_bounce/Makefile b/buttons_bounce/Makefile index 6224db5..323fd86 100644 --- a/buttons_bounce/Makefile +++ b/buttons_bounce/Makefile @@ -24,6 +24,5 @@ SRC += $(BBOUNCE_SRC) $(BBOUNCE): $(BUILD)/$(BBOUNCE).bin $(BBOUNCE_SRC): $(BBOUNCE)/Makefile - touch $@ $(BUILD)/$(BBOUNCE).blif: $(BBOUNCE_VSRC) diff --git a/buttons_debounce/Makefile b/buttons_debounce/Makefile index 4398b69..8982da3 100644 --- a/buttons_debounce/Makefile +++ b/buttons_debounce/Makefile @@ -24,6 +24,5 @@ SRC += $(BDEBOUNCE_SRC) $(BDEBOUNCE): $(BUILD)/$(BDEBOUNCE).bin $(BDEBOUNCE_SRC): $(BDEBOUNCE)/Makefile - touch $@ $(BUILD)/$(BDEBOUNCE).blif: $(BDEBOUNCE_VSRC) diff --git a/buttons_nopullup/Makefile b/buttons_nopullup/Makefile index b1f43f8..e750eb6 100644 --- a/buttons_nopullup/Makefile +++ b/buttons_nopullup/Makefile @@ -24,6 +24,5 @@ SRC += $(BNOPULLUP_SRC) $(BNOPULLUP): $(BUILD)/$(BNOPULLUP).bin $(BNOPULLUP_SRC): $(BNOPULLUP)/Makefile - touch $@ $(BUILD)/$(BNOPULLUP).blif: $(BNOPULLUP_VSRC) diff --git a/fsm_simple/Makefile b/fsm_simple/Makefile index fd29915..2378ffd 100644 --- a/fsm_simple/Makefile +++ b/fsm_simple/Makefile @@ -24,6 +24,5 @@ SRC += $(FSM_SRC) $(FSM): $(BUILD)/fsm.bin $(FSM_SRC): $(FSM)/Makefile - touch $@ $(BUILD)/fsm.blif: $(FSM_VSRC) diff --git a/uart_transmission/Makefile b/uart_transmission/Makefile index 12c1f9f..12ea038 100644 --- a/uart_transmission/Makefile +++ b/uart_transmission/Makefile @@ -24,6 +24,5 @@ SRC += $(UART_SRC) $(UART): $(BUILD)/uart.bin $(UART_SRC): $(UART)/Makefile - touch $@ $(BUILD)/uart.blif: $(UART_VSRC) From fee5d85a46fd11a21107ed76bf65a9e25e0e994a Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Sun, 27 Jan 2019 13:13:44 -0500 Subject: [PATCH 15/34] Add VERBOSE option yosys and arachne-pnr are SUPER verbose by default. This should help keep terminal spam to a minimum. --- Makefile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 643f97c..1b4de96 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,12 @@ else FOOTPRINT := tq144 endif +ifdef VERBOSE +Q := +else +Q :=1 +endif + MODULES := uart_transmission blank blinky buttons_bounce buttons_debounce buttons_nopullup fsm_simple # SRC holds all source files @@ -31,7 +37,7 @@ $(BUILD): # $^ all non-order-only dependencies # $* the stem of an implicit rule -- what % matches in %.blif $(BUILD)/%.blif: %.v | $(BUILD) - yosys -p "synth_ice40 -top $* -blif $@" $^ + yosys $(and $(Q),-q) -p "synth_ice40 -top $* -blif $@" $^ # .PHONY causes targets to be rebuilt every make, and built even if there is an up-to-date file # Depending on a .PHONY target will cause the rule to be run every time @@ -54,7 +60,7 @@ $(BUILD)/%: % # Note that yosys does not run if you only change DEVICE, just things from here down %.asc: %.blif %_$(FOOTPRINT).pcf $(BUILD)/DEVICE.var $(BUILD)/FOOTPRINT.var - arachne-pnr -d $(DEVICE) -P $(FOOTPRINT) -o $@ -p $*_$(FOOTPRINT).pcf $< + arachne-pnr $(and $(Q),-q) -d $(DEVICE) -P $(FOOTPRINT) -o $@ -p $*_$(FOOTPRINT).pcf $< %.bin: %.asc icepack $< $@ From 236452bc56ce05608252bf4ec2e2f4785c151d90 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Sun, 27 Jan 2019 15:51:57 -0500 Subject: [PATCH 16/34] Move duplicated makefile code into common.mk Unfortunately, there is no easy way to reference this, so we're stuck with an ugly include line in every makefile... --- Makefile | 5 ++++- blank/Makefile | 31 ++++--------------------------- blinky/Makefile | 29 ++++------------------------- buttons_bounce/Makefile | 31 ++++--------------------------- buttons_debounce/Makefile | 31 ++++--------------------------- buttons_nopullup/Makefile | 31 ++++--------------------------- fsm_simple/Makefile | 31 ++++--------------------------- uart_transmission/Makefile | 31 ++++--------------------------- 8 files changed, 32 insertions(+), 188 deletions(-) diff --git a/Makefile b/Makefile index 1b4de96..15602e0 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,9 @@ else Q :=1 endif +# Necessary so VPATH doesn't get reinterpreted +VPATH := + MODULES := uart_transmission blank blinky buttons_bounce buttons_debounce buttons_nopullup fsm_simple # SRC holds all source files @@ -21,7 +24,7 @@ SRC := .PHONY: all clean burn-% FORCE -all: $(MODULES) +all: $(BUILD): mkdir -p $(BUILD) diff --git a/blank/Makefile b/blank/Makefile index 1f68066..9d23292 100644 --- a/blank/Makefile +++ b/blank/Makefile @@ -1,28 +1,5 @@ -BLANK := blank +MODULE := blank +M_VSRC := blank.v +M_SRC := blank_ct256.pcf -ifndef BUILD -.PHONY: all burn clean - -all: - $(MAKE) -C .. $(BLANK) - -burn: - $(MAKE) -C .. burn-$(BLANK) - -clean: - $(MAKE) -C .. $@ -endif - -VPATH += blank - -BLANK_VSRC := $(addprefix $(BLANK)/,$(BLANK).v) -BLANK_SRC := $(BLANK_VSRC) $(addprefix $(BLANK)/,$(BLANK)_ct256.pcf) -SRC += $(BLANK_SRC) - -.PHONY: $(BLANK) - -blank: $(BUILD)/$(BLANK).bin - -$(BLANK_SRC): $(BLANK)/Makefile - -$(BUILD)/$(BLANK).blif: $(BLANK_VSRC) +include $(realpath $(dir $(lastword $(MAKEFILE_LIST))))/../common.mk diff --git a/blinky/Makefile b/blinky/Makefile index 14954ad..ef1bad6 100644 --- a/blinky/Makefile +++ b/blinky/Makefile @@ -1,26 +1,5 @@ -ifndef BUILD -.PHONY: all burn clean +MODULE := blinky +M_VSRC := blinky.v +M_SRC := blinky_ct256.pcf -all: - $(MAKE) -C .. blinky - -burn: - $(MAKE) -C .. burn-blinky - -clean: - $(MAKE) -C .. $@ -endif - -VPATH += blinky - -BLINKY_VSRC := blinky/blinky.v -BLINKY_SRC := $(BLINKY_VSRC) blinky/blinky_ct256.pcf -SRC += $(BLINKY_SRC) - -.PHONY: blinky - -blinky: $(BUILD)/blinky.bin - -$(BLINKY_SRC): blinky/Makefile - -$(BUILD)/blinky.blif: $(BLINKY_VSRC) +include $(realpath $(dir $(lastword $(MAKEFILE_LIST))))/../common.mk diff --git a/buttons_bounce/Makefile b/buttons_bounce/Makefile index 323fd86..8d0dd16 100644 --- a/buttons_bounce/Makefile +++ b/buttons_bounce/Makefile @@ -1,28 +1,5 @@ -BBOUNCE := buttons_bounce +MODULE := buttons_bounce +M_VSRC := buttons_bounce.v +M_SRC := buttons_bounce_ct256.pcf -ifndef BUILD -.PHONY: all burn clean - -all: - $(MAKE) -C .. $(BBOUNCE) - -burn: - $(MAKE) -C .. burn-$(BBOUNCE) - -clean: - $(MAKE) -C .. $@ -endif - -VPATH += $(BBOUNCE) - -BBOUNCE_VSRC := $(BBOUNCE)/$(BBOUNCE).v -BBOUNCE_SRC := $(BBOUNCE_VSRC) $(BBOUNCE)/$(BBOUNCE)_ct256.pcf -SRC += $(BBOUNCE_SRC) - -.PHONY: $(BBOUNCE) - -$(BBOUNCE): $(BUILD)/$(BBOUNCE).bin - -$(BBOUNCE_SRC): $(BBOUNCE)/Makefile - -$(BUILD)/$(BBOUNCE).blif: $(BBOUNCE_VSRC) +include $(realpath $(dir $(lastword $(MAKEFILE_LIST))))/../common.mk diff --git a/buttons_debounce/Makefile b/buttons_debounce/Makefile index 8982da3..007ae17 100644 --- a/buttons_debounce/Makefile +++ b/buttons_debounce/Makefile @@ -1,28 +1,5 @@ -BDEBOUNCE := buttons_debounce +MODULE := buttons_debounce +M_VSRC := buttons_debounce.v +M_SRC := buttons_debounce_ct256.pcf -ifndef BUILD -.PHONY: all burn clean - -all: - $(MAKE) -C .. $(BDEBOUNCE) - -burn: - $(MAKE) -C .. burn-$(BDEBOUNCE) - -clean: - $(MAKE) -C .. $@ -endif - -VPATH += $(BDEBOUNCE) - -BDEBOUNCE_VSRC := $(BDEBOUNCE)/$(BDEBOUNCE).v -BDEBOUNCE_SRC := $(BDEBOUNCE_VSRC) $(BDEBOUNCE)/$(BDEBOUNCE)_ct256.pcf -SRC += $(BDEBOUNCE_SRC) - -.PHONY: $(BDEBOUNCE) - -$(BDEBOUNCE): $(BUILD)/$(BDEBOUNCE).bin - -$(BDEBOUNCE_SRC): $(BDEBOUNCE)/Makefile - -$(BUILD)/$(BDEBOUNCE).blif: $(BDEBOUNCE_VSRC) +include $(realpath $(dir $(lastword $(MAKEFILE_LIST))))/../common.mk diff --git a/buttons_nopullup/Makefile b/buttons_nopullup/Makefile index e750eb6..24e8e49 100644 --- a/buttons_nopullup/Makefile +++ b/buttons_nopullup/Makefile @@ -1,28 +1,5 @@ -BNOPULLUP := buttons_nopullup +MODULE := buttons_nopullup +M_VSRC := buttons_nopullup.v +M_SRC := buttons_nopullup_ct256.pcf -ifndef BUILD -.PHONY: all burn clean - -all: - $(MAKE) -C .. $(BNOPULLUP) - -burn: - $(MAKE) -C .. burn-$(BNOPULLUP) - -clean: - $(MAKE) -C .. $@ -endif - -VPATH += $(BNOPULLUP) - -BNOPULLUP_VSRC := $(BNOPULLUP)/$(BNOPULLUP).v -BNOPULLUP_SRC := $(BNOPULLUP_VSRC) $(BNOPULLUP)/$(BNOPULLUP)_ct256.pcf -SRC += $(BNOPULLUP_SRC) - -.PHONY: $(BNOPULLUP) - -$(BNOPULLUP): $(BUILD)/$(BNOPULLUP).bin - -$(BNOPULLUP_SRC): $(BNOPULLUP)/Makefile - -$(BUILD)/$(BNOPULLUP).blif: $(BNOPULLUP_VSRC) +include $(realpath $(dir $(lastword $(MAKEFILE_LIST))))/../common.mk diff --git a/fsm_simple/Makefile b/fsm_simple/Makefile index 2378ffd..c1ac389 100644 --- a/fsm_simple/Makefile +++ b/fsm_simple/Makefile @@ -1,28 +1,5 @@ -FSM := fsm_simple +MODULE := fsm +M_VSRC := fsm.v button.v +M_SRC := fsm_ct256.pcf -ifndef BUILD -.PHONY: all burn clean - -all: - $(MAKE) -C .. $(FSM) - -burn: - $(MAKE) -C .. burn-fsm - -clean: - $(MAKE) -C .. $@ -endif - -VPATH += $(FSM) - -FSM_VSRC := $(addprefix $(FSM)/,fsm.v button.v) -FSM_SRC := $(FSM_VSRC) $(FSM)/fsm_ct256.pcf -SRC += $(FSM_SRC) - -.PHONY: $(FSM) - -$(FSM): $(BUILD)/fsm.bin - -$(FSM_SRC): $(FSM)/Makefile - -$(BUILD)/fsm.blif: $(FSM_VSRC) +include $(realpath $(dir $(lastword $(MAKEFILE_LIST))))/../common.mk diff --git a/uart_transmission/Makefile b/uart_transmission/Makefile index 12ea038..8843caa 100644 --- a/uart_transmission/Makefile +++ b/uart_transmission/Makefile @@ -1,28 +1,5 @@ -UART := uart_transmission +MODULE := uart +M_VSRC := uart.v uart_trx.v +M_SRC := uart_ct256.pcf uart_tq144.pcf -ifndef BUILD -.PHONY: all burn clean - -all: - $(MAKE) -C .. $(UART) - -burn: - $(MAKE) -C .. burn-uart - -clean: - $(MAKE) -C .. $@ -endif - -VPATH += $(UART) - -UART_VSRC := $(addprefix $(UART)/,uart.v uart_trx.v) -UART_SRC := $(UART_VSRC) $(addprefix $(UART)/,uart_ct256.pcf uart_tq144.pcf) -SRC += $(UART_SRC) - -.PHONY: $(UART) - -$(UART): $(BUILD)/uart.bin - -$(UART_SRC): $(UART)/Makefile - -$(BUILD)/uart.blif: $(UART_VSRC) +include $(realpath $(dir $(lastword $(MAKEFILE_LIST))))/../common.mk From dfb55fa62ef35c158e57844aa735d298e2093be3 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Sun, 27 Jan 2019 15:53:57 -0500 Subject: [PATCH 17/34] Use ln over cp for requiring files in build --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 15602e0..af3e602 100644 --- a/Makefile +++ b/Makefile @@ -53,13 +53,13 @@ FORCE: # If they are the same we don't # Anything which depends on $(BUILD)/DEVICE.var will only update if DEVICE changes $(BUILD)/%.var: FORCE - echo $($*) | cmp - $@ || echo $($*) > $@ + @echo $($*) | cmp - $@ || echo $($*) > $@ # Keep .var file around even though they are intermediate targets .PRECIOUS: $(BUILD)/%.var $(BUILD)/%: % - cp -f $< $@ + ln -f $< $@ # Note that yosys does not run if you only change DEVICE, just things from here down %.asc: %.blif %_$(FOOTPRINT).pcf $(BUILD)/DEVICE.var $(BUILD)/FOOTPRINT.var From 985e4fa0c5335e9983f149a1b1350cd3cbd488a4 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Sun, 27 Jan 2019 16:02:18 -0500 Subject: [PATCH 18/34] Add common.mk Forgot to do this before pushing (whoops) --- common.mk | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 common.mk diff --git a/common.mk b/common.mk new file mode 100644 index 0000000..efe2e98 --- /dev/null +++ b/common.mk @@ -0,0 +1,31 @@ +# Really ugly, but make can't decrement so we get this... +getincluder = $(word $(words $(wordlist 2,$(words $1),$1)),$1) +DIR := $(dir $(call getincluder,$(MAKEFILE_LIST))) + +ifndef BUILD +.PHONY: all burn clean + +all: + $(MAKE) -C .. $(MODULE) + +burn: + $(MAKE) -C .. burn-$(MODULE) + +clean: + $(MAKE) -C .. $@ +endif + +VPATH += $(DIR) + +M_VSRC := $(addprefix $(DIR),$(M_VSRC)) +M_SRC := $(M_VSRC) $(addprefix $(DIR),$(M_SRC)) +SRC += $(M_SRC) + +.PHONY: $(MODULE) +$(MODULE): $(BUILD)/$(MODULE).bin + +$(M_SRC): $(DIR)Makefile $(lastword $(MAKEFILE_LIST)) + +$(BUILD)/$(MODULE).blif: $(M_VSRC) + +all: $(MODULE) From a9c7e2c70362cbbdb34e6c2894b466fa585afe78 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Sun, 27 Jan 2019 16:02:58 -0500 Subject: [PATCH 19/34] Update Readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ace3cb6..517df9a 100644 --- a/README.md +++ b/README.md @@ -161,12 +161,12 @@ If on a Windows machine (for viewing purposes only--i.e. this does not apply if ## Project Design Process: In order to create your own project, start by copying the template provided in the blank project folder. The general design process looks like this: -1. Write your top-level Verilog code in `.v`. Any additional Verilog files required can be placed at the same level as `.v` (in the project folder). +1. Write your top-level Verilog code in `.v`. Any additional Verilog files required can be placed at the same level as `.v` (in the project folder). -2. Modify your Makefile: change all `BLANK` and `BLANK_*` variables to some project prefix. If any additional Verilog files are required, they should be added to `_VSRC`. Remember to separate each file with spaces. +2. Modify your Makefile: update the `MODULE` variable (this doesn't need to match the folder name, but does need to be unique across all modules). If any additional Verilog files are required, they should be added to `M_VSRC`. Remember to separate each file with spaces. Any other source files (including pcf files) should be added to `M_SRC`. 3. Modify `_.pcf`. `` should be the package for your chip which is passed do `arachne-pnr`. The iCE40-HX8K-CT256 uses `ct256`, and the iCE40-HX1K-TQ144 uses `tq144`. For a full list of supported packages, see [the icestorm documentation](http://www.clifford.at/icestorm/#flags). If any pins are required other than the input clock and LEDs, add a line to the file using the format `set_io --warn-no-port `. 4. Compile your project by running `make` from either the project or top-level directory. -5. If your project successfully compiles, connect your FPGA over USB and type `make burn` from the project directory, or `make burn-` from the top-level directory to program the binary to your FPGA. +5. If your project successfully compiles, connect your FPGA over USB and type `make burn` from the project directory, or `make burn-` from the top-level directory to program the binary to your FPGA. From d82bbcd8a0d6dad65feebb6c5d8b35f60e78f2bd Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 19 Mar 2019 19:48:14 -0400 Subject: [PATCH 20/34] Add additional options for synthesis --- Makefile | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index af3e602..e4e6539 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,9 @@ # Use := where you can, as it only gets evaluated once BUILD := build # ?= allows the user to pass in a device on the command line -DEVICE ?= 8k -ifeq (8k,$(DEVICE)) +DEVICE ?= hx8k +FAMILY := $(strip $(subst lp,,$(subst hx,, $(subst up,,$(DEVICE))))) +ifeq (8k,$(FAMILY)) FOOTPRINT := ct256 else FOOTPRINT := tq144 @@ -14,15 +15,17 @@ else Q :=1 endif +PNR ?= arachne-pnr +SYNTH ?= yosys + # Necessary so VPATH doesn't get reinterpreted VPATH := - MODULES := uart_transmission blank blinky buttons_bounce buttons_debounce buttons_nopullup fsm_simple # SRC holds all source files SRC := -.PHONY: all clean burn-% FORCE +.PHONY: all clean burn-% time-% FORCE all: @@ -40,7 +43,7 @@ $(BUILD): # $^ all non-order-only dependencies # $* the stem of an implicit rule -- what % matches in %.blif $(BUILD)/%.blif: %.v | $(BUILD) - yosys $(and $(Q),-q) -p "synth_ice40 -top $* -blif $@" $^ + $(SYNTH) $(and $(Q),-q) -p "synth_ice40 -top $* -blif $@" $^ # .PHONY causes targets to be rebuilt every make, and built even if there is an up-to-date file # Depending on a .PHONY target will cause the rule to be run every time @@ -62,8 +65,8 @@ $(BUILD)/%: % ln -f $< $@ # Note that yosys does not run if you only change DEVICE, just things from here down -%.asc: %.blif %_$(FOOTPRINT).pcf $(BUILD)/DEVICE.var $(BUILD)/FOOTPRINT.var - arachne-pnr $(and $(Q),-q) -d $(DEVICE) -P $(FOOTPRINT) -o $@ -p $*_$(FOOTPRINT).pcf $< +%.asc: %.blif %_$(FOOTPRINT).pcf $(BUILD)/FAMILY.var $(BUILD)/FOOTPRINT.var + $(PNR) $(and $(Q),-q) -d $(FAMILY) -P $(FOOTPRINT) -p $*_$(FOOTPRINT).pcf -o $@ $< %.bin: %.asc icepack $< $@ @@ -71,6 +74,9 @@ $(BUILD)/%: % burn-%: $(BUILD)/%.bin iceprog $< +time-%: $(BUILD)/%.asc $(BUILD)/%_$(FOOTPRINT).pcf $(BUILD)/DEVICE.var $(BUILD)/FOOTPRINT.var + icetime -t -d $(DEVICE) -P $(FOOTPRINT) -p $(BUILD)/$*_$(FOOTPRINT).pcf $< + clean: rm -rf $(BUILD) From 515a5a612b1c5ee139a5e21ab3c795bc405161c8 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 19 Mar 2019 19:57:34 -0400 Subject: [PATCH 21/34] Fix subdir builds not working --- common.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common.mk b/common.mk index efe2e98..0e7b7fc 100644 --- a/common.mk +++ b/common.mk @@ -28,4 +28,6 @@ $(M_SRC): $(DIR)Makefile $(lastword $(MAKEFILE_LIST)) $(BUILD)/$(MODULE).blif: $(M_VSRC) +ifdef BUILD all: $(MODULE) +endif From 28de8184a8efcc1b2f7dd0b37ed0a8d11ddf7e7c Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Wed, 20 Mar 2019 22:28:08 -0400 Subject: [PATCH 22/34] Remove some projects A few of these projects have been removed for being hard to port (depending on a specific piece of hardware). The fms one has been removed for being not very useful. --- Makefile | 2 +- buttons_bounce/Makefile | 5 - buttons_bounce/buttons_bounce.v | 52 --------- buttons_bounce/buttons_bounce_ct256.pcf | 18 --- buttons_debounce/Makefile | 5 - buttons_debounce/buttons_debounce.v | 70 ------------ buttons_debounce/buttons_debounce_ct256.pcf | 18 --- buttons_nopullup/Makefile | 5 - buttons_nopullup/buttons_nopullup.v | 40 ------- buttons_nopullup/buttons_nopullup_ct256.pcf | 18 --- fsm_simple/Makefile | 5 - fsm_simple/button.v | 57 ---------- fsm_simple/fsm.v | 119 -------------------- fsm_simple/fsm_ct256.pcf | 18 --- {uart_transmission => uart}/Makefile | 0 {uart_transmission => uart}/uart.v | 0 {uart_transmission => uart}/uart_ct256.pcf | 0 {uart_transmission => uart}/uart_tq144.pcf | 0 {uart_transmission => uart}/uart_trx.v | 0 19 files changed, 1 insertion(+), 431 deletions(-) delete mode 100644 buttons_bounce/Makefile delete mode 100644 buttons_bounce/buttons_bounce.v delete mode 100644 buttons_bounce/buttons_bounce_ct256.pcf delete mode 100644 buttons_debounce/Makefile delete mode 100644 buttons_debounce/buttons_debounce.v delete mode 100644 buttons_debounce/buttons_debounce_ct256.pcf delete mode 100644 buttons_nopullup/Makefile delete mode 100644 buttons_nopullup/buttons_nopullup.v delete mode 100644 buttons_nopullup/buttons_nopullup_ct256.pcf delete mode 100644 fsm_simple/Makefile delete mode 100644 fsm_simple/button.v delete mode 100644 fsm_simple/fsm.v delete mode 100644 fsm_simple/fsm_ct256.pcf rename {uart_transmission => uart}/Makefile (100%) rename {uart_transmission => uart}/uart.v (100%) rename {uart_transmission => uart}/uart_ct256.pcf (100%) rename {uart_transmission => uart}/uart_tq144.pcf (100%) rename {uart_transmission => uart}/uart_trx.v (100%) diff --git a/Makefile b/Makefile index e4e6539..561e27d 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ SYNTH ?= yosys # Necessary so VPATH doesn't get reinterpreted VPATH := -MODULES := uart_transmission blank blinky buttons_bounce buttons_debounce buttons_nopullup fsm_simple +MODULES := uart blank blinky # SRC holds all source files SRC := diff --git a/buttons_bounce/Makefile b/buttons_bounce/Makefile deleted file mode 100644 index 8d0dd16..0000000 --- a/buttons_bounce/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -MODULE := buttons_bounce -M_VSRC := buttons_bounce.v -M_SRC := buttons_bounce_ct256.pcf - -include $(realpath $(dir $(lastword $(MAKEFILE_LIST))))/../common.mk diff --git a/buttons_bounce/buttons_bounce.v b/buttons_bounce/buttons_bounce.v deleted file mode 100644 index 7c19207..0000000 --- a/buttons_bounce/buttons_bounce.v +++ /dev/null @@ -1,52 +0,0 @@ -/* Top level module for button demo without debouncing - (not a good way of doing things!) - This uses button 1 of the keypad when installed correctly. - */ -module buttons_bounce ( - // input hardware clock (12 MHz) - hwclk, - // LED - led1, - // Keypad lines - keypad_r1, - keypad_c1, - ); - - /* Clock input */ - input hwclk; - - /* LED outputs */ - output led1; - - /* Numpad I/O */ - output keypad_r1=0; - input keypad_c1; - - /* LED register */ - reg ledval = 1'b0; - - /* Numpad pull-up settings for columns: - PIN_TYPE: _ - PULLUP: - PACKAGE_PIN: - D_IN_0: - */ - wire keypad_c1_din; - SB_IO #( - .PIN_TYPE(6'b0000_01), - .PULLUP(1'b1) - ) keypad_c1_config ( - .PACKAGE_PIN(keypad_c1), - .D_IN_0(keypad_c1_din) - ); - - /* LED Wiring */ - assign led1=ledval; - - /* Toggle LED when button [1] pressed */ - always @ (negedge keypad_c1_din) begin - ledval = ~ledval; - end - - -endmodule diff --git a/buttons_bounce/buttons_bounce_ct256.pcf b/buttons_bounce/buttons_bounce_ct256.pcf deleted file mode 100644 index a1e80fd..0000000 --- a/buttons_bounce/buttons_bounce_ct256.pcf +++ /dev/null @@ -1,18 +0,0 @@ -# example.pcf -set_io --warn-no-port led1 B5 -set_io --warn-no-port led2 B4 -set_io --warn-no-port led3 A2 -set_io --warn-no-port led4 A1 -set_io --warn-no-port led5 C5 -set_io --warn-no-port led6 C4 -set_io --warn-no-port led7 B3 -set_io --warn-no-port led8 C3 -set_io --warn-no-port hwclk J3 - -# NUMPAD pins (note: r4 is gnd, can't use) -set_io --warn-no-port keypad_r1 J15 -set_io --warn-no-port keypad_r2 G14 -set_io --warn-no-port keypad_r3 K14 -set_io --warn-no-port keypad_c1 K15 -set_io --warn-no-port keypad_c2 M16 -set_io --warn-no-port keypad_c3 N16 \ No newline at end of file diff --git a/buttons_debounce/Makefile b/buttons_debounce/Makefile deleted file mode 100644 index 007ae17..0000000 --- a/buttons_debounce/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -MODULE := buttons_debounce -M_VSRC := buttons_debounce.v -M_SRC := buttons_debounce_ct256.pcf - -include $(realpath $(dir $(lastword $(MAKEFILE_LIST))))/../common.mk diff --git a/buttons_debounce/buttons_debounce.v b/buttons_debounce/buttons_debounce.v deleted file mode 100644 index 08b7bc6..0000000 --- a/buttons_debounce/buttons_debounce.v +++ /dev/null @@ -1,70 +0,0 @@ -/* Top level module for button demo WITH debouncing - This uses button 1 of the keypad when installed correctly. - */ -module buttons_debounce ( - // input hardware clock (12 MHz) - hwclk, - // LED - led1, - // Keypad lines - keypad_r1, - keypad_c1, - ); - - /* Clock input */ - input hwclk; - - /* LED outputs */ - output led1; - - /* Numpad I/O */ - output keypad_r1=0; - input keypad_c1; - - /* LED register */ - reg ledval = 1'b0; - - /* Numpad pull-up settings for columns: - PIN_TYPE: _ - PULLUP: - PACKAGE_PIN: - D_IN_0: - */ - wire keypad_c1_din; - SB_IO #( - .PIN_TYPE(6'b0000_01), - .PULLUP(1'b1) - ) keypad_c1_config ( - .PACKAGE_PIN(keypad_c1), - .D_IN_0(keypad_c1_din) - ); - - /* Debouncing timer and period = 10 ms */ - reg [31:0] debounce_timer = 32'b0; - parameter DEBOUNCE_PERIOD = 32'd120000; - reg debouncing = 1'b0; - - /* LED Wiring */ - assign led1=ledval; - - /* Our high speed clock will deal with debounce timing */ - always @ (posedge hwclk) begin - // check for button presses - if (~debouncing && ~keypad_c1_din) begin - ledval <= ~ledval; - debouncing <= 1; - // reset debouncing if button is held low - end else if (debouncing && ~keypad_c1_din) begin - debounce_timer <= 32'b0; - // or if it's high, increment debounce timer - end else if (debouncing && debounce_timer < DEBOUNCE_PERIOD) begin - debounce_timer <= debounce_timer + 1; - // finally, if it's high and timer expired, debouncing done! - end else if (debouncing) begin - debounce_timer <= 32'b0; - debouncing <= 1'b0; - end - end - - -endmodule diff --git a/buttons_debounce/buttons_debounce_ct256.pcf b/buttons_debounce/buttons_debounce_ct256.pcf deleted file mode 100644 index a1e80fd..0000000 --- a/buttons_debounce/buttons_debounce_ct256.pcf +++ /dev/null @@ -1,18 +0,0 @@ -# example.pcf -set_io --warn-no-port led1 B5 -set_io --warn-no-port led2 B4 -set_io --warn-no-port led3 A2 -set_io --warn-no-port led4 A1 -set_io --warn-no-port led5 C5 -set_io --warn-no-port led6 C4 -set_io --warn-no-port led7 B3 -set_io --warn-no-port led8 C3 -set_io --warn-no-port hwclk J3 - -# NUMPAD pins (note: r4 is gnd, can't use) -set_io --warn-no-port keypad_r1 J15 -set_io --warn-no-port keypad_r2 G14 -set_io --warn-no-port keypad_r3 K14 -set_io --warn-no-port keypad_c1 K15 -set_io --warn-no-port keypad_c2 M16 -set_io --warn-no-port keypad_c3 N16 \ No newline at end of file diff --git a/buttons_nopullup/Makefile b/buttons_nopullup/Makefile deleted file mode 100644 index 24e8e49..0000000 --- a/buttons_nopullup/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -MODULE := buttons_nopullup -M_VSRC := buttons_nopullup.v -M_SRC := buttons_nopullup_ct256.pcf - -include $(realpath $(dir $(lastword $(MAKEFILE_LIST))))/../common.mk diff --git a/buttons_nopullup/buttons_nopullup.v b/buttons_nopullup/buttons_nopullup.v deleted file mode 100644 index d2a16b7..0000000 --- a/buttons_nopullup/buttons_nopullup.v +++ /dev/null @@ -1,40 +0,0 @@ -/* Top level module for button demo without debouncing and with no - pull-up resistor (not a good way of doing things!) - */ -module buttons_nopullup ( - // input hardware clock (12 MHz) - hwclk, - // LED - led1, - // Keypad lines - keypad_r1, - keypad_c1, - ); - - /* Clock input */ - input hwclk; - - /* LED outputs */ - output led1; - - /* Numpad I/O */ - output keypad_r1=0; - input keypad_c1; - - // Note: Left as is, keypad_c1 is a floating value, meaning - // it has an undetermined voltage. It will trigger edges when - // we don't want it to. - - /* LED register */ - reg ledval = 1'b0; - - /* LED Wiring */ - assign led1=ledval; - - /* Toggle LED when button [1] pressed */ - always @ (negedge keypad_c1) begin - ledval = ~ledval; - end - - -endmodule diff --git a/buttons_nopullup/buttons_nopullup_ct256.pcf b/buttons_nopullup/buttons_nopullup_ct256.pcf deleted file mode 100644 index a1e80fd..0000000 --- a/buttons_nopullup/buttons_nopullup_ct256.pcf +++ /dev/null @@ -1,18 +0,0 @@ -# example.pcf -set_io --warn-no-port led1 B5 -set_io --warn-no-port led2 B4 -set_io --warn-no-port led3 A2 -set_io --warn-no-port led4 A1 -set_io --warn-no-port led5 C5 -set_io --warn-no-port led6 C4 -set_io --warn-no-port led7 B3 -set_io --warn-no-port led8 C3 -set_io --warn-no-port hwclk J3 - -# NUMPAD pins (note: r4 is gnd, can't use) -set_io --warn-no-port keypad_r1 J15 -set_io --warn-no-port keypad_r2 G14 -set_io --warn-no-port keypad_r3 K14 -set_io --warn-no-port keypad_c1 K15 -set_io --warn-no-port keypad_c2 M16 -set_io --warn-no-port keypad_c3 N16 \ No newline at end of file diff --git a/fsm_simple/Makefile b/fsm_simple/Makefile deleted file mode 100644 index c1ac389..0000000 --- a/fsm_simple/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -MODULE := fsm -M_VSRC := fsm.v button.v -M_SRC := fsm_ct256.pcf - -include $(realpath $(dir $(lastword $(MAKEFILE_LIST))))/../common.mk diff --git a/fsm_simple/button.v b/fsm_simple/button.v deleted file mode 100644 index f78119b..0000000 --- a/fsm_simple/button.v +++ /dev/null @@ -1,57 +0,0 @@ -/* Simple button module */ -module button ( - // input clock - clk, - // I/O pins - pin_in, - press, - ); - - input clk; - input pin_in; - output press; - - /* Pull-up settings for input: - PIN_TYPE: _ - PULLUP: - PACKAGE_PIN: - D_IN_0: - */ - wire pin_din; - SB_IO #( - .PIN_TYPE(6'b0000_01), - .PULLUP(1'b1) - ) pin_in_config ( - .PACKAGE_PIN(pin_in), - .D_IN_0(pin_din) - ); - - /* Debouncing timer and period = 10 ms */ - reg [31:0] debounce_timer = 32'b0; - parameter DEBOUNCE_PERIOD = 32'd120000; - reg debouncing = 1'b0; - reg buttonpress = 1'b0; - assign press = buttonpress; - - /* Our high speed clock will deal with debounce timing */ - always @ (posedge clk) begin - // check for button presses - if (~debouncing && ~pin_din) begin - buttonpress <= 1; - debouncing <= 1; - // reset debouncing if button is held low - end else if (debouncing && ~pin_din) begin - debounce_timer <= 32'b0; - // or if it's high, increment debounce timer - end else if (debouncing && debounce_timer < DEBOUNCE_PERIOD) begin - debounce_timer <= debounce_timer + 1; - // finally, if it's high and timer expired, debouncing done! - end else if (debouncing) begin - debounce_timer <= 32'b0; - debouncing <= 1'b0; - buttonpress <= 0; - end - end - - -endmodule \ No newline at end of file diff --git a/fsm_simple/fsm.v b/fsm_simple/fsm.v deleted file mode 100644 index 81699f4..0000000 --- a/fsm_simple/fsm.v +++ /dev/null @@ -1,119 +0,0 @@ -/* Top level module for button demo WITH debouncing - This uses button 1 of the keypad when installed correctly. - */ -module fsm ( - // input hardware clock (12 MHz) - hwclk, - // LED - led1, - led2, - led3, - // Keypad lines - keypad_r1, - keypad_c1, - keypad_c2, - ); - - /* Clock input */ - input hwclk; - - /* LED outputs */ - output led1; - output led2; - output led3; - reg [2:0] ledvals = 3'b0; - - /* Numpad I/O */ - output keypad_r1=0; - input keypad_c1; - input keypad_c2; - - /* Button Modules */ - wire press1, press2; - button button1 ( - .clk (hwclk), - .pin_in (keypad_c1), - .press (press1), - ); - button button2 ( - .clk (hwclk), - .pin_in (keypad_c2), - .press (press2), - ); - - /* State variables */ - parameter STATE_RST = 8'd0; - parameter STATE_1 = 8'd1; - parameter STATE_12 = 8'd2; - parameter STATE_121 = 8'd3; - parameter STATE_1211 = 8'd4; - reg [7:0] state = STATE_RST; - assign led1 = ledvals[0]; - assign led2 = ledvals[1]; - assign led3 = ledvals[2]; - - wire button_pressed = press1 | press2; - - /* Our high speed clock will deal with the simple FSM */ - always @ (posedge button_pressed) begin - // toggle LEDs - if (press1) begin - ledvals[0] <= ~ledvals[0]; - end else begin - ledvals[1] <= ~ledvals[1]; - end - case (state) - STATE_RST : begin - if (press1) begin - state <= STATE_1; - ledvals[2] <= 0; - end else begin - state <= STATE_RST; - ledvals[2] <= 0; - end - end - - STATE_1 : begin - if (press1) begin - state <= STATE_1; - ledvals[2] <= 0; - end else begin - state <= STATE_12; - ledvals[2] <= 0; - end - end - STATE_12 : begin - if (press1) begin - state <= STATE_121; - ledvals[2] <= 0; - end else begin - state <= STATE_RST; - ledvals[2] <= 0; - end - end - STATE_121 : begin - if (press1) begin - state <= STATE_1211; - ledvals[2] <= 1; - end else begin - state <= STATE_12; - ledvals[2] <= 0; - end - end - STATE_1211 : begin - if (press1) begin - state <= STATE_1; - ledvals[2] <= 0; - end else begin - state <= STATE_12; - ledvals[2] <= 0; - end - end - default : begin - state <= STATE_RST; - ledvals[2] <= 0; - end - endcase - end - -endmodule diff --git a/fsm_simple/fsm_ct256.pcf b/fsm_simple/fsm_ct256.pcf deleted file mode 100644 index a1e80fd..0000000 --- a/fsm_simple/fsm_ct256.pcf +++ /dev/null @@ -1,18 +0,0 @@ -# example.pcf -set_io --warn-no-port led1 B5 -set_io --warn-no-port led2 B4 -set_io --warn-no-port led3 A2 -set_io --warn-no-port led4 A1 -set_io --warn-no-port led5 C5 -set_io --warn-no-port led6 C4 -set_io --warn-no-port led7 B3 -set_io --warn-no-port led8 C3 -set_io --warn-no-port hwclk J3 - -# NUMPAD pins (note: r4 is gnd, can't use) -set_io --warn-no-port keypad_r1 J15 -set_io --warn-no-port keypad_r2 G14 -set_io --warn-no-port keypad_r3 K14 -set_io --warn-no-port keypad_c1 K15 -set_io --warn-no-port keypad_c2 M16 -set_io --warn-no-port keypad_c3 N16 \ No newline at end of file diff --git a/uart_transmission/Makefile b/uart/Makefile similarity index 100% rename from uart_transmission/Makefile rename to uart/Makefile diff --git a/uart_transmission/uart.v b/uart/uart.v similarity index 100% rename from uart_transmission/uart.v rename to uart/uart.v diff --git a/uart_transmission/uart_ct256.pcf b/uart/uart_ct256.pcf similarity index 100% rename from uart_transmission/uart_ct256.pcf rename to uart/uart_ct256.pcf diff --git a/uart_transmission/uart_tq144.pcf b/uart/uart_tq144.pcf similarity index 100% rename from uart_transmission/uart_tq144.pcf rename to uart/uart_tq144.pcf diff --git a/uart_transmission/uart_trx.v b/uart/uart_trx.v similarity index 100% rename from uart_transmission/uart_trx.v rename to uart/uart_trx.v From c59feddcb8ccab7863ed131d7a1cd294e072edf5 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Wed, 20 Mar 2019 22:30:11 -0400 Subject: [PATCH 23/34] Make a few commands quieter --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 561e27d..59f6831 100644 --- a/Makefile +++ b/Makefile @@ -55,8 +55,8 @@ FORCE: # If they are different, we update the file # If they are the same we don't # Anything which depends on $(BUILD)/DEVICE.var will only update if DEVICE changes -$(BUILD)/%.var: FORCE - @echo $($*) | cmp - $@ || echo $($*) > $@ +$(BUILD)/%.var: FORCE | $(BUILD) + @echo "$($*)" | cmp -s - "$@" || echo "$($*)" > $@ # Keep .var file around even though they are intermediate targets .PRECIOUS: $(BUILD)/%.var @@ -85,4 +85,4 @@ include $(addsuffix /Makefile,$(MODULES)) # Because our sources/pinmaps depend on the makefile # all targets will get rebuilt every time the makefile changes $(SRC): Makefile - touch $@ + @touch $@ From d1cd38e16217d21e8961f69d954340da3280ba34 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Wed, 20 Mar 2019 22:34:51 -0400 Subject: [PATCH 24/34] Switch to board-specific pcfs The old system only worked for a few boards, using package as a proxy Now we can add support for many more boards just by writing up some pcfs --- Makefile | 25 +++---- blank/blank.v | 11 +-- blinky/blinky.v | 40 +++++------ boards/Lattice/ICE40HX1K-STICK-EVN/cfg | 4 ++ boards/Lattice/ICE40HX1K-STICK-EVN/pcf | 93 ++++++++++++++++++++++++++ boards/Lattice/ICE40HX8K-B-EVN/cfg | 4 ++ boards/Olimex/iCE40HX8K-EVB/cfg | 4 ++ boards/Olimex/iCE40HX8K-EVB/pcf | 81 ++++++++++++++++++++++ uart/uart.v | 22 +++--- 9 files changed, 226 insertions(+), 58 deletions(-) create mode 100644 boards/Lattice/ICE40HX1K-STICK-EVN/cfg create mode 100644 boards/Lattice/ICE40HX1K-STICK-EVN/pcf create mode 100644 boards/Lattice/ICE40HX8K-B-EVN/cfg create mode 100644 boards/Olimex/iCE40HX8K-EVB/cfg create mode 100644 boards/Olimex/iCE40HX8K-EVB/pcf diff --git a/Makefile b/Makefile index 59f6831..e09ddac 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,9 @@ # Use := where you can, as it only gets evaluated once -BUILD := build -# ?= allows the user to pass in a device on the command line -DEVICE ?= hx8k +BUILD := build + +BOARD ?= Lattice/ICE40HX1K-STICK-EVN +include boards/$(BOARD)/cfg FAMILY := $(strip $(subst lp,,$(subst hx,, $(subst up,,$(DEVICE))))) -ifeq (8k,$(FAMILY)) -FOOTPRINT := ct256 -else -FOOTPRINT := tq144 -endif ifdef VERBOSE Q := @@ -43,7 +39,7 @@ $(BUILD): # $^ all non-order-only dependencies # $* the stem of an implicit rule -- what % matches in %.blif $(BUILD)/%.blif: %.v | $(BUILD) - $(SYNTH) $(and $(Q),-q) -p "synth_ice40 -top $* -blif $@" $^ + $(SYNTH) $(and $(Q),-q) -p "read_verilog -DLEDS=$(LEDS) -DCLOCK=$(CLOCK) $^; synth_ice40 -top $* -blif $@" # .PHONY causes targets to be rebuilt every make, and built even if there is an up-to-date file # Depending on a .PHONY target will cause the rule to be run every time @@ -65,8 +61,8 @@ $(BUILD)/%: % ln -f $< $@ # Note that yosys does not run if you only change DEVICE, just things from here down -%.asc: %.blif %_$(FOOTPRINT).pcf $(BUILD)/FAMILY.var $(BUILD)/FOOTPRINT.var - $(PNR) $(and $(Q),-q) -d $(FAMILY) -P $(FOOTPRINT) -p $*_$(FOOTPRINT).pcf -o $@ $< +%.asc: %.blif boards/$(BOARD)/pcf $(BUILD)/FAMILY.var $(BUILD)/PACKAGE.var $(BUILD)/BOARD.var + $(PNR) $(and $(Q),-q) -d $(FAMILY) -P $(PACKAGE) -p boards/$(BOARD)/pcf -o $@ $< %.bin: %.asc icepack $< $@ @@ -74,8 +70,8 @@ $(BUILD)/%: % burn-%: $(BUILD)/%.bin iceprog $< -time-%: $(BUILD)/%.asc $(BUILD)/%_$(FOOTPRINT).pcf $(BUILD)/DEVICE.var $(BUILD)/FOOTPRINT.var - icetime -t -d $(DEVICE) -P $(FOOTPRINT) -p $(BUILD)/$*_$(FOOTPRINT).pcf $< +time-%: $(BUILD)/%.asc boards/$(BOARD)/pcf $(BUILD)/DEVICE.var $(BUILD)/PACKAGE.var $(BUILD)/BOARD.var + icetime -t -d $(DEVICE) -P $(PACKAGE) -p boards/$(BOARD)/pcf $< clean: rm -rf $(BUILD) @@ -84,5 +80,6 @@ include $(addsuffix /Makefile,$(MODULES)) # Because our sources/pinmaps depend on the makefile # all targets will get rebuilt every time the makefile changes -$(SRC): Makefile +# Additionally, we need to depend on LEDS and CLOCK +$(SRC): Makefile $(BUILD)/LEDS.var $(BUILD)/CLOCK.var @touch $@ diff --git a/blank/blank.v b/blank/blank.v index 69cc3e1..7cc8708 100644 --- a/blank/blank.v +++ b/blank/blank.v @@ -1,15 +1,8 @@ // Blink an LED provided an input clock /* module */ -module blank (hwclk, led1, led2, led3, led4, led5, led6, led7, led8 ); +module blank (hwclk, led); /* I/O */ input hwclk; - output led1; - output led2; - output led3; - output led4; - output led5; - output led6; - output led7; - output led8; + output [`LEDS - 1:0] led; endmodule diff --git a/blinky/blinky.v b/blinky/blinky.v index b1e537f..0098948 100644 --- a/blinky/blinky.v +++ b/blinky/blinky.v @@ -1,33 +1,25 @@ // Blink an LED provided an input clock + +`default_nettype none + /* module */ -module blinky (hwclk, led1, led2, led3, led4, led5, led6, led7, led8 ); - /* I/O */ +module blinky (hwclk, led); input hwclk; - output led1; - output led2; - output led3; - output led4; - output led5; - output led6; - output led7; - output led8; - - /* Counter register */ - reg [31:0] counter = 32'b0; + output reg [`LEDS - 1:0] led; - /* LED drivers */ - assign led1 = counter[18]; - assign led2 = counter[19]; - assign led3 = counter[20]; - assign led4 = counter[21]; - assign led5 = counter[22]; - assign led6 = counter[23]; - assign led7 = counter[24]; - assign led8 = counter[25]; + /* + * led[`LEDS-1] should blink at 1hz + * the *switching* speed should be 2 hz + */ + parameter cycles = `CLOCK / (2 * `LEDS); + reg [32:0] counter = 32'b0; - /* always */ always @ (posedge hwclk) begin - counter <= counter + 1; + if (counter == cycles) begin + led <= led + 1; + counter <= 32'b0; + end else + counter <= counter + 1; end endmodule diff --git a/boards/Lattice/ICE40HX1K-STICK-EVN/cfg b/boards/Lattice/ICE40HX1K-STICK-EVN/cfg new file mode 100644 index 0000000..de7c1ce --- /dev/null +++ b/boards/Lattice/ICE40HX1K-STICK-EVN/cfg @@ -0,0 +1,4 @@ +DEVICE := hx1k +PACKAGE := tq144 +LEDS := 5 +CLOCK := 32'd12_000_000 diff --git a/boards/Lattice/ICE40HX1K-STICK-EVN/pcf b/boards/Lattice/ICE40HX1K-STICK-EVN/pcf new file mode 100644 index 0000000..fc2fdd7 --- /dev/null +++ b/boards/Lattice/ICE40HX1K-STICK-EVN/pcf @@ -0,0 +1,93 @@ +# Copyright 2015 Al Williams, 2019 Sean Anderson +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Generic iCEstick placement constraints file + +# 12 MHz clock +set_io -nowarn iCE_CLK 21 +set_io -nowarn hwclk 21 + +# Red LEDs +set_io -nowarn LED0 99 +set_io -nowarn led[0] 99 +set_io -nowarn LED1 98 +set_io -nowarn led[1] 98 +set_io -nowarn LED2 97 +set_io -nowarn led[2] 97 +set_io -nowarn LED3 96 +set_io -nowarn led[3] 96 + +# Green LED +set_io -nowarn LED4 95 +set_io -nowarn led[4] 95 + +# IrDA port +set_io -nowarn RXD 106 +set_io -nowarn TXD 105 +set_io -nowarn SD 107 + +# Pmod connector +set_io -nowarn PIO1_02 78 # Pin 1 +set_io -nowarn PIO1_03 79 # Pin 2 +set_io -nowarn PIO1_04 80 # Pin 3 +set_io -nowarn PIO1_05 81 # Pin 4 +set_io -nowarn PIO1_06 87 # Pin 7 +set_io -nowarn PIO1_07 88 # Pin 8 +set_io -nowarn PIO1_08 90 # Pin 9 +set_io -nowarn PIO1_09 91 # Pin 10 + +# Connector J1 +set_io -nowarn PIO0_02 112 # Pin 3 +set_io -nowarn PIO0_03 113 # Pin 4 +set_io -nowarn PIO0_04 114 # Pin 5 +set_io -nowarn PIO0_05 115 # Pin 6 +set_io -nowarn PIO0_06 116 # Pin 7 +set_io -nowarn PIO0_07 117 # Pin 8 +set_io -nowarn PIO0_08 118 # Pin 9 +set_io -nowarn PIO0_09 119 # Pin 10 + +# Connector J3 +set_io -nowarn PIO2_17 62 # Pin 3 +set_io -nowarn PIO2_16 61 # Pin 4 +set_io -nowarn PIO2_15 60 # Pin 5 +set_io -nowarn PIO2_14 56 # Pin 6 +set_io -nowarn PIO2_13 48 # Pin 7 +set_io -nowarn PIO2_12 47 # Pin 8 +set_io -nowarn PIO2_11 45 # Pin 9 +set_io -nowarn PIO2_10 44 # Pin 10 + +# FTDI Port B UART +set_io -nowarn DCDn 1 +set_io -nowarn DSRn 2 +set_io -nowarn DTRn 3 +set_io -nowarn CTSn 4 +set_io -nowarn RTSn 7 +set_io -nowarn RS232_Tx_TTL 8 +set_io -nowarn uart_tx 8 +set_io -nowarn RS232_Rx_TTL 9 +set_io -nowarn uart_rx 9 + +# SPI +set_io -nowarn iCE_SCK 70 +set_io -nowarn sck 70 +set_io -nowarn iCE_MISO 68 +set_io -nowarn sdi 68 +set_io -nowarn iCE_MOSI 67 +set_io -nowarn sdo 67 +set_io -nowarn iCE_SS_B 71 +set_io -nowarn ss 71 + +# Configuration pins +set_io -nowarn CDONE 65 +set_io -nowarn CRESET 66 diff --git a/boards/Lattice/ICE40HX8K-B-EVN/cfg b/boards/Lattice/ICE40HX8K-B-EVN/cfg new file mode 100644 index 0000000..d8255cd --- /dev/null +++ b/boards/Lattice/ICE40HX8K-B-EVN/cfg @@ -0,0 +1,4 @@ +DEVICE := hx8k +PACKAGE := ct256 +LEDS := 8 +CLOCK := 32'd12_000_000 diff --git a/boards/Olimex/iCE40HX8K-EVB/cfg b/boards/Olimex/iCE40HX8K-EVB/cfg new file mode 100644 index 0000000..bdd4631 --- /dev/null +++ b/boards/Olimex/iCE40HX8K-EVB/cfg @@ -0,0 +1,4 @@ +DEVICE := hx8k +PACKAGE := ct256 +LEDS := 2 +CLOCK := 32'd100_000_000 diff --git a/boards/Olimex/iCE40HX8K-EVB/pcf b/boards/Olimex/iCE40HX8K-EVB/pcf new file mode 100644 index 0000000..d46edad --- /dev/null +++ b/boards/Olimex/iCE40HX8K-EVB/pcf @@ -0,0 +1,81 @@ +# Whenever possible, pin names have been taken from the official schematic +# + +# Clock +set_io -nowarn SYSCLK J3 +set_io -nowarn hwclk J3 + +# LEDs +set_io -nowarn LED1 M12 +set_io -nowarn led[0] M12 +set_io -nowarn LED2 R16 +set_io -nowarn led[1] R16 + +# Buttons +set_io -nowarn BUT1 K11 +set_io -nowarn but[0] K11 +set_io -nowarn BUT2 P13 +set_io -nowarn but[1] P13 + +# SPI Flash +set_io -nowarn iCE40-CDONE M10 +set_io -nowarn iCE40-CRESET N11 +set_io -nowarn iCE40-SDO P12 +set_io -nowarn sdo P12 +set_io -nowarn iCE40-SDI P11 +set_io -nowarn sdi P11 +set_io -nowarn iCE40-SCK R11 +set_io -nowarn sck R11 +set_io -nowarn iCE40-SS_B R12 +set_io -nowarn ss R12 + +# Programming connector +set_io -nowarn RxD L11 +set_io -nowarn uart_rx L11 +set_io -nowarn TxD T16 +set_io -nowarn uart_tx T16 + +# SRAM +set_io -nowarn SRAM_CS T6 +set_io -nowarn SRAM_OE L9 +set_io -nowarn SRAM_WE T7 +set_io -nowarn SA[0] N6 +set_io -nowarn SA[1] T1 +set_io -nowarn SA[2] P4 +set_io -nowarn SA[3] R2 +set_io -nowarn SA[4] N5 +set_io -nowarn SA[5] T2 +set_io -nowarn SA[6] P5 +set_io -nowarn SA[7] R3 +set_io -nowarn SA[8] R5 +set_io -nowarn SA[9] T3 +set_io -nowarn SA[10] R4 +set_io -nowarn SA[11] M7 +set_io -nowarn SA[12] N7 +set_io -nowarn SA[13] P6 +set_io -nowarn SA[14] M8 +set_io -nowarn SA[15] T5 +set_io -nowarn SA[16] R6 +set_io -nowarn SA[17] P8 +set_io -nowarn SD[0] T8 +set_io -nowarn SD[1] P7 +set_io -nowarn SD[2] N9 +set_io -nowarn SD[3] T9 +set_io -nowarn SD[4] M9 +set_io -nowarn SD[5] R9 +set_io -nowarn SD[6] K9 +set_io -nowarn SD[7] P9 +set_io -nowarn SD[8] R10 +set_io -nowarn SD[9] L10 +set_io -nowarn SD[10] P10 +set_io -nowarn SD[11] N10 +set_io -nowarn SD[12] T10 +set_io -nowarn SD[13] T11 +set_io -nowarn SD[14] T15 +set_io -nowarn SD[15] T14 + +# JTAG +set_io -nowarn TDI R14 +set_io -nowarn TMS R15 +set_io -nowarn TCK P14 +set_io -nowarn TDO P15 diff --git a/uart/uart.v b/uart/uart.v index d50841d..42a7126 100644 --- a/uart/uart.v +++ b/uart/uart.v @@ -3,29 +3,29 @@ module uart ( // input hardware clock (12 MHz) hwclk, // all LEDs - led1, + led, // UART lines - ftdi_tx, + uart_tx, ); /* Clock input */ input hwclk; /* LED outputs */ - output led1; + output [`LEDS - 1:0] led; - /* FTDI I/O */ - output ftdi_tx; + /* uart I/O */ + output uart_tx; - /* 9600 Hz clock generation (from 12 MHz) */ + /* 9600 Hz clock generation (from 100 MHz) */ reg clk_9600 = 0; reg [31:0] cntr_9600 = 32'b0; - parameter period_9600 = 625; + parameter period_9600 = 434; - /* 1 Hz clock generation (from 12 MHz) */ + /* 1 Hz clock generation (from 100 MHz) */ reg clk_1 = 0; reg [31:0] cntr_1 = 32'b0; - parameter period_1 = 6000000; + parameter period_1 = 50000000; // Note: could also use "0" or "9" below, but I wanted to // be clear about what the actual binary value is. @@ -53,11 +53,11 @@ module uart ( // input: tx is finished .txdone (uart_txed), // output UART tx pin - .tx (ftdi_tx), + .tx (uart_tx), ); /* Wiring */ - assign led1=ledval; + assign led[0] = ledval; /* Low speed clock generation */ always @ (posedge hwclk) begin From 97bf80766923544556742f46cf7d4e0659ec4585 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Wed, 20 Mar 2019 22:36:14 -0400 Subject: [PATCH 25/34] Load previous variables on start This allows us to save config options like the BOARD used --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index e09ddac..49df310 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,9 @@ # Use := where you can, as it only gets evaluated once BUILD := build +# Load previous values of variables +$(foreach VARIABLE,$(wildcard $(BUILD)/*.var),$(eval $(basename $(notdir $(VARIABLE))) ?= $(shell cat $(VARIABLE)))) + BOARD ?= Lattice/ICE40HX1K-STICK-EVN include boards/$(BOARD)/cfg FAMILY := $(strip $(subst lp,,$(subst hx,, $(subst up,,$(DEVICE))))) From e1616f64c64e2aa3ff5016653cbf99899d7ff23f Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Wed, 20 Mar 2019 22:38:59 -0400 Subject: [PATCH 26/34] Remove unused pcf files --- blank/blank_ct256.pcf | 10 ---------- blinky/blinky_ct256.pcf | 10 ---------- uart/uart_ct256.pcf | 13 ------------- uart/uart_tq144.pcf | 10 ---------- 4 files changed, 43 deletions(-) delete mode 100644 blank/blank_ct256.pcf delete mode 100644 blinky/blinky_ct256.pcf delete mode 100644 uart/uart_ct256.pcf delete mode 100644 uart/uart_tq144.pcf diff --git a/blank/blank_ct256.pcf b/blank/blank_ct256.pcf deleted file mode 100644 index aded2bf..0000000 --- a/blank/blank_ct256.pcf +++ /dev/null @@ -1,10 +0,0 @@ -# example.pcf -set_io --warn-no-port led1 B5 -set_io --warn-no-port led2 B4 -set_io --warn-no-port led3 A2 -set_io --warn-no-port led4 A1 -set_io --warn-no-port led5 C5 -set_io --warn-no-port led6 C4 -set_io --warn-no-port led7 B3 -set_io --warn-no-port led8 C3 -set_io --warn-no-port hwclk J3 \ No newline at end of file diff --git a/blinky/blinky_ct256.pcf b/blinky/blinky_ct256.pcf deleted file mode 100644 index aded2bf..0000000 --- a/blinky/blinky_ct256.pcf +++ /dev/null @@ -1,10 +0,0 @@ -# example.pcf -set_io --warn-no-port led1 B5 -set_io --warn-no-port led2 B4 -set_io --warn-no-port led3 A2 -set_io --warn-no-port led4 A1 -set_io --warn-no-port led5 C5 -set_io --warn-no-port led6 C4 -set_io --warn-no-port led7 B3 -set_io --warn-no-port led8 C3 -set_io --warn-no-port hwclk J3 \ No newline at end of file diff --git a/uart/uart_ct256.pcf b/uart/uart_ct256.pcf deleted file mode 100644 index c6fe96a..0000000 --- a/uart/uart_ct256.pcf +++ /dev/null @@ -1,13 +0,0 @@ -# example.pcf -set_io --warn-no-port led1 B5 -set_io --warn-no-port led2 B4 -set_io --warn-no-port led3 A2 -set_io --warn-no-port led4 A1 -set_io --warn-no-port led5 C5 -set_io --warn-no-port led6 C4 -set_io --warn-no-port led7 B3 -set_io --warn-no-port led8 C3 -set_io --warn-no-port hwclk J3 -# FTDI / UART pins -set_io --warn-no-port ftdi_tx B12 -set_io --warn-no-port ftdi_rx B10 \ No newline at end of file diff --git a/uart/uart_tq144.pcf b/uart/uart_tq144.pcf deleted file mode 100644 index 08e8e33..0000000 --- a/uart/uart_tq144.pcf +++ /dev/null @@ -1,10 +0,0 @@ -# example.pcf -set_io --warn-no-port led1 99 -set_io --warn-no-port led2 98 -set_io --warn-no-port led3 97 -set_io --warn-no-port led4 96 -set_io --warn-no-port led5 95 -set_io --warn-no-port hwclk 21 -# FTDI / UART pins -set_io --warn-no-port ftdi_tx 8 -set_io --warn-no-port ftdi_rx 9 From 40d91d492ed75955f1fd2401891be80abf38dbbb Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Wed, 20 Mar 2019 22:38:07 -0400 Subject: [PATCH 27/34] Remove unused variable M_SRC --- common.mk | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/common.mk b/common.mk index 0e7b7fc..b53c3b2 100644 --- a/common.mk +++ b/common.mk @@ -18,14 +18,11 @@ endif VPATH += $(DIR) M_VSRC := $(addprefix $(DIR),$(M_VSRC)) -M_SRC := $(M_VSRC) $(addprefix $(DIR),$(M_SRC)) -SRC += $(M_SRC) +SRC += $(M_VSRC) .PHONY: $(MODULE) $(MODULE): $(BUILD)/$(MODULE).bin -$(M_SRC): $(DIR)Makefile $(lastword $(MAKEFILE_LIST)) - $(BUILD)/$(MODULE).blif: $(M_VSRC) ifdef BUILD From 8e327a38732a5f5bc455036e154a4a59fa140e02 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Wed, 20 Mar 2019 22:37:08 -0400 Subject: [PATCH 28/34] Add option to customize flash program Easy to create a script to do any custom flash job --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 49df310..8f1981f 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ endif PNR ?= arachne-pnr SYNTH ?= yosys +FLASH ?= iceprog # Necessary so VPATH doesn't get reinterpreted VPATH := @@ -70,8 +71,8 @@ $(BUILD)/%: % %.bin: %.asc icepack $< $@ -burn-%: $(BUILD)/%.bin - iceprog $< +burn-%: $(BUILD)/%.bin $(BUILD)/FLASH.var + $(FLASH) $< time-%: $(BUILD)/%.asc boards/$(BOARD)/pcf $(BUILD)/DEVICE.var $(BUILD)/PACKAGE.var $(BUILD)/BOARD.var icetime -t -d $(DEVICE) -P $(PACKAGE) -p boards/$(BOARD)/pcf $< From 2914342c6f42f63929b382af996de9d8fd98fc6c Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Wed, 20 Mar 2019 22:39:36 -0400 Subject: [PATCH 29/34] Add passthrough project This is roughly from http://zipcpu.com/tutorial/lsn-01-wires.pdf Very useful for testing --- Makefile | 2 +- passthrough/Makefile | 4 ++++ passthrough/passthrough.v | 13 +++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 passthrough/Makefile create mode 100644 passthrough/passthrough.v diff --git a/Makefile b/Makefile index 8f1981f..c6dbb17 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ FLASH ?= iceprog # Necessary so VPATH doesn't get reinterpreted VPATH := -MODULES := uart blank blinky +MODULES := uart blank blinky passthrough # SRC holds all source files SRC := diff --git a/passthrough/Makefile b/passthrough/Makefile new file mode 100644 index 0000000..a09d5b0 --- /dev/null +++ b/passthrough/Makefile @@ -0,0 +1,4 @@ +MODULE := passthrough +M_VSRC := passthrough.v + +include $(realpath $(dir $(lastword $(MAKEFILE_LIST))))/../common.mk diff --git a/passthrough/passthrough.v b/passthrough/passthrough.v new file mode 100644 index 0000000..cfe8fb5 --- /dev/null +++ b/passthrough/passthrough.v @@ -0,0 +1,13 @@ +/* Just pass through buttons to LEDs and RxD to TxD */ + +module passthrough (but, led, uart_tx, uart_rx); + /* I/O */ + input [`LED-1:0] but; + input uart_rx; + output uart_tx; + output [`LED-1:0] led; + + assign but = led; + assign uart_tx = uart_rx; + +endmodule From 9f15b1cc915f8874fe4a5fb6198bef1fd6b186ad Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Fri, 22 Mar 2019 18:37:58 -0400 Subject: [PATCH 30/34] Add BUTS variable for buttons If we do `BUTS :=` that means there are *no* buttons. You can test for this with ifdef in your verilog --- Makefile | 15 ++++++++++----- boards/Lattice/ICE40HX1K-STICK-EVN/cfg | 1 + boards/Lattice/ICE40HX8K-B-EVN/cfg | 1 + boards/Olimex/iCE40HX8K-EVB/cfg | 1 + 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index c6dbb17..f327e5e 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,13 @@ BUILD := build # Load previous values of variables -$(foreach VARIABLE,$(wildcard $(BUILD)/*.var),$(eval $(basename $(notdir $(VARIABLE))) ?= $(shell cat $(VARIABLE)))) +VARS := $(foreach VAR,$(wildcard $(BUILD)/*.var),$(basename $(notdir $(VARIABLE)))) +$(foreach VAR,$(VARS),$(eval $(VAR) ?= $(shell cat $(BUILD)/$(VAR).var))) +# List of variables set by the board cfg +# We don't just use VARS since this could be the first run, +# so some of these variables may not have a .var file +BOARD_VARS := BOARD DEVICE PACKAGE LEDS BUTS CLOCK BOARD ?= Lattice/ICE40HX1K-STICK-EVN include boards/$(BOARD)/cfg FAMILY := $(strip $(subst lp,,$(subst hx,, $(subst up,,$(DEVICE))))) @@ -43,7 +48,7 @@ $(BUILD): # $^ all non-order-only dependencies # $* the stem of an implicit rule -- what % matches in %.blif $(BUILD)/%.blif: %.v | $(BUILD) - $(SYNTH) $(and $(Q),-q) -p "read_verilog -DLEDS=$(LEDS) -DCLOCK=$(CLOCK) $^; synth_ice40 -top $* -blif $@" + $(SYNTH) $(and $(Q),-q) -p "read_verilog $(foreach VAR,$(BOARD_VARS),$(and $($(VAR)),-D$(VAR)=$($(VAR)))) $^; synth_ice40 -top $* -blif $@" # .PHONY causes targets to be rebuilt every make, and built even if there is an up-to-date file # Depending on a .PHONY target will cause the rule to be run every time @@ -65,7 +70,7 @@ $(BUILD)/%: % ln -f $< $@ # Note that yosys does not run if you only change DEVICE, just things from here down -%.asc: %.blif boards/$(BOARD)/pcf $(BUILD)/FAMILY.var $(BUILD)/PACKAGE.var $(BUILD)/BOARD.var +%.asc: %.blif boards/$(BOARD)/pcf $(BUILD)/FAMILY.var $(BUILD)/PACKAGE.var $(BUILD)/BOARD.var $(BUILD)/PNR.var $(PNR) $(and $(Q),-q) -d $(FAMILY) -P $(PACKAGE) -p boards/$(BOARD)/pcf -o $@ $< %.bin: %.asc @@ -84,6 +89,6 @@ include $(addsuffix /Makefile,$(MODULES)) # Because our sources/pinmaps depend on the makefile # all targets will get rebuilt every time the makefile changes -# Additionally, we need to depend on LEDS and CLOCK -$(SRC): Makefile $(BUILD)/LEDS.var $(BUILD)/CLOCK.var +# Additionally, we need to depend on BOARD (and SYNTH since this is the only place for it) +$(SRC): Makefile $(BUILD)/BOARD.var $(BUILD)/SYNTH.var @touch $@ diff --git a/boards/Lattice/ICE40HX1K-STICK-EVN/cfg b/boards/Lattice/ICE40HX1K-STICK-EVN/cfg index de7c1ce..f69d3c5 100644 --- a/boards/Lattice/ICE40HX1K-STICK-EVN/cfg +++ b/boards/Lattice/ICE40HX1K-STICK-EVN/cfg @@ -1,4 +1,5 @@ DEVICE := hx1k PACKAGE := tq144 LEDS := 5 +BUTS := CLOCK := 32'd12_000_000 diff --git a/boards/Lattice/ICE40HX8K-B-EVN/cfg b/boards/Lattice/ICE40HX8K-B-EVN/cfg index d8255cd..e215e95 100644 --- a/boards/Lattice/ICE40HX8K-B-EVN/cfg +++ b/boards/Lattice/ICE40HX8K-B-EVN/cfg @@ -1,4 +1,5 @@ DEVICE := hx8k PACKAGE := ct256 LEDS := 8 +BUTS := CLOCK := 32'd12_000_000 diff --git a/boards/Olimex/iCE40HX8K-EVB/cfg b/boards/Olimex/iCE40HX8K-EVB/cfg index bdd4631..a6b57ab 100644 --- a/boards/Olimex/iCE40HX8K-EVB/cfg +++ b/boards/Olimex/iCE40HX8K-EVB/cfg @@ -1,4 +1,5 @@ DEVICE := hx8k PACKAGE := ct256 LEDS := 2 +BUTS := 2 CLOCK := 32'd100_000_000 From 94119f6ba83e28aadfb42a5714e6e9e197b20682 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Fri, 22 Mar 2019 18:39:11 -0400 Subject: [PATCH 31/34] Modify passthrough to use BUTS --- passthrough/passthrough.v | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/passthrough/passthrough.v b/passthrough/passthrough.v index cfe8fb5..8c30ae2 100644 --- a/passthrough/passthrough.v +++ b/passthrough/passthrough.v @@ -1,13 +1,21 @@ /* Just pass through buttons to LEDs and RxD to TxD */ -module passthrough (but, led, uart_tx, uart_rx); - /* I/O */ - input [`LED-1:0] but; - input uart_rx; - output uart_tx; - output [`LED-1:0] led; +`ifdef BUTS +`endif +module passthrough ( + `ifdef BUTS + input [width - 1:0] but, + output [width - 1:0] led, + `endif + input uart_rx, + output uart_tx +); + +`ifdef BUTS + parameter width = `LEDS > `BUTS ? `BUTS : `LEDS; assign but = led; +`endif assign uart_tx = uart_rx; endmodule From f01ee0f25d02c596a2eff3ed5e7fe271b062ce1d Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Sun, 24 Mar 2019 13:33:11 -0400 Subject: [PATCH 32/34] Finish removing references to per-project pcfs --- blank/Makefile | 1 - blinky/Makefile | 1 - uart/Makefile | 1 - 3 files changed, 3 deletions(-) diff --git a/blank/Makefile b/blank/Makefile index 9d23292..dc564b0 100644 --- a/blank/Makefile +++ b/blank/Makefile @@ -1,5 +1,4 @@ MODULE := blank M_VSRC := blank.v -M_SRC := blank_ct256.pcf include $(realpath $(dir $(lastword $(MAKEFILE_LIST))))/../common.mk diff --git a/blinky/Makefile b/blinky/Makefile index ef1bad6..7ae39c2 100644 --- a/blinky/Makefile +++ b/blinky/Makefile @@ -1,5 +1,4 @@ MODULE := blinky M_VSRC := blinky.v -M_SRC := blinky_ct256.pcf include $(realpath $(dir $(lastword $(MAKEFILE_LIST))))/../common.mk diff --git a/uart/Makefile b/uart/Makefile index 8843caa..1740ae1 100644 --- a/uart/Makefile +++ b/uart/Makefile @@ -1,5 +1,4 @@ MODULE := uart M_VSRC := uart.v uart_trx.v -M_SRC := uart_ct256.pcf uart_tq144.pcf include $(realpath $(dir $(lastword $(MAKEFILE_LIST))))/../common.mk From c5a21a9d58eb6b1991ca03e0a1bbeb5bbf6b6da5 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Sun, 24 Mar 2019 13:35:48 -0400 Subject: [PATCH 33/34] Split defined into their own variable; set default nettype none globally --- Makefile | 11 ++++++----- blinky/blinky.v | 2 -- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index f327e5e..c5b15f8 100644 --- a/Makefile +++ b/Makefile @@ -5,13 +5,14 @@ BUILD := build VARS := $(foreach VAR,$(wildcard $(BUILD)/*.var),$(basename $(notdir $(VARIABLE)))) $(foreach VAR,$(VARS),$(eval $(VAR) ?= $(shell cat $(BUILD)/$(VAR).var))) -# List of variables set by the board cfg -# We don't just use VARS since this could be the first run, -# so some of these variables may not have a .var file -BOARD_VARS := BOARD DEVICE PACKAGE LEDS BUTS CLOCK BOARD ?= Lattice/ICE40HX1K-STICK-EVN include boards/$(BOARD)/cfg FAMILY := $(strip $(subst lp,,$(subst hx,, $(subst up,,$(DEVICE))))) +# List of variables set by the board cfg +# We don't just use VARS since this could be the first run, +# so some of these variables may not have a .var file +BOARD_VARS := DEVICE PACKAGE LEDS BUTS CLOCK +BOARD_DEFINES := $(foreach VAR,$(BOARD_VARS),$(and $($(VAR)),-D$(VAR)=$($(VAR)))) ifdef VERBOSE Q := @@ -48,7 +49,7 @@ $(BUILD): # $^ all non-order-only dependencies # $* the stem of an implicit rule -- what % matches in %.blif $(BUILD)/%.blif: %.v | $(BUILD) - $(SYNTH) $(and $(Q),-q) -p "read_verilog $(foreach VAR,$(BOARD_VARS),$(and $($(VAR)),-D$(VAR)=$($(VAR)))) $^; synth_ice40 -top $* -blif $@" + $(SYNTH) $(and $(Q),-q) -p "read_verilog -noautowire $(BOARD_DEFINES) $^; synth_ice40 -top $* -blif $@" # .PHONY causes targets to be rebuilt every make, and built even if there is an up-to-date file # Depending on a .PHONY target will cause the rule to be run every time diff --git a/blinky/blinky.v b/blinky/blinky.v index 0098948..6ccd4e9 100644 --- a/blinky/blinky.v +++ b/blinky/blinky.v @@ -1,7 +1,5 @@ // Blink an LED provided an input clock -`default_nettype none - /* module */ module blinky (hwclk, led); input hwclk; From ca903965c263ce90923621931033384c8bf35025 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Sun, 24 Mar 2019 13:36:51 -0400 Subject: [PATCH 34/34] Add verilator support (broken) --- Makefile | 46 +++++++++++++++++-- common.mk | 5 +- passthrough/Makefile | 1 + passthrough/passthrough.cpp | 92 +++++++++++++++++++++++++++++++++++++ passthrough/passthrough.v | 3 -- 5 files changed, 139 insertions(+), 8 deletions(-) create mode 100644 passthrough/passthrough.cpp diff --git a/Makefile b/Makefile index c5b15f8..37dcde0 100644 --- a/Makefile +++ b/Makefile @@ -31,12 +31,12 @@ MODULES := uart blank blinky passthrough # SRC holds all source files SRC := -.PHONY: all clean burn-% time-% FORCE +.PHONY: all clean burn-% time-% test-% cov-% FORCE all: $(BUILD): - mkdir -p $(BUILD) + mkdir -p $@ # First pattern rule creates a .blif from a .v # We also have an order-only prerequisite on the build dir @@ -88,8 +88,46 @@ clean: include $(addsuffix /Makefile,$(MODULES)) +# The following snippet Copyright 2003-2019 by Wilson Snyder, 2019 Sean Anderson +# This program is free software; you can redistribute it and/or modify +# it under the terms of either the GNU Lesser General Public License Version 3 +# or the Perl Artistic License Version 2.0. + +VERILATOR ?= verilator +VERILATOR_COVERAGE ?= verilator_coverage +# Generate C++ in executable form +VERILATOR_FLAGS += -cc --exe +# Optimize +VERILATOR_FLAGS += -O2 -x-assign 0 +# Warn abount lint issues; may not want this on less solid designs +VERILATOR_FLAGS += -Wall +# Make waveforms +VERILATOR_FLAGS += --trace +# Check SystemVerilog assertions +VERILATOR_FLAGS += --assert +# Generate coverage analysis +VERILATOR_FLAGS += --coverage +# end snippet + +# Similar to BOARD_DEFINES, but we need to be careful to remove non-c-friendly characters +# signed numbers are NOT supported +sanitize = $(lastword $(subst 'h,' 0x,$(subst 'd,' ,$(subst _,,$1)))) +export USER_CPPFLAGS := $(foreach VAR,$(BOARD_VARS),$(and $($(VAR)),-D$(VAR)=$(call sanitize,$($(VAR))))) + +$(BUILD)/test-%: + mkdir -p $@ + +test-%: | $(BUILD)/test-% + $(VERILATOR) $(VERILATOR_FLAGS) $$(echo "$(BOARD_DEFINES)") -Mdir $(BUILD)/test-$* --prefix $* $^ + $(MAKE) -C $(BUILD)/test-$* -f $*.mk + $(BUILD)/test-$*/$* +trace + +cov-%: test-% + $(VERILATOR_COVERAGE) --annotate $(BUILD)/test-$*/logs/annotated $(BUILD)/test-$*/logs/coverage.dat + # Because our sources/pinmaps depend on the makefile # all targets will get rebuilt every time the makefile changes -# Additionally, we need to depend on BOARD (and SYNTH since this is the only place for it) -$(SRC): Makefile $(BUILD)/BOARD.var $(BUILD)/SYNTH.var +# Additionally, we need to depend on BOARD +# (and SYNTH/VERILATOR* since this is the only place to put it) +$(SRC): Makefile $(BUILD)/BOARD.var $(BUILD)/SYNTH.var $(BUILD)/VERILATOR.var $(BUILD)/VERILATOR_COVERAGE.var @touch $@ diff --git a/common.mk b/common.mk index b53c3b2..a8286a3 100644 --- a/common.mk +++ b/common.mk @@ -18,13 +18,16 @@ endif VPATH += $(DIR) M_VSRC := $(addprefix $(DIR),$(M_VSRC)) -SRC += $(M_VSRC) +M_CSRC := $(addprefix $(DIR),$(M_CSRC)) +SRC += $(M_VSRC) $(M_CSRC) .PHONY: $(MODULE) $(MODULE): $(BUILD)/$(MODULE).bin $(BUILD)/$(MODULE).blif: $(M_VSRC) +test-$(MODULE): $(M_VSRC) $(M_CSRC) + ifdef BUILD all: $(MODULE) endif diff --git a/passthrough/Makefile b/passthrough/Makefile index a09d5b0..db61303 100644 --- a/passthrough/Makefile +++ b/passthrough/Makefile @@ -1,4 +1,5 @@ MODULE := passthrough M_VSRC := passthrough.v +M_CSRC := passthrough.cpp include $(realpath $(dir $(lastword $(MAKEFILE_LIST))))/../common.mk diff --git a/passthrough/passthrough.cpp b/passthrough/passthrough.cpp new file mode 100644 index 0000000..52197e9 --- /dev/null +++ b/passthrough/passthrough.cpp @@ -0,0 +1,92 @@ +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2017 by Wilson Snyder. +//====================================================================== + +// Include common routines +#include + +// Include model header, generated from Verilating "tb.v" +#include "Vtb.h" + +// If "verilator --trace" is used, include the tracing class +#if VM_TRACE +# include +#endif + +// Current simulation time (64-bit unsigned) +vluint64_t main_time = 0; +// Called by $time in Verilog +double sc_time_stamp() { + return main_time; // Note does conversion to real, to match SystemC +} + +int main(int argc, char** argv) { + + // Pass arguments so Verilated code can see them, e.g. $value$plusargs + Verilated::commandArgs(argc, argv); + // Set debug level, 0 is off, 9 is highest presently used + Verilated::debug(0); + // Randomize values on reset + Verilated::randReset(2); + + // Construct the Verilated model, from Vtb.h generated from Verilating "tb.v" + Vpassthrough* tb = new Vpassthrough; // Or use a const unique_ptr, or the VL_UNIQUE_PTR wrapper + +#if VM_TRACE + // If verilator was invoked with --trace argument, + // and if at run time passed the +trace argument, turn on tracing + VerilatedVcdC* tfp = NULL; + const char* flag = Verilated::commandArgsPlusMatch("trace"); + if (flag && 0==strcmp(flag, "+trace")) { + Verilated::traceEverOn(true); // Verilator must compute traced signals + VL_PRINTF("Enabling waves into logs/vlt_dump.vcd...\n"); + tfp = new VerilatedVcdC; + tb->trace(tfp, 99); // Trace 99 levels of hierarchy + Verilated::mkdir("logs"); + tfp->open("logs/vlt_dump.vcd"); // Open the dump file + } +#endif + + // Set some inputs + tb->but = 0; + tb->uart_rx = 0; + + for (; main_time < 20; main_time++) { + tb->but = main_time & 3; + tb->uart_rx = !!(main_time & 4); + + // Evaluate model + tb->eval(); + +#if VM_TRACE + // Dump trace data for this cycle + if (tfp) + tfp->dump(main_time); +#endif + + // Read outputs + VL_PRINTF("[%" VL_PRI64 "d] but=%x led=%x uart_rx=%x uart_tx=%x\n", + main_clock, tb->but, tb->led, tb->uart_rx, tb->uart_tx); + } + + // Final model cleanup + tb->final(); + + // Close trace if opened +#if VM_TRACE + if (tfp) + tfp->close(); +#endif + + // Coverage analysis (since test passed) +#if VM_COVERAGE + Verilated::mkdir("logs"); + VerilatedCov::write("logs/coverage.dat"); +#endif + + // Destroy model + delete tb; + + // Fin + exit(0); +} diff --git a/passthrough/passthrough.v b/passthrough/passthrough.v index 8c30ae2..73673e5 100644 --- a/passthrough/passthrough.v +++ b/passthrough/passthrough.v @@ -1,8 +1,5 @@ /* Just pass through buttons to LEDs and RxD to TxD */ -`ifdef BUTS -`endif - module passthrough ( `ifdef BUTS input [width - 1:0] but,