[Libre-soc-bugs] [Bug 50] nmigen pinmux

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Fri Nov 12 18:18:06 GMT 2021


https://bugs.libre-soc.org/show_bug.cgi?id=50

--- Comment #7 from Luke Kenneth Casson Leighton <lkcl at lkcl.net> ---
i have cut it back somewhat, but this is how to create a platform.
Blinker is dome sort of top-level system (module) that, internally,
will have done this:

For example, by including this Resource into the platform's resources list:

    Resource("abc", 0, Pins("J3", dir="i"))

then pin J3 on the device will be configured as an input, and you can request
the abc resource's input Signal like this:

    platform.request("abc").i

(and then assign to it)



from nmigen.build import Platform, Resource, Pins, Clock, Attrs, Connector
from nmigen.build.run import LocalBuildProducts
from nmigen.cli import main_parser, main_runner
from nmigen.vendor.lattice_ice40 import LatticeICE40Platform

class ICE40HX8KBEVNPlatform(LatticeICE40Platform):
    device = "iCE40HX8K"
    package = "CT256"

    resources = [
        Resource("clk1", 0, Pins("J3", dir="i"), Clock(12e6),
                 Attrs(GLOBAL=True, IO_STANDARD="SB_LVCMOS")),  # GBIN6
        Resource("rst", 0, Pins("R9", dir="i"),
                 Attrs(GLOBAL=True, IO_STANDARD="SB_LVCMOS")),  # GBIN5
        Resource("led", 0, Pins("C3", dir="o"),
                 Attrs(IO_STANDARD="SB_LVCMOS")),  # LED2
    ]

    default_clk = "clk1"  # you must have a default clock resource
    default_rst = "rst"   # you must have a default reset resource

    def toolchain_program(self, products: LocalBuildProducts, name: str):
        iceprog = os.environ.get("ICEPROG", "iceprog")
        with products.extract("{}.bin".format(name)) as bitstream_filename:
            subprocess.check_call([iceprog, "-S", bitstream_filename])

if __name__ == "__main__":
    ICE40HX8KBEVNPlatform().build(Blinker(), do_program=True)


so, basically, we do not just create a module and blat its output to a file,
we create an *ASICPlatform*, hand the module to that platform, and ask the
platform to "build" the pinconnections, which will include setting up JTAG
Boundary connectivity.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the libre-soc-bugs mailing list