Skip to content

Commit 7e24efe

Browse files
agrifwhitequark
authored andcommitted
add support for Tang Primer 20k
1 parent c26a72e commit 7e24efe

File tree

1 file changed

+269
-0
lines changed

1 file changed

+269
-0
lines changed

amaranth_boards/tang_primer_20k.py

Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
import os
2+
import subprocess
3+
4+
from amaranth.build import *
5+
from amaranth.vendor import GowinPlatform
6+
7+
from .resources import *
8+
9+
10+
__all__ = [
11+
"TangPrimer20kPlatform",
12+
"TangPrimer20kLitePlatform",
13+
"TangPrimer20kDockPlatform",
14+
]
15+
16+
17+
class TangPrimer20kPlatform(GowinPlatform):
18+
part = "GW2A-LV18PG256C8/I7"
19+
family = "GW2A-18C"
20+
default_clk = "clk27"
21+
resources = [
22+
Resource("clk27", 0, Pins("H11", dir="i"),
23+
Clock(27e6), Attrs(IO_TYPE="LVCMOS33")),
24+
25+
UARTResource(0, rx="T13", tx="M11",
26+
attrs=Attrs(PULL_MODE="UP", IO_TYPE="LVCMOS33")),
27+
28+
*SPIFlashResources(0, cs_n="M9", clk="L10", cipo="P10", copi="R10",
29+
attrs=Attrs(IO_TYPE="LVCMOS33")),
30+
31+
*SDCardResources(0, clk="N10", cmd="R14", cd="D15",
32+
dat0="M8", dat1="M7", dat2="M10", dat3="N11",
33+
attrs=Attrs(IO_TYPE="LVCMOS33")),
34+
35+
DDR3Resource(0, rst_n="B9", clk_p="J1", clk_n="J3", clk_en="J2",
36+
cs_n="P5", we_n="L2", ras_n="R4", cas_n="R6",
37+
a="F7 A4 D6 F8 C4 E6 B1 D8 A5 F9 K3 B7 A3 C8",
38+
ba="H4 D3 H5", dqs_p="G2 J5", dqs_n="G3 K6",
39+
dq="G5 F5 F4 F3 E2 C1 E1 B3 M3 K4 N2 L1 P4 H3 R1 M2",
40+
dm="G1 K5", odt="R3",
41+
attrs=Attrs(IO_TYPE="SSTL15"),
42+
diff_attrs=Attrs(IO_TYPE="SSTL15D")),
43+
44+
# ZIF connector on core board
45+
Resource("spi_lcd", 0,
46+
Subsignal("bl", PinsN("P12", dir="o")),
47+
Subsignal("rst", PinsN("G13", dir="o")),
48+
Subsignal("rs", Pins("J13", dir="o")),
49+
Subsignal("cs", PinsN("C16", dir="o")),
50+
Subsignal("clk", Pins("F12", dir="o")),
51+
Subsignal("copi", Pins("L15", dir="o")),
52+
Attrs(IO_TYPE="LVCMOS33")),
53+
]
54+
55+
connectors = [
56+
# GND, 5V, 3V3 are power pins
57+
# V01 and V7 are IO bank voltages, tied to 3V3 by R5 and R9 (resp.)
58+
Connector("sodimm", 0,
59+
# GND GND 5V 5V 5V 5V GND GND NC ( 1- 10)
60+
" T13 - - - - - - - - - "
61+
# NC GND GND NC NC NC GND GND ( 11- 20)
62+
" M11 - - - T10 - - - - - "
63+
# NC 3V3 NC 3V3 GND GND ( 21- 30)
64+
" - - - - - - T6 R16 P6 P16"
65+
# GND GND GND GND ( 31- 40)
66+
" - - T7 P16 R8 N15 - - T8 N16"
67+
# GND GND GND ( 41- 50)
68+
" P8 N14 - L16 T9 L14 P9 - - K15"
69+
# GND GND GND ( 51- 60)
70+
" P11 K14 T11 - - K16 R11 J15 T12 - "
71+
# GND GND ( 61- 70)
72+
" - H16 R12 H14 P13 - R13 G16 T14 H15"
73+
# GND GND ( 71- 80)
74+
" - - M15 L13 M14 K11 F13 K12 G12 K13"
75+
# NC NC NC ( 81- 90)
76+
" T15 - J16 H13 J14 J12 - - G14 H12"
77+
# NC NC NC NC ( 91-100)
78+
" G15 G11 - - F14 B10 F16 A13 - - "
79+
# NC NC NC NC NC NC (101-110)
80+
"E15 - D14 - - - A15 - B14 - "
81+
# NC NC NC NC NC NC NC (111-120)
82+
" - - A14 - B13 - - - C12 - "
83+
# NC NC NC GND GND (121-130)
84+
" B12 - A12 - C11 - - - B11 E16"
85+
# GND GND NC GND GND (131-140)
86+
" A11 F15 - - C10 C13 - - - D16"
87+
# NC GND GND GND (141-150)
88+
" - E14 B8 - - C9 C6 A9 A7 - "
89+
# GND GND GND (151-160)
90+
" - L12 A6 J11 - - C7 E9 D7 E8 "
91+
# GND GND V01 V01 GND GND V7 (161-170)
92+
" - - T2 - T3 - - - T4 - "
93+
# GND GND V7 GND GND (171-180)
94+
" T5 - - - N6 F10 N7 - - D11"
95+
# GND GND NC NC GND GND (181-190)
96+
" N9 D10 R9 - - E10 - - - - "
97+
# GND GND NC NC (191-200)
98+
" N8 R7 L9 P7 - - - M6 - L8 "
99+
# NC NC NC NC (201-204)
100+
" - - - - "
101+
)
102+
]
103+
104+
def toolchain_prepare(self, fragment, name, **kwargs):
105+
overrides = {
106+
"add_options":
107+
"set_option -use_mspi_as_gpio 1 -use_sspi_as_gpio 1"
108+
" -use_ready_as_gpio 1 -use_done_as_gpio 1",
109+
"gowin_pack_opts":
110+
"--mspi_as_gpio --sspi_as_gpio --ready_as_gpio --done_as_gpio",
111+
}
112+
return super().toolchain_prepare(fragment, name, **overrides, **kwargs)
113+
114+
def toolchain_program(self, products, name):
115+
with products.extract("{}.fs".format(name)) as bitstream_filename:
116+
subprocess.check_call(
117+
["openFPGALoader", "-b", "tangprimer20k", bitstream_filename])
118+
119+
120+
class TangPrimer20kLitePlatform(TangPrimer20kPlatform):
121+
resources = TangPrimer20kPlatform.resources + [
122+
*ButtonResources(pins={0: "T10"}, invert=True,
123+
attrs=Attrs(IO_TYPE="LVCMOS33")),
124+
*ButtonResources(pins={1: "T2"}, invert=True,
125+
attrs=Attrs(IO_TYPE="LVCMOS15")),
126+
127+
*SwitchResources(pins="D7 C7",
128+
attrs=Attrs(PULL_MODE="NONE", IO_TYPE="LVCMOS15")),
129+
]
130+
131+
connectors = TangPrimer20kPlatform.connectors + [
132+
# top left, top right, bottom left, bottom right
133+
Connector("pmod", 0, "L8 P7 E10 D11 - - M6 R7 D10 F10 - -"),
134+
Connector("pmod", 1, "T6 T7 T8 T9 - - P6 R8 P8 P9 - -"),
135+
Connector("pmod", 2, "F15 D16 C9 L12 - - E16 E14 A9 J11 - -"),
136+
Connector("pmod", 3, "R16 P16 N16 L16 - - P15 N15 N14 L14 - -"),
137+
138+
# 0 on top, 1 on bottom, odd/even rows
139+
Connector("gpio", 0,
140+
" - - N6 N7 B11 A12 L9 N8 R9 N9 " # ( 1-10)
141+
"A6 A7 C6 B8 C10 - A11 C11 B12 C12" # (11-20)
142+
"B13 A14 B14 A15 D14 E15 F16 F14 G15 G14" # (21-30)
143+
"J14 J16 G12 F13 M14 M15 T14 R13 P13 R12" # (31-40)
144+
),
145+
Connector("gpio", 1,
146+
" - - - - - - T5 - T3 T4 " # ( 1-10)
147+
" - - E9 E8 T15 C13 T13 M11 B10 A13" # (11-20)
148+
"H12 G11 H13 J12 K12 K13 L13 K11 R11 T12" # (21-30)
149+
"P11 T11 G16 H15 H16 H14 K16 J15 K15 K14" # (31-40)
150+
),
151+
]
152+
153+
154+
class TangPrimer20kDockPlatform(TangPrimer20kPlatform):
155+
resources = TangPrimer20kPlatform.resources + [
156+
*LEDResources(pins="C13 A13 N16 N14 L14 L16", invert=True,
157+
attrs=Attrs(IO_TYPE="LVCMOS33")),
158+
159+
# WS2812 RGB LED
160+
Resource("ws2812", 0, Pins("T9", dir="o"),
161+
Attrs(IO_TYPE="LVCMOS33")),
162+
163+
*ButtonResources(pins={0: "T10"}, invert=True,
164+
attrs=Attrs(IO_TYPE="LVCMOS33")),
165+
*ButtonResources(pins={1: "T3", 2: "T2", 3: "D7", 4: "C7"}, invert=True,
166+
attrs=Attrs(IO_TYPE="LVCMOS15")),
167+
168+
*SwitchResources(pins={0: "B10"},
169+
attrs=Attrs(PULL_MODE="DOWN", IO_TYPE="LVCMOS33")),
170+
*SwitchResources(pins={1: "E9", 2: "E8", 3: "T4", 4: "T5"},
171+
attrs=Attrs(PULL_MODE="DOWN", IO_TYPE="LVCMOS15")),
172+
173+
Resource("eth_clk50", 0, Pins("A9", dir="i"),
174+
Clock(50e6), Attrs(IO_TYPE="LVCMOS33")),
175+
Resource("eth_rmii", 0,
176+
Subsignal("rst", PinsN("F10", dir="o")),
177+
Subsignal("mdio", Pins("F16", dir="io")),
178+
Subsignal("mdc", Pins("F14", dir="o")),
179+
Subsignal("tx_en", Pins("E16", dir="o")),
180+
Subsignal("tx_data", Pins("D16 E14", dir="o")),
181+
Subsignal("rx_crs", Pins("M6", dir="i")),
182+
Subsignal("rx_er", Pins("L8" , dir="i")),
183+
Subsignal("rx_data", Pins("F15 C9", dir="i")),
184+
Attrs(IO_TYPE="LVCMOS33")),
185+
186+
ULPIResource(0, data="G11 H12 J12 H13 T14 R13 P13 R12",
187+
clk="T15", dir="K12", nxt="K13", stp="K11",
188+
rst="F10", rst_invert=True,
189+
attrs=Attrs(PULL_MODE="NONE", IO_TYPE="LVCMOS33")),
190+
191+
Resource("hdmi", 0,
192+
Subsignal("clk", DiffPairs(p="G16", n="H15", dir="o")),
193+
Subsignal("d", DiffPairs(p="H14 J15 K14", n="H16 K16 K15", dir="o")),
194+
Subsignal("hdp", Pins("J11", dir="i"),
195+
Attrs(IO_TYPE="LVCMOS33")),
196+
Subsignal("cec", Pins("L12", dir="io"),
197+
Attrs(IO_TYPE="LVCMOS33")),
198+
Subsignal("sda", Pins("F14", dir="io"),
199+
Attrs(IO_TYPE="LVCMOS33")),
200+
Subsignal("scl", Pins("F16", dir="io"),
201+
Attrs(IO_TYPE="LVCMOS33")),
202+
Attrs(PULL_MODE="NONE")),
203+
204+
# labeled DISPLAY or RGB LCD
205+
Resource("lcd", 0,
206+
Subsignal("bl", Pins("E10", dir="o")),
207+
Subsignal("clk", Pins("R9", dir="o")),
208+
Subsignal("de", Pins("E15", dir="o")),
209+
Subsignal("hs", PinsN("A15", dir="o")),
210+
Subsignal("vs", PinsN("D14", dir="o")),
211+
Subsignal("r", Pins("L9 N8 N9 N7 N6", dir="o")),
212+
Subsignal("g", Pins("D11 A11 B11 P7 R7 D10", dir="o")),
213+
Subsignal("b", Pins("B12 C12 B13 A14 B14", dir="o")),
214+
Attrs(IO_TYPE="LVCMOS33")),
215+
216+
# labeled CAM or DVP
217+
Resource("dvp", 0,
218+
Subsignal("d",
219+
Pins("T12 T11 P11 R11 M15 M14 J16 J14", dir="i")),
220+
Subsignal("scl", Pins("F14", dir="io")),
221+
Subsignal("sda", Pins("F16", dir="io")),
222+
Subsignal("pclk", Pins("F13", dir="i")),
223+
Subsignal("xclk", Pins("G12", dir="o")),
224+
Subsignal("rst", PinsN("L13", dir="o")),
225+
Subsignal("vs", Pins("G15", dir="i")),
226+
Subsignal("pwdn", Pins("C10", dir="o")),
227+
Subsignal("hs", Pins("G14", dir="i")),
228+
Attrs(IO_TYPE="LVCMOS33")),
229+
230+
# labeled TP or CTP
231+
Resource("lcd_touch", 0,
232+
Subsignal("sda", Pins("F14", dir="io")),
233+
Subsignal("scl", Pins("F16", dir="io")),
234+
Subsignal("int", Pins("C11", dir="i")),
235+
Subsignal("rst", PinsN("A12", dir="o")),
236+
Attrs(IO_TYPE="LVCMOS33")),
237+
238+
# labeled GPIO or MIC ARRAY
239+
Resource("mic_i2s", 0,
240+
Subsignal("sd", Pins("P8 T8 R8 T7", dir="i")),
241+
Subsignal("ws", Pins("P6", dir="i")),
242+
Subsignal("clk", Pins("T6", dir="i")),
243+
Attrs(IO_TYPE="LVCMOS33")),
244+
Resource("mic_led", 0,
245+
Subsignal("clk", Pins("P9", dir="o")),
246+
Subsignal("dat", Pins("T9", dir="o")),
247+
Attrs(IO_TYPE="LVCMOS33")),
248+
249+
# 3.5mm audio via PT8211
250+
Resource("dac_i2s", 0,
251+
Subsignal("sd", Pins("P15", dir="o")),
252+
Subsignal("ws", Pins("P16", dir="o")),
253+
Subsignal("clk", Pins("N15", dir="o")),
254+
Subsignal("pa_en", Pins("R16", dir="o")),
255+
Attrs(PULL_MODE="UP", IO_TYPE="LVCMOS33"))
256+
]
257+
258+
connectors = TangPrimer20kPlatform.connectors + [
259+
# top left to top right
260+
Connector("pmod", 0, "B11 D11 N7 N8 - - A11 N6 N9 L9 - -"),
261+
Connector("pmod", 1, "E15 A15 A14 C12 - - D14 B14 B13 B12 - -"),
262+
Connector("pmod", 2, "P11 R11 M15 J16 - - T11 T12 M14 J14 - -"),
263+
Connector("pmod", 3, "P6 T7 P8 T9 - - T6 R8 T8 P9 - -"),
264+
]
265+
266+
267+
if __name__ == "__main__":
268+
from .test.blinky import *
269+
TangPrimer20kDockPlatform().build(Blinky(), do_program=True)

0 commit comments

Comments
 (0)