ecp5_evn: add SPI Flash, UART, and EXTCLK peripherals
[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 # By default this CLK is not populated, see User Manual Section 4.
51 Resource("extclk", 0, Pins("B11", dir="i"),
52 Attrs(IO_TYPE="LVCMOS33")),
53
54 *LEDResources(pins="A13 A12 B19 A18 B18 C17 A17 B17", invert=True,
55 attrs=Attrs(IO_TYPE=bank1_iostandard)),
56 *ButtonResources(pins="P4", invert=True,
57 attrs=Attrs(IO_TYPE=bank6_iostandard)),
58 *SwitchResources(pins={1: "J1", 2: "H1", 3: "K1"}, invert=True,
59 attrs=Attrs(IO_TYPE=bank6_iostandard)),
60 *SwitchResources(pins={4: "E15", 5: "D16", 6: "B16", 7: "C16", 8: "A16"}, invert=True,
61 attrs=Attrs(IO_TYPE=bank1_iostandard)),
62
63 # In order to use the UART as a UART you need to swap two resistor jumpers,
64 # and potentially reconfigure the onboard FTDI chip, see section 6.2 in the
65 # User Manual for hardware instructions, and
66 # https://github.com/trabucayre/fixFT2232_ecp5evn to reconfigure the FTDI.
67 UARTResource(0,
68 rx="P2", tx="P3",
69 attrs=Attrs(IO_TYPE=bank6_iostandard, PULLMODE="UP")
70 ),
71
72 *SPIFlashResources(0,
73 cs="R2", clk="U3", miso="V2", mosi="W2", wp="Y2", hold="W1",
74 attrs=Attrs(IO_STANDARD="LVCMOS33")
75 ),
76
77 Resource("serdes", 0,
78 Subsignal("tx", DiffPairs("W4", "W5", dir="o")),
79 Subsignal("rx", DiffPairs("Y5", "Y6", dir="i")),
80 ),
81 Resource("serdes", 1,
82 Subsignal("tx", DiffPairs("W8", "W9", dir="o")),
83 Subsignal("rx", DiffPairs("Y7", "Y8", dir="i")),
84 ),
85 Resource("serdes", 2,
86 Subsignal("tx", DiffPairs("W13", "W14", dir="o")),
87 Subsignal("rx", DiffPairs("Y14", "Y15", dir="i")),
88 ),
89 Resource("serdes", 3,
90 Subsignal("tx", DiffPairs("W17", "W18", dir="o")),
91 Subsignal("rx", DiffPairs("Y16", "Y17", dir="i")),
92 ),
93
94 Resource("serdes_clk", 0, DiffPairs("Y11", "Y12", dir="i")),
95 Resource("serdes_clk", 1, DiffPairs("Y19", "W20", dir="i")), # 200 MHz
96
97 # TODO: add other resources
98 ]
99 connectors = [
100 # Expansion connectors
101 Connector("J", 39, "- - - D15 B15 C15 B13 B20 D11 E11 B12 C12 D12 E12 C13 D13 E13 A14 A9 B10 - - - - - - - - E7 - A11 - A19 - - - - - - -"),
102 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 -"),
103 # Arduino
104 Connector("J", 6, "K16 J16 H17 J17 H18 H16 - G18 G16 F17"),
105 Connector("J", 3, "F19 F20 E20 E19 D19 D20 C20 K17"),
106 Connector("J", 7, "C18 - D17 - - - - -"),
107 Connector("J", 4, "F18 E17 E18 D18 F16 E16"),
108 # Raspberry Pi
109 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"),
110 # GPIO
111 Connector("J", 5, "- - H20 G19 - - K18 J18 - - K19 J19 - - K20 J20 - - G20 - - -"), # Contains 4 differential pairs
112 Connector("J", 8, "- - L19 M19 L20 M20 L16 -"),
113 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
114 Connector("J", 33, "- - - - C2 B2 - - D1 C1 - - E1 D2 - - G5 H4 - - H3 H5 - - F3 G3 - - E2 F2 - -"), # Contains 7 differential pairs
115 # Mic
116 Connector("J", 30, "- B6 D9 C9 E9 D10 A6 E10 - -"),
117 # PMOD
118 Connector("J", 31, "C6 C7 E8 D8 - - C8 B8 A7 A8 - -"),
119 # JTAG
120 Connector("J", 1, "- V4 R5 - - U5 - T5"),
121 # Parallel configuration
122 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
123 ]
124
125 @property
126 def file_templates(self):
127 return {
128 **super().file_templates,
129 "{{name}}-openocd.cfg": r"""
130 interface ftdi
131 ftdi_device_desc "Lattice ECP5 Evaluation Board"
132 ftdi_vid_pid 0x0403 0x6010
133 ftdi_channel 0
134 ftdi_layout_init 0xfff8 0xfffb
135 reset_config none
136 adapter_khz 25000
137
138 jtag newtap ecp5 tap -irlen 8 -expected-id 0x81113043
139 """
140 }
141
142 def toolchain_program(self, products, name):
143 openocd = os.environ.get("OPENOCD", "openocd")
144 with products.extract("{}-openocd.cfg".format(name), "{}.svf".format(name)) \
145 as (config_filename, vector_filename):
146 subprocess.check_call([openocd,
147 "-f", config_filename,
148 "-c", "transport select jtag; init; svf -quiet {}; exit".format(vector_filename)
149 ])
150
151
152 if __name__ == "__main__":
153 from .test.blinky import *
154 ECP55GEVNPlatform().build(Blinky(), do_program=True)