ecp5_evn: add SPI Flash, UART, and EXTCLK peripherals
[nmigen-boards.git] / nmigen_boards / blackice.py
1 import os
2 import subprocess
3
4 from nmigen.build import *
5 from nmigen.vendor.lattice_ice40 import *
6 from .resources import *
7
8
9 __all__ = ["BlackIcePlatform"]
10
11
12 class BlackIcePlatform(LatticeICE40Platform):
13 device = "iCE40HX4K"
14 package = "TQ144"
15 default_clk = "clk100"
16 resources = [
17 Resource("clk100", 0, Pins("129", dir="i"),
18 Clock(100e6), Attrs(GLOBAL=True, IO_STANDARD="SB_LVCMOS")),
19
20 *LEDResources(pins="71 67 68 70", attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
21 # Semantic aliases
22 Resource("led_b", 0, Pins("71", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
23 Resource("led_g", 0, Pins("67", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
24 Resource("led_o", 0, Pins("68", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
25 Resource("led_r", 0, Pins("70", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
26
27 *ButtonResources(pins="63 64", invert=True, attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
28 *SwitchResources(pins="37 38 39 41", invert=True, attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
29
30 UARTResource(0,
31 rx="88", tx="85",
32 attrs=Attrs(IO_STANDARD="SB_LVCMOS", PULLUP=1),
33 role="dce"
34 ),
35
36 SRAMResource(0,
37 cs="136", oe="45", we="120",
38 a="137 138 139 141 142 42 43 44 73 74 75 76 115 116 117 118 119 78",
39 d="135 134 130 128 125 124 122 121 61 60 56 55 52 49 48 47",
40 attrs=Attrs(IO_STANDARD="SB_LVCMOS"),
41 ),
42 ]
43 connectors = [
44 Connector("pmod", 0, " 94 91 88 85 - - 95 93 90 87 - -"), # PMOD1/2
45 Connector("pmod", 1, "105 102 99 97 - - 104 101 98 96 - -"), # PMOD3/4
46 Connector("pmod", 2, "143 114 112 107 - - 144 113 110 106 - -"), # PMOD5/6
47 Connector("pmod", 3, " 10 9 2 1 - - 8 7 4 3 - -"), # PMOD7/8
48 Connector("pmod", 4, " 20 19 16 15 - - 18 17 12 11 - -"), # PMOD9/10
49 Connector("pmod", 5, " 34 33 22 21 - - 32 31 26 25 - -"), # PMOD11/12
50 Connector("pmod", 6, " 29 28 24 23 - -"), # PMOD13
51 Connector("pmod", 7, " 71 67 68 70 - -"), # PMOD14
52 ]
53
54 def toolchain_program(self, products, name):
55 with products.extract("{}.bin".format(name)) as bitstream_filename:
56 subprocess.check_call(["cp", bitstream_filename, "/dev/ttyACM0"])
57
58
59 if __name__ == "__main__":
60 from .test.blinky import *
61 BlackIcePlatform().build(Blinky(), do_program=True)