amaranth-lang / amaranth

A modern hardware definition language and toolchain based on Python
https://amaranth-lang.org/docs/amaranth/
BSD 2-Clause "Simplified" License
1.57k stars 174 forks source link

Wrong number of pins reported when the direction is "io" #397

Closed jeanthom closed 4 years ago

jeanthom commented 4 years ago

Hi,

I just came across a bug that causes nMigen to report the wrong number of pins when the direction of the pins is set to bidirectional.

Test code:

from nmigen import *
from nmigen_boards.arty_a7 import ArtyA7Platform

platform = ArtyA7Platform()
ram = platform.request("ddr3", 0)

print("Number of DQ signals:", len(ram.dq)) # DQ is "io"
print("Number of A signals:", len(ram.a)) # A is output only

Result:

Number of DQ signals: 33
Number of A signals: 14

What I was expecting:

Number of DQ signals: 16
Number of A signals: 14
whitequark commented 4 years ago

You should never use attributes of the object returned by platform.request directly. Instead, use ram.x.i for inputs or inouts, ram.x.o for outputs or inouts, and ram.x.oe for inouts.

jeanthom commented 4 years ago

Ok, I will use .i/.o/.oe instead.

whitequark commented 4 years ago

FWIW, this is a footgun I'm aware of and I have plans to fix it.