--- /dev/null
+import os\r
+import subprocess\r
+\r
+from nmigen.build import *\r
+from nmigen.vendor.lattice_ice40 import *\r
+\r
+\r
+__all__ = ["ICEBreakerPlatform"]\r
+\r
+\r
+class ICEBreakerPlatform(LatticeICE40Platform):\r
+ device = "iCE40UP5K"\r
+ package = "SG48"\r
+ resources = [\r
+ Resource("clk12", 0, Pins("35", dir="i"),\r
+ Clock(12e6), Attrs(GLOBAL="1", IO_STANDARD="SB_LVCMOS33")),\r
+\r
+ Resource("user_led_n", 0, Pins("11", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS33")),\r
+ Resource("user_led_n", 1, Pins("37", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS33")),\r
+ # Color-specific aliases\r
+ Resource("user_ledr_n", 0, Pins("11", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS33")),\r
+ Resource("user_ledg_n", 0, Pins("37", dir="o"), Attrs(IO_STANDARD="SB_LVCMOS33")),\r
+ Resource("user_btn_n", 4, Pins("10", dir="i"), Attrs(IO_STANDARD="SB_LVCMOS33")),\r
+\r
+ Resource("serial", 0,\r
+ Subsignal("rx", Pins("6", dir="i")),\r
+ Subsignal("tx", Pins("9", dir="o"), Attrs(PULLUP="1")),\r
+ Attrs(IO_STANDARD="SB_LVTTL")\r
+ ),\r
+\r
+ Resource("spiflash", 0,\r
+ Subsignal("cs_n", Pins("16", dir="o")),\r
+ Subsignal("clk", Pins("15", dir="o")),\r
+ Subsignal("mosi", Pins("14", dir="o")),\r
+ Subsignal("miso", Pins("17", dir="i")),\r
+ Subsignal("wp", Pins("12", dir="o")),\r
+ Subsignal("hold", Pins("13", dir="o")),\r
+ Attrs(IO_STANDARD="SB_LVCMOS33")\r
+ ),\r
+\r
+ Resource("spiflash4x", 0,\r
+ Subsignal("cs_n", Pins("16", dir="o")),\r
+ Subsignal("clk", Pins("15", dir="o")),\r
+ Subsignal("dq", Pins("14 17 12 13", dir="io")),\r
+ Attrs(IO_STANDARD="SB_LVCMOS33")\r
+ ),\r
+ ]\r
+ connectors = [\r
+ Connector("pmod", 0, "4 2 47 45 - - 3 48 46 44 - -"), # PMOD1A\r
+ Connector("pmod", 1, "43 38 34 31 - - 42 36 32 28 - -"), # PMOD1B\r
+ Connector("pmod", 2, "27 25 21 19 - - 26 23 20 18 - -"), # PMOD2\r
+ ]\r
+ # The attached LED/button section can be either used standalone or as a PMOD.\r
+ # Attach to platform using:\r
+ # p.add_resources(p.break_off_pmod)\r
+ # pmod_btn = plat.request("user_btn")\r
+ break_off_pmod = [\r
+ Resource("user_btn", 0, Pins("9", dir="i", conn=("pmod", 2)), Attrs(IO_STANDARD="SB_LVCMOS33")),\r
+ Resource("user_btn", 1, Pins("4", dir="i", conn=("pmod", 2)), Attrs(IO_STANDARD="SB_LVCMOS33")),\r
+ Resource("user_btn", 2, Pins("10", dir="i", conn=("pmod", 2)), Attrs(IO_STANDARD="SB_LVCMOS33")),\r
+\r
+ Resource("user_led", 0, Pins("7", dir="o", conn=("pmod", 2)), Attrs(IO_STANDARD="SB_LVCMOS33")),\r
+ Resource("user_led", 1, Pins("1", dir="o", conn=("pmod", 2)), Attrs(IO_STANDARD="SB_LVCMOS33")),\r
+ Resource("user_led", 2, Pins("2", dir="o", conn=("pmod", 2)), Attrs(IO_STANDARD="SB_LVCMOS33")),\r
+ Resource("user_led", 3, Pins("8", dir="o", conn=("pmod", 2)), Attrs(IO_STANDARD="SB_LVCMOS33")),\r
+ Resource("user_led", 4, Pins("3", dir="o", conn=("pmod", 2)), Attrs(IO_STANDARD="SB_LVCMOS33")),\r
+\r
+ # Color-specific aliases\r
+ Resource("user_ledr", 0, Pins("7", dir="o", conn=("pmod", 2)), Attrs(IO_STANDARD="SB_LVCMOS33")),\r
+ Resource("user_ledg", 0, Pins("1", dir="o", conn=("pmod", 2)), Attrs(IO_STANDARD="SB_LVCMOS33")),\r
+ Resource("user_ledg", 1, Pins("2", dir="o", conn=("pmod", 2)), Attrs(IO_STANDARD="SB_LVCMOS33")),\r
+ Resource("user_ledg", 2, Pins("8", dir="o", conn=("pmod", 2)), Attrs(IO_STANDARD="SB_LVCMOS33")),\r
+ Resource("user_ledg", 3, Pins("3", dir="o", conn=("pmod", 2)), Attrs(IO_STANDARD="SB_LVCMOS33"))\r
+ ]\r
+\r
+ def toolchain_program(self, products, name):\r
+ iceprog = os.environ.get("ICEPROG", "iceprog")\r
+ with products.extract("{}.bin".format(name)) as bitstream_filename:\r
+ subprocess.run([iceprog, bitstream_filename], check=True)\r
+\r
+\r
+if __name__ == "__main__":\r
+ from ._blinky import Blinky\r
+ p = ICEBreakerPlatform()\r
+ p.add_resources(p.break_off_pmod)\r
+ p.build(Blinky("clk12"), do_program=True)\r