From cd8666d0b39a26774946572427bb2053d6805026 Mon Sep 17 00:00:00 2001 From: Dan Callaghan Date: Mon, 9 Aug 2021 19:26:40 +1000 Subject: [PATCH] build/lattice: work around lack of SDR I/O primitives in nextpnr Fixes #907. --- litex/build/lattice/common.py | 31 +++++++++++++++++++++++++++++++ litex/build/lattice/oxide.py | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/litex/build/lattice/common.py b/litex/build/lattice/common.py index b243a9796..842872e78 100644 --- a/litex/build/lattice/common.py +++ b/litex/build/lattice/common.py @@ -241,6 +241,31 @@ class LatticeNXSDROutput: def lower(dr): return LatticeNXSDROutputImpl(dr.i, dr.o, dr.clk) +# NX SDR Input and Output via regular flip-flops --------------------------------------------------- + +# This is a workaround for IO-specific primitives IFD1P3BX / OFD1P3BX being unsupported in nextpnr: +# https://github.com/YosysHQ/nextpnr/issues/698 + +class LatticeNXSDRFFImpl(Module): + def __init__(self, i, o, clk): + self.specials += Instance("FD1P3BX", + i_CK = clk, + i_PD = 0, + i_SP = 1, + i_D = i, + o_Q = o, + ) + +class LatticeNXSDRInputViaFlipFlop: + @staticmethod + def lower(dr): + return LatticeNXSDRFFImpl(dr.i, dr.o, dr.clk) + +class LatticeNXSDROutputViaFlipFlop: + @staticmethod + def lower(dr): + return LatticeNXSDRFFImpl(dr.i, dr.o, dr.clk) + # NX DDR Input ------------------------------------------------------------------------------------- class LatticeNXDDRInputImpl(Module): @@ -283,6 +308,12 @@ lattice_NX_special_overrides = { DDROutput: LatticeNXDDROutput, } +lattice_NX_special_overrides_for_oxide = dict(lattice_NX_special_overrides) +lattice_NX_special_overrides_for_oxide.update({ + SDRInput: LatticeNXSDRInputViaFlipFlop, + SDROutput: LatticeNXSDROutputViaFlipFlop, +}) + # iCE40 AsyncResetSynchronizer --------------------------------------------------------------------- class LatticeiCE40AsyncResetSynchronizerImpl(Module): diff --git a/litex/build/lattice/oxide.py b/litex/build/lattice/oxide.py index dfdc0d798..f2042480c 100644 --- a/litex/build/lattice/oxide.py +++ b/litex/build/lattice/oxide.py @@ -110,7 +110,7 @@ class LatticeOxideToolchain: "keep": ("keep", "true"), } - special_overrides = common.lattice_NX_special_overrides + special_overrides = common.lattice_NX_special_overrides_for_oxide def __init__(self): self.yosys_template = _yosys_template