Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssertionError when running with a Module using an Instance. #600

cr1901 opened this issue Mar 13, 2021 · 3 comments


Copy link

cr1901 commented Mar 13, 2021

The following code snippet triggers an assertion failure:

from nmigen import *
from nmigen_boards.tinyfpga_ax2 import *

from import *
from nmigen_boards.resources import *

plat = TinyFPGAAX2Platform()
plat.add_resources([Resource("led", 0, Pins("gpio_0:1"))])

class Test(Elaboratable):
    def __init__(self):

    def elaborate(self, plat):
        m = Module()
        led = plat.request("led")

        m.submodules += [
            Instance("top", o_o=led)

        return m

plan =, name="actual_top", do_build=False)
$ python
Traceback (most recent call last):
  File "", line 25, in <module>
    plan =, name="actual_top", do_build=False)
  File "C:/msys64/home/william/projects/fpga/nmigen/nmigen/nmigen/build/", line 95, in build
    plan = self.prepare(elaboratable, name, **kwargs)
  File "C:/msys64/home/william/projects/fpga/nmigen/nmigen/nmigen/build/", line 166, in prepare
    fragment._propagate_ports(ports=self.iter_ports(), all_undef_as_ports=False)
  File "C:/msys64/home/william/projects/fpga/nmigen/nmigen/nmigen/hdl/", line 462, in _propagate_ports
    self._prepare_use_def_graph(parent, level, uses, defs, ios, self)
  File "C:/msys64/home/william/projects/fpga/nmigen/nmigen/nmigen/hdl/", line 436, in _prepare_use_def_graph
    subfrag._prepare_use_def_graph(parent, level, uses, defs, ios, top)
  File "C:/msys64/home/william/projects/fpga/nmigen/nmigen/nmigen/hdl/", line 428, in _prepare_use_def_graph
  File "C:/msys64/home/william/projects/fpga/nmigen/nmigen/nmigen/hdl/", line 396, in add_defs
    assert defs[sig] is self

The error is that the Pins direction (an inout?) of the led Resource does not match what Instance expects (an output). I'm not sure why this AssertionError is triggered. Is there a good place to raise a "driver conflict in Instance" error before this assertion triggers?

Fix to stop the AssertionError:

plat.add_resources([Resource("led", 0, Pins("gpio_0:1", dir="o"))])
Copy link

awygle commented Mar 13, 2021

I believe this would be addressed by #596

Copy link

The error is that the Pins direction (an inout?)

That's not an inout. You're requesting a triple, implicitly. Use dir="o" when defining the LED resource, or better, LEDResources.

Copy link
Contributor Author

cr1901 commented Mar 14, 2021

#596 will close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

No branches or pull requests

3 participants