ecp5_evn: add SPI Flash, UART, and EXTCLK peripherals
[nmigen-boards.git] / nmigen_boards / icebreaker.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__ = ["ICEBreakerPlatform"]
10
11
12 class ICEBreakerPlatform(LatticeICE40Platform):
13 device = "iCE40UP5K"
14 package = "SG48"
15 default_clk = "clk12"
16 resources = [
17 Resource("clk12", 0, Pins("35", dir="i"),
18 Clock(12e6), Attrs(GLOBAL=True, IO_STANDARD="SB_LVCMOS")),
19
20 *LEDResources(pins="11 37", invert=True, attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
21 # Semantic aliases
22 Resource("led_r", 0, PinsN("11", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
23 Resource("led_g", 0, PinsN("37", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS")),
24
25 *ButtonResources(pins="10", invert=True, attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
26
27 UARTResource(0,
28 rx="6", tx="9",
29 attrs=Attrs(IO_STANDARD="SB_LVTTL", PULLUP=1)
30 ),
31
32 *SPIFlashResources(0,
33 cs="16", clk="15", mosi="14", miso="17", wp="12", hold="13",
34 attrs=Attrs(IO_STANDARD="SB_LVCMOS")
35 ),
36 ]
37 connectors = [
38 Connector("pmod", 0, " 4 2 47 45 - - 3 48 46 44 - -"), # PMOD1A
39 Connector("pmod", 1, "43 38 34 31 - - 42 36 32 28 - -"), # PMOD1B
40 Connector("pmod", 2, "27 25 21 19 - - 26 23 20 18 - -"), # PMOD2
41 ]
42 # The attached LED/button section can be either used standalone or as a PMOD.
43 # Attach to platform using:
44 # p.add_resources(p.break_off_pmod)
45 # pmod_btn = plat.request("user_btn")
46 break_off_pmod = [
47 *LEDResources(pins={2: "7", 3: "1", 4: "2", 5: "8", 6: "3"}, conn=("pmod", 2),
48 attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
49 # Semantic aliases
50 Resource("led_r", 1, Pins("7", dir="o", conn=("pmod", 2)),
51 Attrs(IO_STANDARD="SB_LVCMOS")),
52 Resource("led_g", 1, Pins("1", dir="o", conn=("pmod", 2)),
53 Attrs(IO_STANDARD="SB_LVCMOS")),
54 Resource("led_g", 2, Pins("2", dir="o", conn=("pmod", 2)),
55 Attrs(IO_STANDARD="SB_LVCMOS")),
56 Resource("led_g", 3, Pins("8", dir="o", conn=("pmod", 2)),
57 Attrs(IO_STANDARD="SB_LVCMOS")),
58 Resource("led_g", 4, Pins("3", dir="o", conn=("pmod", 2)),
59 Attrs(IO_STANDARD="SB_LVCMOS")),
60
61 *ButtonResources(pins={1: "9", 2: "4", 3: "10"}, conn=("pmod", 2),
62 attrs=Attrs(IO_STANDARD="SB_LVCMOS")),
63 ]
64
65 def toolchain_program(self, products, name):
66 iceprog = os.environ.get("ICEPROG", "iceprog")
67 with products.extract("{}.bin".format(name)) as bitstream_filename:
68 subprocess.check_call([iceprog, bitstream_filename])
69
70
71 if __name__ == "__main__":
72 from .test.blinky import *
73 p = ICEBreakerPlatform()
74 p.add_resources(p.break_off_pmod)
75 p.build(Blinky(), do_program=True)