Created
April 9, 2026 11:39
-
-
Save jeanthom/64c2e7b57dc761bc9cbb62dcafd5b201 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from amaranth import * | |
| from amaranth.hdl import IOPort | |
| from amaranth.build import * | |
| from amaranth.vendor import GowinPlatform | |
| from amaranth_boards.resources import * | |
| # Issue without iter_port_constraints_bits patch | |
| # | |
| # Traceback (most recent call last): | |
| # File "/Users/jeanthomas/Documents/Notes/ioport-reproducer/main.py", line 36, in <module> | |
| # platform.build(top, do_program=False) | |
| # ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^ | |
| # File "/Users/jeanthomas/Documents/Notes/ioport-reproducer/.venv/lib/python3.14/site-packages/amaranth/build/plat.py", line 116, in build | |
| # plan = self.prepare(elaboratable, name, **kwargs) | |
| # File "/Users/jeanthomas/Documents/Notes/ioport-reproducer/.venv/lib/python3.14/site-packages/amaranth/build/plat.py", line 176, in prepare | |
| # return self.toolchain_prepare(self._design, name, **kwargs) | |
| # ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| # File "/Users/jeanthomas/Documents/Notes/ioport-reproducer/.venv/lib/python3.14/site-packages/amaranth/build/plat.py", line 435, in toolchain_prepare | |
| # render(content_tpl, origin=content_tpl)) | |
| # ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| # File "/Users/jeanthomas/Documents/Notes/ioport-reproducer/.venv/lib/python3.14/site-packages/amaranth/build/plat.py", line 416, in render | |
| # return compiled.render({ | |
| # ~~~~~~~~~~~~~~~^^ | |
| # "name": name, | |
| # ^^^^^^^^^^^^^ | |
| # ...<11 lines>... | |
| # "autogenerated": autogenerated, | |
| # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| # }) | |
| # ^^ | |
| # File "/Users/jeanthomas/Documents/Notes/ioport-reproducer/.venv/lib/python3.14/site-packages/jinja2/environment.py", line 1295, in render | |
| # self.environment.handle_exception() | |
| # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^ | |
| # File "/Users/jeanthomas/Documents/Notes/ioport-reproducer/.venv/lib/python3.14/site-packages/jinja2/environment.py", line 942, in handle_exception | |
| # raise rewrite_traceback_stack(source=source) | |
| # File "<template>", line 2, in top-level template code | |
| # File "/Users/jeanthomas/Documents/Notes/ioport-reproducer/.venv/lib/python3.14/site-packages/amaranth/build/plat.py", line 181, in iter_port_constraints_bits | |
| # yield name, port.metadata[0].name, port.metadata[0].attrs | |
| # ^^^^^^^^^^^^^^^^^^^^^ | |
| # AttributeError: 'NoneType' object has no attribute 'name' | |
| class TangMega138kProDockPlatform(GowinPlatform): | |
| part = "GW5AST-LV138FPG676AC1/I0" | |
| family = "GW5AST-138B" | |
| device = None | |
| default_clk = "clk50" | |
| resources = [ | |
| Resource("clk50", 0, Pins("P16", dir="i"), | |
| Clock(50e6), Attrs(IO_TYPE="LVCMOS33")), | |
| ] | |
| connectors = [] | |
| def iter_port_constraints_bits(self): | |
| for name, port, _dir in self._design.ports: | |
| if len(port) == 1: | |
| if port.metadata[0] is None: | |
| continue | |
| yield name, port.metadata[0].name, port.metadata[0].attrs | |
| else: | |
| for bit, meta in enumerate(port.metadata): | |
| if meta is None: | |
| continue | |
| yield f"{name}[{bit}]", meta.name, meta.attrs | |
| class Top(Elaboratable): | |
| def elaborate(self, platform): | |
| m = Module() | |
| my_port = IOPort(1, name="my_port") | |
| m.submodules.blackbox = Instance("blackbox", | |
| io_port=my_port) | |
| return m | |
| if __name__ == '__main__': | |
| top = Top() | |
| platform = TangMega138kProDockPlatform(toolchain='Gowin') | |
| platform.build(top, do_program=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment