# This file is Copyright (c) 2019 Florent Kermarrec # License: BSD #!/usr/bin/env python3 from migen import * from litex.build.generic_platform import * from litex.build.xilinx import XilinxPlatform from litex.soc.cores.clock import * from litex.soc.interconnect.csr import * from litex.soc.integration.soc_core import * from litex.soc.integration.builder import * from litex.soc.cores.uart import UARTWishboneBridge from litescope import LiteScopeAnalyzer from usb3_pipe.serdes import A7USB3SerDes from usb3_pipe.phy import USB3PHY # IOs ---------------------------------------------------------------------------------------------- _io = [ ("clk100", 0, Pins("R4"), IOStandard("LVCMOS33")), ("user_led", 0, Pins("AB1"), IOStandard("LVCMOS33")), ("user_led", 1, Pins("AB8"), IOStandard("LVCMOS33")), ("user_btn", 0, Pins("AA1"), IOStandard("LVCMOS33")), ("user_btn", 1, Pins("AB6"), IOStandard("LVCMOS33")), ("serial", 0, Subsignal("tx", Pins("T1")), Subsignal("rx", Pins("U1")), IOStandard("LVCMOS33"), ), ("pcie_tx", 0, Subsignal("p", Pins("B6")), Subsignal("n", Pins("A6")), ), ("pcie_rx", 0, Subsignal("p", Pins("B10")), Subsignal("n", Pins("A10")), ), ] # Platform ----------------------------------------------------------------------------------------- class Platform(XilinxPlatform): def __init__(self): XilinxPlatform.__init__(self, "xc7a35t-fgg484-2", _io, toolchain="vivado") # CRG ---------------------------------------------------------------------------------------------- class _CRG(Module): def __init__(self, platform, sys_clk_freq): self.clock_domains.cd_sys = ClockDomain() self.clock_domains.cd_oob = ClockDomain() self.clock_domains.cd_clk125 = ClockDomain() # # # clk100 = platform.request("clk100") platform.add_period_constraint(clk100, 1e9/100e6) self.cd_sys.clk.attr.add("keep") self.cd_clk125.clk.attr.add("keep") self.submodules.pll = pll = S7PLL(speedgrade=-2) pll.register_clkin(clk100, 100e6) pll.create_clkout(self.cd_sys, sys_clk_freq) pll.create_clkout(self.cd_oob, sys_clk_freq/8) pll.create_clkout(self.cd_clk125, 125e6) # USB3SoC ------------------------------------------------------------------------------------------ class USB3SoC(SoCMini): def __init__(self, platform, with_analyzer=False): sys_clk_freq = int(133e6) SoCMini.__init__(self, platform, sys_clk_freq, ident="USB3SoC", ident_version=True) # CRG -------------------------------------------------------------------------------------- self.submodules.crg = _CRG(platform, sys_clk_freq) # Serial bridge ---------------------------------------------------------------------------- self.submodules.serial_bridge = UARTWishboneBridge(platform.request("serial"), sys_clk_freq) self.add_wb_master(self.serial_bridge.wishbone) # USB3 SerDes ------------------------------------------------------------------------------ usb3_serdes = A7USB3SerDes(platform, sys_clk = self.crg.cd_sys.clk, sys_clk_freq = sys_clk_freq, refclk_pads = ClockSignal("clk125"), refclk_freq = 125e6, tx_pads = platform.request("pcie_tx"), rx_pads = platform.request("pcie_rx")) self.submodules += usb3_serdes self.comb += [ usb3_serdes.tx_polarity.eq(0), usb3_serdes.rx_polarity.eq(0), ] # USB3 PHY --------------------------------------------------------------------------------- usb3_phy = USB3PHY(serdes=usb3_serdes, sys_clk_freq=sys_clk_freq) self.submodules += usb3_phy # Leds ------------------------------------------------------------------------------------- self.comb += platform.request("user_led", 0).eq(usb3_serdes.ready) self.comb += platform.request("user_led", 1).eq(usb3_phy.ready) # Analyzer --------------------------------------------------------------------------------- if with_analyzer: analyzer_signals = [ # LFPS usb3_serdes.tx_idle, usb3_serdes.rx_idle, usb3_serdes.tx_pattern, usb3_phy.lfps.rx_polling, usb3_phy.lfps.tx_polling, # Training Sequence usb3_phy.ts.rx_tseq, usb3_phy.ts.rx_ts1, usb3_phy.ts.rx_ts2, usb3_phy.ts.tx_ts2, # LTSSM usb3_phy.ltssm.polling_fsm, # Endpoints usb3_serdes.source, usb3_serdes.sink, ] self.submodules.analyzer = LiteScopeAnalyzer(analyzer_signals, 4096, csr_csv="tools/analyzer.csv") self.add_csr("analyzer") # Build -------------------------------------------------------------------------------------------- def main(): platform = Platform() soc = USB3SoC(platform) builder = Builder(soc, output_dir="build", csr_csv="tools/csr.csv") vns = builder.build() if __name__ == "__main__": main()