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 Platform.build with a Module using an Instance. #600

Closed
cr1901 opened this issue Mar 13, 2021 · 3 comments · Fixed by #1104
Closed

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

cr1901 opened this issue Mar 13, 2021 · 3 comments · Fixed by #1104
Labels

Comments

@cr1901
Copy link
Contributor

cr1901 commented Mar 13, 2021

The following code snippet triggers an assertion failure:

from nmigen import *
from nmigen_boards.tinyfpga_ax2 import *

from nmigen.build import *
from nmigen_boards.resources import *


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

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

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

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

        return m

plan = plat.build(Test(), name="actual_top", do_build=False)
$ python mk_build.py
Traceback (most recent call last):
  File "mk_build.py", line 25, in <module>
    plan = plat.build(Test(), name="actual_top", do_build=False)
  File "C:/msys64/home/william/projects/fpga/nmigen/nmigen/nmigen/build/plat.py", line 95, in build
    plan = self.prepare(elaboratable, name, **kwargs)
  File "C:/msys64/home/william/projects/fpga/nmigen/nmigen/nmigen/build/plat.py", 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/ir.py", 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/ir.py", 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/ir.py", line 428, in _prepare_use_def_graph
    add_defs(value._lhs_signals())
  File "C:/msys64/home/william/projects/fpga/nmigen/nmigen/nmigen/hdl/ir.py", line 396, in add_defs
    assert defs[sig] is self
AssertionError

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"))])
@awygle
Copy link
Contributor

awygle commented Mar 13, 2021

I believe this would be addressed by #596

@whitequark
Copy link
Member

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.

@cr1901
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
Labels
Development

Successfully merging a pull request may close this issue.

3 participants