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