2024-03-26 15:43:35 -04:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# This file is part of LiteX-Boards.
|
|
|
|
|
#
|
|
|
|
|
# Copyright (c) 2024 Gwenhael Goavec-Merou <gwenhael@enjoy-digital.fr>
|
|
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
|
|
|
|
# Build/use
|
|
|
|
|
# Build/Load bitstream:
|
|
|
|
|
# ./xilinx_zc706.py --with-jtagbone --uart-name=crossover --csr-csv=csr.csv --build --load
|
|
|
|
|
#
|
|
|
|
|
# litex_server --jtag --jtag-config openocd_xc7z_smt2-nc.cfg
|
|
|
|
|
#
|
|
|
|
|
# In a second terminal:
|
|
|
|
|
# litex_cli --regs # to dump all registers
|
|
|
|
|
# Or
|
|
|
|
|
# litex_term crossover # to have access to LiteX bios
|
|
|
|
|
#
|
|
|
|
|
# --------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
from migen import *
|
|
|
|
|
|
|
|
|
|
from litex.gen import *
|
|
|
|
|
|
|
|
|
|
from litex_boards.platforms import xilinx_zc706
|
|
|
|
|
|
|
|
|
|
from litex.soc.cores.clock import *
|
|
|
|
|
from litex.soc.integration.soc_core import *
|
|
|
|
|
from litex.soc.integration.builder import *
|
|
|
|
|
from litex.soc.cores.led import LedChaser
|
|
|
|
|
|
2024-03-27 03:49:40 -04:00
|
|
|
|
from litedram.modules import MT8JTF12864
|
|
|
|
|
from litedram.phy import s7ddrphy
|
|
|
|
|
|
2024-03-26 16:53:45 -04:00
|
|
|
|
from liteeth.phy.k7_1000basex import K7_1000BASEX
|
|
|
|
|
|
2024-03-26 16:41:41 -04:00
|
|
|
|
from litepcie.phy.s7pciephy import S7PCIEPHY
|
|
|
|
|
from litepcie.software import generate_litepcie_software
|
|
|
|
|
|
2024-03-26 15:43:35 -04:00
|
|
|
|
# CRG ----------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
class _CRG(LiteXModule):
|
|
|
|
|
def __init__(self, platform, sys_clk_freq):
|
2024-03-27 03:49:40 -04:00
|
|
|
|
self.rst = Signal()
|
|
|
|
|
self.cd_sys = ClockDomain()
|
|
|
|
|
self.cd_sys4x = ClockDomain()
|
|
|
|
|
self.cd_idelay = ClockDomain()
|
|
|
|
|
self.cd_eth = ClockDomain()
|
2024-03-26 15:43:35 -04:00
|
|
|
|
|
|
|
|
|
# # #
|
|
|
|
|
|
2024-03-26 16:35:10 -04:00
|
|
|
|
# Clk/Rst.
|
|
|
|
|
clk200 = platform.request("clk200")
|
|
|
|
|
|
|
|
|
|
# PLL.
|
2024-03-26 15:43:35 -04:00
|
|
|
|
self.pll = pll = S7PLL(speedgrade=-1)
|
|
|
|
|
self.comb += pll.reset.eq(self.rst)
|
2024-03-26 16:35:10 -04:00
|
|
|
|
pll.register_clkin(clk200, 200e6)
|
2024-03-27 03:49:40 -04:00
|
|
|
|
pll.create_clkout(self.cd_sys, sys_clk_freq)
|
|
|
|
|
pll.create_clkout(self.cd_sys4x, 4*sys_clk_freq)
|
|
|
|
|
pll.create_clkout(self.cd_idelay, 200e6)
|
|
|
|
|
pll.create_clkout(self.cd_eth, 200e6)
|
2024-03-26 15:43:35 -04:00
|
|
|
|
platform.add_false_path_constraints(self.cd_sys.clk, pll.clkin) # Ignore sys_clk to pll.clkin path created by SoC's rst.
|
|
|
|
|
|
2024-03-27 03:49:40 -04:00
|
|
|
|
# IDelayCtrl.
|
|
|
|
|
self.idelayctrl = S7IDELAYCTRL(self.cd_idelay)
|
|
|
|
|
|
2024-03-26 15:43:35 -04:00
|
|
|
|
# BaseSoC ------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
class BaseSoC(SoCCore):
|
2024-03-26 16:53:45 -04:00
|
|
|
|
def __init__(self, sys_clk_freq=125e6,
|
|
|
|
|
with_ethernet = False,
|
|
|
|
|
with_etherbone = False,
|
|
|
|
|
eth_ip = "192.168.1.50",
|
|
|
|
|
remote_ip = None,
|
|
|
|
|
eth_dynamic_ip = False,
|
|
|
|
|
with_led_chaser = True,
|
|
|
|
|
with_pcie = False,
|
|
|
|
|
**kwargs):
|
2024-03-26 15:43:35 -04:00
|
|
|
|
platform = xilinx_zc706.Platform()
|
|
|
|
|
kwargs["uart_name"] = "crossover"
|
|
|
|
|
kwargs["with_jtagbone"] = True
|
|
|
|
|
|
|
|
|
|
# CRG --------------------------------------------------------------------------------------
|
|
|
|
|
self.crg = _CRG(platform, sys_clk_freq)
|
|
|
|
|
|
|
|
|
|
# SoCCore ----------------------------------------------------------------------------------
|
2024-03-26 16:35:10 -04:00
|
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq, ident="LiteX SoC on ZCU706", **kwargs)
|
2024-03-26 15:43:35 -04:00
|
|
|
|
|
2024-03-27 03:49:40 -04:00
|
|
|
|
# DDR3 SDRAM -------------------------------------------------------------------------------
|
|
|
|
|
if not self.integrated_main_ram_size:
|
|
|
|
|
self.ddrphy = s7ddrphy.K7DDRPHY(platform.request("ddram"),
|
|
|
|
|
memtype = "DDR3",
|
|
|
|
|
nphases = 4,
|
|
|
|
|
sys_clk_freq = sys_clk_freq)
|
|
|
|
|
self.add_sdram("sdram",
|
|
|
|
|
phy = self.ddrphy,
|
|
|
|
|
module = MT8JTF12864(sys_clk_freq, "1:4"),
|
|
|
|
|
l2_cache_size = kwargs.get("l2_size", 8192)
|
|
|
|
|
)
|
|
|
|
|
|
2024-03-26 16:53:45 -04:00
|
|
|
|
# Ethernet / Etherbone ---------------------------------------------------------------------
|
|
|
|
|
if with_ethernet or with_etherbone:
|
|
|
|
|
self.ethphy = K7_1000BASEX(
|
|
|
|
|
refclk_or_clk_pads = self.crg.cd_eth.clk,
|
|
|
|
|
data_pads = self.platform.request("sfp", 0),
|
|
|
|
|
sys_clk_freq = self.clk_freq,
|
|
|
|
|
with_csr = False
|
|
|
|
|
)
|
|
|
|
|
self.comb += self.platform.request("sfp_tx_disable_n", 0).eq(1)
|
|
|
|
|
platform.add_platform_command("set_property SEVERITY {{Warning}} [get_drc_checks REQP-52]")
|
|
|
|
|
if with_etherbone:
|
|
|
|
|
self.add_etherbone(phy=self.ethphy, ip_address=eth_ip, with_ethmac=with_ethernet)
|
|
|
|
|
elif with_ethernet:
|
|
|
|
|
self.add_ethernet(phy=self.ethphy, dynamic_ip=eth_dynamic_ip, local_ip=eth_ip, remote_ip=remote_ip)
|
|
|
|
|
|
2024-03-26 16:41:41 -04:00
|
|
|
|
# PCIe -------------------------------------------------------------------------------------
|
|
|
|
|
if with_pcie:
|
|
|
|
|
self.pcie_phy = S7PCIEPHY(platform, platform.request("pcie_x4"),
|
|
|
|
|
data_width = 128,
|
|
|
|
|
bar0_size = 0x20000)
|
|
|
|
|
self.add_pcie(phy=self.pcie_phy, ndmas=1)
|
|
|
|
|
|
2024-03-26 15:43:35 -04:00
|
|
|
|
# Leds -------------------------------------------------------------------------------------
|
|
|
|
|
if with_led_chaser:
|
|
|
|
|
self.leds = LedChaser(
|
|
|
|
|
pads = platform.request_all("user_led"),
|
|
|
|
|
sys_clk_freq = sys_clk_freq
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Build --------------------------------------------------------------------------------------------
|
|
|
|
|
def main():
|
|
|
|
|
from litex.build.parser import LiteXArgumentParser
|
|
|
|
|
parser = LiteXArgumentParser(platform=xilinx_zc706.Platform, description="LiteX SoC on ZC706.")
|
2024-03-26 16:53:45 -04:00
|
|
|
|
parser.add_target_argument("--sys-clk-freq", default=125e6, type=float, help="System clock frequency.")
|
|
|
|
|
parser.add_target_argument("--with-ethernet", action="store_true", help="Enable Ethernet support.")
|
|
|
|
|
parser.add_target_argument("--with-etherbone", action="store_true", help="Enable Etherbone support.")
|
|
|
|
|
parser.add_target_argument("--eth-ip", default="192.168.1.50", help="Ethernet/Etherbone IP address.")
|
|
|
|
|
parser.add_target_argument("--remote-ip", default="192.168.1.100", help="Remote IP address of TFTP server.")
|
|
|
|
|
parser.add_target_argument("--eth-dynamic-ip", action="store_true", help="Enable dynamic Ethernet IP addresses setting.")
|
|
|
|
|
parser.add_target_argument("--with-pcie", action="store_true", help="Enable PCIe support.")
|
|
|
|
|
parser.add_target_argument("--driver", action="store_true", help="Generate PCIe driver.")
|
2024-03-26 15:43:35 -04:00
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
2024-03-26 16:41:41 -04:00
|
|
|
|
soc = BaseSoC(
|
2024-03-26 16:53:45 -04:00
|
|
|
|
sys_clk_freq = args.sys_clk_freq,
|
|
|
|
|
with_ethernet = args.with_ethernet,
|
|
|
|
|
with_etherbone = args.with_etherbone,
|
|
|
|
|
eth_ip = args.eth_ip,
|
|
|
|
|
remote_ip = args.remote_ip,
|
|
|
|
|
eth_dynamic_ip = args.eth_dynamic_ip,
|
|
|
|
|
with_pcie = args.with_pcie,
|
2024-03-26 16:41:41 -04:00
|
|
|
|
**parser.soc_argdict
|
|
|
|
|
)
|
2024-03-26 15:43:35 -04:00
|
|
|
|
builder = Builder(soc, **parser.builder_argdict)
|
|
|
|
|
if args.build:
|
|
|
|
|
builder.build(**parser.toolchain_argdict)
|
|
|
|
|
|
2024-03-27 03:49:40 -04:00
|
|
|
|
if args.driver:
|
|
|
|
|
generate_litepcie_software(soc, os.path.join(builder.output_dir, "driver"))
|
|
|
|
|
|
2024-03-26 15:43:35 -04:00
|
|
|
|
if args.load:
|
|
|
|
|
prog = soc.platform.create_programmer()
|
|
|
|
|
prog.load_bitstream(builder.get_bitstream_filename(mode="sram"))
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|