-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile.template
190 lines (157 loc) · 5.41 KB
/
Makefile.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# define project name, and should be same as top module name and also used as final bitstream filename.
PROJECT = blink
# available devices: nexus/ecp5/ice40/gowin. machxo2 had limited support for 1200, not enabled now.
DEVICE = ice40
# sources list seperated by space. for multiple source files, the top module should be first one in list.
SOURCES = blink.v
############################################
# options per ARCH #
############################################
# for Lattice Nexus devices
ifeq ($(strip $(DEVICE)), nexus)
NEXUS_DEVICE = LIFCL-40-8SG72C
FREQUENCY = 65
# physical constraints file
PC_FILE = io.pdc
OBJECT = $(PROJECT).bit
endif
# for Lattice ECP5 devices
ifeq ($(strip $(DEVICE)), ecp5)
# for colorlight-i9
FPGA_TYPE = 45k
FPGA_PACKAGE = CABGA381
# FREQUENCY of Colorlight-i9
FREQUENCY = 25
SPEED = 6
# for colorlight-i5
#FPGA_TYPE = 25k
#FPGA_PACKAGE = CABGA381
#FREQUENCY = 25
#SPEED = 6
# for 5a-75b-v7.0/i7
#FPGA_TYPE = 25k
#FPGA_PACKAGE = CABGA256
#FREQUENCY = 25
#SPEED = 6
PC_FILE = io.lpf
OBJECT = $(PROJECT).bit
endif
# for Lattice iCE40 devices
ifeq ($(strip $(DEVICE)), ice40)
# for icesugar-nano-lp1k
#FPGA_TYPE = lp1k
#FPGA_PACKAGE = cm36
# the default freq is 12Mhz and can be changed with 'icesprog'
#FREQUENCY = 12
# for icesugar-up5k
FPGA_TYPE = up5k
FPGA_PACKAGE = sg48
# FREQUENCY of icesugar is 12Mhz and can not be changed.
FREQUENCY = 12
PC_FILE = io.pcf
OBJECT = $(PROJECT).rpt $(PROJECT).bin
endif
# for Gowin LittleBee devices
ifeq ($(strip $(DEVICE)), gowin)
# tang nano
#GOWIN_DEVICE = GW1N-LV1QN48C6/I5
#GOWIN_PACK_DEVICE = GW1N-1
#PC_FILE = tangnano.cst
# tang nano 1k
#GOWIN_DEVICE = GW1NZ-LV1QN48C6/I5
#GOWIN_PACK_DEVICE = GW1NZ-1
#PC_FILE = tangnano1k.cst
# tang nano 4k
#GOWIN_DEVICE = GW1NSR-LV4CQN48PC7/I6
#GOWIN_PACK_DEVICE = GW1NS-4
#PC_FILE = tangnano4k.cst
# tang nano 9k
GOWIN_DEVICE = GW1NR-LV9QN88PC6/I5
GOWIN_PACK_DEVICE = GW1N-9C
PC_FILE = tangnano9k.cst
OBJECT = $(PROJECT).fs
endif
all: $(OBJECT)
############################################
# Synthesis #
############################################
top.json: $(SOURCES)
yosys -ql ${PROJECT}-yosys.log -p "read_verilog $<; synth_$(strip $(DEVICE)) -json $@" $(SOURCES)
############################################
# place and route and pack #
############################################
# for Lattice Nexus devices
ifeq ($(strip $(DEVICE)), nexus)
top.fasm: top.json $(PC_FILE)
nextpnr-$(DEVICE) -ql ${PROJECT}-nextpnr.log --device ${NEXUS_DEVICE} --json $< --pdc ${PC_FILE} --freq ${FREQUENCY} --fasm $@
$(PROJECT).bit: top.fasm
prjoxide pack top.fasm $@
endif
# for Lattice ECP5 devices
ifeq ($(strip $(DEVICE)), ecp5)
top.config: top.json $(PC_FILE)
nextpnr-$(DEVICE) -ql ${PROJECT}-nextpnr.log --${FPGA_TYPE} --package ${FPGA_PACKAGE} --speed ${SPEED} --json $< --textcfg $@ --lpf ${PC_FILE} --freq ${FREQUENCY}
$(PROJECT).bit: top.config
ecppack --bit $@ $<
endif
# for Lattice iCE40 devices
ifeq ($(strip $(DEVICE)), ice40)
top.asc: top.json $(PC_FILE)
nextpnr-$(DEVICE) -ql ${PROJECT}-nextpnr.log --${FPGA_TYPE} --package ${FPGA_PACKAGE} --json top.json --pcf ${PC_FILE} --asc $@ --freq ${FREQUENCY}
$(PROJECT).rpt: top.asc
icetime -d ${FPGA_TYPE} -mtr $@ $<
$(PROJECT).bin: top.asc
icepack top.asc $@
endif
# for Gowin LittleBee devices
ifeq ($(strip $(DEVICE)), gowin)
pnrtop.json: top.json $(PC_FILE)
nextpnr-$(DEVICE) -ql ${PROJECT}-nextpnr.log \
--json top.json \
--write pnrtop.json \
--device ${GOWIN_DEVICE} \
--cst ${PC_FILE}
$(PROJECT).fs: pnrtop.json
gowin_pack -d ${GOWIN_PACK_DEVICE} -o ${PROJECT}.fs pnrtop.json
endif
############################################
# prog #
############################################
# it depends on your development board
# for openFPGALoader:
# board name: https://trabucayre.github.io/openFPGALoader/compatibility/board.html
# cabel name: https://trabucayre.github.io/openFPGALoader/compatibility/cable.html
# fpga: https://trabucayre.github.io/openFPGALoader/compatibility/fpga.html
# for Lattice ECP5 devices
ifeq ($(strip $(DEVICE)), ecp5)
# flash to ram using openocd:
# sudo openocd -f ./cmsisdap.cfg -c "init;scan_chain;exit;" #probe
# sudo openocd -f ./cmsisdap.cfg -c "init;scan_chain;svf -tap ecp5.tap -quiet -progress ${PROJECT}.svf;exit;" # flash to sram
# erase flash:
# ecpdap probes && ecpdap scan && ecpdap flash scan && ecpdap flash unprotect && ecpdap flash erase
prog: all
# program to sram
ecpdap probes && ecpdap scan && ecpdap program --freq 5000 ${PROJECT}.bit
progflash: all
# program to flash
ecpdap probes && ecpdap scan && ecpdap flash scan && ecpdap flash unprotect && ecpdap flash --freq 5000 write ${PROJECT}.bit && ecpdap flash protect
endif
# for Lattice iCE40 devices
# for icesugar, use 'icesprog'
# for jtag, use 'iceprog'
ifeq ($(strip $(DEVICE)), ice40)
prog: all
icesprog ${PROJECT}.bin
endif
# for Gowin LittleBee devices
ifeq ($(strip $(DEVICE)), gowin)
prog: all
openFPGALoader -b tangnano9k ${PROJECT}.fs
endif
############################################
# clean #
############################################
clean:
rm -f top.json pnrtop.json top.asc top.fasm top.config
rm -f ${PROJECT}-yosys.log ${PROJECT}-nextpnr.log
rm -f ${PROJECT}.fs ${PROJECT}.bin ${PROJECT}.bit ${PROJECT}.svf ${PROJECT}.rpt