9639b14e3e82fd599a64e8c09a51ef99029b5716
[nmigen-boards.git] / nmigen_boards / ecp5_5g_evn.py
1 import os
2 import subprocess
3
4 from nmigen.build import *
5 from nmigen.vendor.lattice_ecp5 import *
6 from .resources import *
7
8
9 __all__ = ["ECP55GEVNPlatform"]
10
11
12 class ECP55GEVNPlatform(LatticeECP5Platform):
13 device = "LFE5UM5G-85F"
14 package = "BG381"
15 speed = "8"
16 default_clk = "clk12"
17 default_rst = "rst"
18
19 def __init__(self, *, VCCIO1="2V5", VCCIO6="3V3", **kwargs):
20 """
21 VCCIO1 is connected by default to 2.5 V via R100 (can be set to 3.3 V by disconnecting
22 R100 and connecting R105)
23 VCCIO6 is connected to 3.3 V by default via R99 (can be switched to 2.5 V with R104,
24 see page 51 in the ECP5-5G-EVN datasheet)
25 """
26 super().__init__(**kwargs)
27 assert VCCIO1 in ("3V3", "2V5")
28 assert VCCIO6 in ("3V3", "2V5")
29 self._VCCIO1 = VCCIO1
30 self._VCCIO6 = VCCIO6
31
32 def _vccio_to_iostandard(self, vccio):
33 if vccio == "2V5":
34 return "LVCMOS25"
35 if vccio == "3V3":
36 return "LVCMOS33"
37 assert False
38
39 def bank1_iostandard(self):
40 return self._vccio_to_iostandard(self._VCCIO1)
41
42 def bank6_iostandard(self):
43 return self._vccio_to_iostandard(self._VCCIO6)
44
45 resources = [
46 Resource("rst", 0, PinsN("G2", dir="i"), Attrs(IO_TYPE="LVCMOS33")),
47 Resource("clk12", 0, Pins("A10", dir="i"),
48 Clock(12e6), Attrs(IO_TYPE="LVCMOS33")),
49
50 *LEDResources(pins="A13 A12 B19 A18 B18 C17 A17 B17", invert=True,
51 attrs=Attrs(IO_TYPE=bank1_iostandard)),
52 *ButtonResources(pins="P4", invert=True,
53 attrs=Attrs(IO_TYPE=bank6_iostandard)),
54 *SwitchResources(pins={1: "J1", 2: "H1", 3: "K1"}, invert=True,
55 attrs=Attrs(IO_TYPE=bank6_iostandard)),
56 *SwitchResources(pins={4: "E15", 5: "D16", 6: "B16", 7: "C16", 8: "A16"}, invert=True,
57 attrs=Attrs(IO_TYPE=bank1_iostandard)),
58
59 Resource("serdes", 0,
60 Subsignal("tx", DiffPairs("W4", "W5", dir="o")),
61 Subsignal("rx", DiffPairs("Y5", "Y6", dir="i")),
62 ),
63 Resource("serdes", 1,
64 Subsignal("tx", DiffPairs("W8", "W9", dir="o")),
65 Subsignal("rx", DiffPairs("Y7", "Y8", dir="i")),
66 ),
67 Resource("serdes", 2,
68 Subsignal("tx", DiffPairs("W13", "W14", dir="o")),
69 Subsignal("rx", DiffPairs("Y14", "Y15", dir="i")),
70 ),
71 Resource("serdes", 3,
72 Subsignal("tx", DiffPairs("W17", "W18", dir="o")),
73 Subsignal("rx", DiffPairs("Y16", "Y17", dir="i")),
74 ),
75
76 Resource("serdes_clk", 0, DiffPairs("Y11", "Y12", dir="i")),
77 Resource("serdes_clk", 1, DiffPairs("Y19", "W20", dir="i")), # 200 MHz
78
79 # TODO: add other resources
80 ]
81 connectors = [
82 # Expansion connectors
83 Connector("J", 39, "- - - D15 B15 C15 B13 B20 D11 E11 B12 C12 D12 E12 C13 D13 E13 A14 A9 B10 - - - - - - - - E7 - A11 - A19 - - - - - - -"),
84 Connector("J", 40, "K2 - A15 F1 H2 G1 J4 J5 J3 K3 L4 L5 M4 N5 N4 P5 N3 M3 - - K5 - M5 - L3 - N2 M1 L2 - L1 N1 C14 - P1 E14 D14 - K4 -"),
85 # Arduino
86 Connector("J", 6, "K16 J16 H17 J17 H18 H16 - G18 G16 F17"),
87 Connector("J", 3, "F19 F20 E20 E19 D19 D20 C20 K17"),
88 Connector("J", 7, "C18 - D17 - - - - -"),
89 Connector("J", 4, "F18 E17 E18 D18 F16 E16"),
90 # Raspberry Pi
91 Connector("JP", 8, "- - T17 - U16 - U17 P18 - N20 N19 T16 M18 - N17 P17 - M17 U20 - T19 N18 R20 U19 - R18 L18 L17 U18 - T18 T20 P20 - R17 P19 N16 P16 - R16"),
92 # GPIO
93 Connector("J", 5, "- - H20 G19 - - K18 J18 - - K19 J19 - - K20 J20 - - G20 - - -"), # Contains 4 differential pairs
94 Connector("J", 8, "- - L19 M19 L20 M20 L16 -"),
95 Connector("J", 32, "- - - - A5 A4 - - C5 B5 - - B4 C4 - - B3 A3 - - D5 E4 - - D3 C3 - - E3 F4 - - F5 E5 - - B1 A2 - -"), # Contains 9 differential pairs
96 Connector("J", 33, "- - - - C2 B2 - - D1 C1 - - E1 D2 - - G5 H4 - - H3 H5 - - F3 G3 - - E2 F2 - -"), # Contains 7 differential pairs
97 # Mic
98 Connector("J", 30, "- B6 D9 C9 E9 D10 A6 E10 - -"),
99 # PMOD
100 Connector("J", 31, "C6 C7 E8 D8 - - C8 B8 A7 A8 - -"),
101 # JTAG
102 Connector("J", 1, "- V4 R5 - - U5 - T5"),
103 # Parallel configuration
104 Connector("J", 38, "W3 R2 T3 Y3 R1 V3 T1 V2 U1 W2 V1 T2 W1 U2 Y2 R2 U3 R3 - -"), # Connect pin 2 / R2 with jumper when needed
105 ]
106
107 @property
108 def file_templates(self):
109 return {
110 **super().file_templates,
111 "{{name}}-openocd.cfg": r"""
112 interface ftdi
113 ftdi_device_desc "Lattice ECP5 Evaluation Board"
114 ftdi_vid_pid 0x0403 0x6010
115 ftdi_channel 0
116 ftdi_layout_init 0xfff8 0xfffb
117 reset_config none
118 adapter_khz 25000
119
120 jtag newtap ecp5 tap -irlen 8 -expected-id 0x81113043
121 """
122 }
123
124 def toolchain_program(self, products, name):
125 openocd = os.environ.get("OPENOCD", "openocd")
126 with products.extract("{}-openocd.cfg".format(name), "{}.svf".format(name)) \
127 as (config_filename, vector_filename):
128 subprocess.check_call([openocd,
129 "-f", config_filename,
130 "-c", "transport select jtag; init; svf -quiet {}; exit".format(vector_filename)
131 ])
132
133
134 if __name__ == "__main__":
135 from .test.blinky import *
136 ECP55GEVNPlatform().build(Blinky(), do_program=True)