e575aacff42f6f561a859574c67c9ee69afe3da7
[nmigen-boards.git] / nmigen_boards / icestick.py
1 import os
2 import subprocess
3
4 from nmigen.build import *
5 from nmigen.vendor.lattice_ice40 import *
6 from .dev import *
7 from .dev.uart import IrDAResource
8
9
10 __all__ = ["ICEStickPlatform"]
11
12
13 class ICEStickPlatform(LatticeICE40Platform):
14 device = "iCE40HX1K"
15 package = "TQ144"
16 resources = [
17 Resource("clk12", 0, Pins("21", dir="i"),
18 Clock(12e6), Attrs(GLOBAL="1", IO_STANDARD="SB_LVCMOS33")),
19
20 Resource("user_led", 0, Pins("99", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS33")),
21 Resource("user_led", 1, Pins("98", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS33")),
22 Resource("user_led", 2, Pins("97", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS33")),
23 Resource("user_led", 3, Pins("96", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS33")),
24 Resource("user_led", 4, Pins("95", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS33")),
25
26 UARTResource(0,
27 rx="9", tx="8", rts="7", cts="4", dtr="3", dsr="2", dcd="1",
28 attrs=Attrs(IO_STANDARD="SB_LVTTL", PULLUP="1")
29 ),
30
31 IrDAResource(0,
32 rx="106", tx="105", sd="107",
33 attrs=Attrs(IO_STANDARD="SB_LVCMOS33")
34 ),
35
36 *SPIFlashResources(0,
37 cs="71", clk="70", mosi="67", miso="68",
38 attrs=Attrs(IO_STANDARD="SB_LVCMOS33")
39 ),
40 ]
41 connectors = [
42 Connector("pmod", 0, "78 79 80 81 - - 87 88 90 91 - -"), # J2
43
44 Connector("j", 1, "- - 112 113 114 115 116 117 118 119"), # J1
45 Connector("j", 3, "- - 62 61 60 56 48 47 45 44"), # J3
46 ]
47
48 def toolchain_program(self, products, name):
49 iceprog = os.environ.get("ICEPROG", "iceprog")
50 with products.extract("{}.bin".format(name)) as bitstream_filename:
51 subprocess.check_call([iceprog, bitstream_filename])
52
53
54 if __name__ == "__main__":
55 from ._blinky import build_and_program
56 build_and_program(ICEStickPlatform, "clk12")