2020-08-24 15:56:11 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
#
|
|
|
|
# This file is part of LiteDRAM.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2020 Florent Kermarrec <florent@enjoy-digital.fr>
|
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
|
|
import os
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
from migen import *
|
2020-12-10 02:44:35 -05:00
|
|
|
from migen.genlib.resetsync import AsyncResetSynchronizer
|
2020-08-24 15:56:11 -04:00
|
|
|
|
|
|
|
from litex.boards.platforms import kcu105
|
|
|
|
|
|
|
|
from litex.soc.cores.clock import *
|
2020-10-29 13:58:37 -04:00
|
|
|
from litex.soc.interconnect.csr import *
|
2020-08-24 15:56:11 -04:00
|
|
|
from litex.soc.integration.soc_core import *
|
|
|
|
from litex.soc.integration.soc_sdram import *
|
|
|
|
from litex.soc.integration.builder import *
|
|
|
|
|
|
|
|
from litedram.modules import EDY4016A
|
|
|
|
from litedram.phy import usddrphy
|
|
|
|
|
2020-09-24 07:03:07 -04:00
|
|
|
from liteeth.phy.ku_1000basex import KU_1000BASEX
|
|
|
|
|
2020-08-24 15:56:11 -04:00
|
|
|
# CRG ----------------------------------------------------------------------------------------------
|
|
|
|
|
2020-08-28 11:57:59 -04:00
|
|
|
class _CRG(Module, AutoCSR):
|
2020-08-24 15:56:11 -04:00
|
|
|
def __init__(self, platform, sys_clk_freq):
|
2020-08-28 13:03:44 -04:00
|
|
|
self.clock_domains.cd_sys_pll = ClockDomain()
|
|
|
|
self.clock_domains.cd_sys = ClockDomain()
|
|
|
|
self.clock_domains.cd_sys4x = ClockDomain(reset_less=True)
|
|
|
|
self.clock_domains.cd_pll4x = ClockDomain(reset_less=True)
|
2020-11-06 10:14:22 -05:00
|
|
|
self.clock_domains.cd_idelay = ClockDomain()
|
2020-08-28 13:03:44 -04:00
|
|
|
self.clock_domains.cd_uart = ClockDomain()
|
2020-09-24 07:03:07 -04:00
|
|
|
self.clock_domains.cd_eth = ClockDomain()
|
2020-08-24 15:56:11 -04:00
|
|
|
|
|
|
|
# # #
|
|
|
|
|
2020-08-28 13:03:44 -04:00
|
|
|
self.submodules.main_pll = main_pll = USMMCM(speedgrade=-2)
|
|
|
|
self.comb += main_pll.reset.eq(platform.request("cpu_reset"))
|
|
|
|
main_pll.register_clkin(platform.request("clk125"), 125e6)
|
|
|
|
main_pll.create_clkout(self.cd_sys_pll, sys_clk_freq)
|
2020-11-06 10:14:22 -05:00
|
|
|
main_pll.create_clkout(self.cd_idelay, 200e6, with_reset=False)
|
2020-08-28 13:03:44 -04:00
|
|
|
main_pll.create_clkout(self.cd_uart, 100e6)
|
2020-09-24 07:03:07 -04:00
|
|
|
main_pll.create_clkout(self.cd_eth, 200e6)
|
2020-08-28 13:03:44 -04:00
|
|
|
main_pll.expose_drp()
|
|
|
|
|
2020-08-24 15:56:11 -04:00
|
|
|
self.submodules.pll = pll = USMMCM(speedgrade=-2)
|
2020-08-28 13:03:44 -04:00
|
|
|
self.comb += pll.reset.eq(~main_pll.locked)
|
|
|
|
pll.register_clkin(self.cd_sys_pll.clk, sys_clk_freq)
|
2020-08-28 11:57:59 -04:00
|
|
|
pll.create_clkout(self.cd_pll4x, sys_clk_freq*4, buf=None, with_reset=False)
|
2020-08-24 15:56:11 -04:00
|
|
|
|
|
|
|
self.specials += [
|
2020-11-06 10:14:22 -05:00
|
|
|
Instance("BUFGCE_DIV",
|
|
|
|
p_BUFGCE_DIVIDE = 4,
|
|
|
|
i_CE = 1,
|
|
|
|
i_I = self.cd_pll4x.clk,
|
|
|
|
o_O = self.cd_sys.clk,
|
|
|
|
),
|
|
|
|
Instance("BUFGCE",
|
|
|
|
i_CE = 1,
|
|
|
|
i_I = self.cd_pll4x.clk,
|
|
|
|
o_O = self.cd_sys4x.clk,
|
|
|
|
),
|
|
|
|
AsyncResetSynchronizer(self.cd_idelay, ~pll.locked),
|
2020-08-24 15:56:11 -04:00
|
|
|
]
|
|
|
|
|
2020-11-06 10:14:22 -05:00
|
|
|
self.submodules.idelayctrl = USIDELAYCTRL(cd_ref=self.cd_idelay, cd_sys=self.cd_sys)
|
2020-08-24 15:56:11 -04:00
|
|
|
|
|
|
|
sys_clk_counter = Signal(32)
|
|
|
|
self.sync += sys_clk_counter.eq(sys_clk_counter + 1)
|
|
|
|
self.sys_clk_counter = CSRStatus(32)
|
|
|
|
self.comb += self.sys_clk_counter.status.eq(sys_clk_counter)
|
|
|
|
|
|
|
|
# Bench SoC ----------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class BenchSoC(SoCCore):
|
2020-12-10 02:44:35 -05:00
|
|
|
def __init__(self, uart="crossover", sys_clk_freq=int(125e6), with_bist=False, with_analyzer=False):
|
2020-08-24 15:56:11 -04:00
|
|
|
platform = kcu105.Platform()
|
|
|
|
|
|
|
|
# SoCCore ----------------------------------------------------------------------------------
|
2020-10-29 13:58:37 -04:00
|
|
|
SoCCore.__init__(self, platform, clk_freq=sys_clk_freq,
|
2020-12-10 05:12:45 -05:00
|
|
|
ident = "LiteDRAM bench on KCU105",
|
|
|
|
ident_version = True,
|
2020-10-29 13:58:37 -04:00
|
|
|
integrated_rom_size = 0x10000,
|
2020-08-24 15:56:11 -04:00
|
|
|
integrated_rom_mode = "rw",
|
|
|
|
csr_data_width = 32,
|
2020-09-24 07:03:07 -04:00
|
|
|
uart_name = uart)
|
2020-08-24 15:56:11 -04:00
|
|
|
|
|
|
|
# CRG --------------------------------------------------------------------------------------
|
|
|
|
self.submodules.crg = _CRG(platform, sys_clk_freq)
|
2020-08-27 12:41:54 -04:00
|
|
|
self.add_csr("crg")
|
2020-08-24 15:56:11 -04:00
|
|
|
|
|
|
|
# DDR4 SDRAM -------------------------------------------------------------------------------
|
|
|
|
self.submodules.ddrphy = usddrphy.USDDRPHY(platform.request("ddram"),
|
|
|
|
memtype = "DDR4",
|
|
|
|
sys_clk_freq = sys_clk_freq,
|
2020-08-28 11:57:59 -04:00
|
|
|
iodelay_clk_freq = 200e6)
|
2020-08-24 15:56:11 -04:00
|
|
|
self.add_csr("ddrphy")
|
|
|
|
self.add_sdram("sdram",
|
2020-11-06 04:34:26 -05:00
|
|
|
phy = self.ddrphy,
|
|
|
|
module = EDY4016A(sys_clk_freq, "1:4"),
|
|
|
|
origin = self.mem_map["main_ram"],
|
|
|
|
size = 0x40000000,
|
|
|
|
with_bist = with_bist,
|
2020-08-24 15:56:11 -04:00
|
|
|
)
|
|
|
|
|
2020-08-28 03:46:28 -04:00
|
|
|
# UARTBone ---------------------------------------------------------------------------------
|
2020-09-24 07:03:07 -04:00
|
|
|
if uart != "serial":
|
|
|
|
self.add_uartbone(name="serial", clk_freq=100e6, baudrate=115200, cd="uart")
|
|
|
|
|
|
|
|
# Etherbone --------------------------------------------------------------------------------
|
|
|
|
self.submodules.ethphy = KU_1000BASEX(self.crg.cd_eth.clk,
|
|
|
|
data_pads = self.platform.request("sfp", 0),
|
|
|
|
sys_clk_freq = self.clk_freq)
|
|
|
|
self.add_csr("ethphy")
|
|
|
|
self.comb += self.platform.request("sfp_tx_disable_n", 0).eq(1)
|
|
|
|
self.platform.add_platform_command("set_property SEVERITY {{Warning}} [get_drc_checks REQP-1753]")
|
|
|
|
self.add_etherbone(phy=self.ethphy)
|
2020-08-24 15:56:11 -04:00
|
|
|
|
2020-12-10 02:44:35 -05:00
|
|
|
# Analyzer ---------------------------------------------------------------------------------
|
|
|
|
if with_analyzer:
|
|
|
|
from litescope import LiteScopeAnalyzer
|
|
|
|
analyzer_signals = [self.ddrphy.dfi]
|
|
|
|
self.submodules.analyzer = LiteScopeAnalyzer(analyzer_signals,
|
|
|
|
depth = 256,
|
|
|
|
clock_domain = "sys",
|
|
|
|
csr_csv = "analyzer.csv")
|
|
|
|
self.add_csr("analyzer")
|
|
|
|
|
2020-08-24 15:56:11 -04:00
|
|
|
# Leds -------------------------------------------------------------------------------------
|
2020-10-29 13:58:37 -04:00
|
|
|
from litex.soc.cores.led import LedChaser
|
2020-08-24 15:56:11 -04:00
|
|
|
self.submodules.leds = LedChaser(
|
|
|
|
pads = platform.request_all("user_led"),
|
|
|
|
sys_clk_freq = sys_clk_freq)
|
|
|
|
self.add_csr("leds")
|
|
|
|
|
|
|
|
# Main ---------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description="LiteDRAM Bench on KCU105")
|
2020-12-10 02:44:35 -05:00
|
|
|
parser.add_argument("--uart", default="crossover", help="Selected UART: crossover (default) or serial")
|
|
|
|
parser.add_argument("--build", action="store_true", help="Build bitstream")
|
|
|
|
parser.add_argument("--with-bist", action="store_true", help="Add BIST Generator/Checker")
|
|
|
|
parser.add_argument("--with-analyzer", action="store_true", help="Add Analyzer")
|
|
|
|
parser.add_argument("--load", action="store_true", help="Load bitstream")
|
|
|
|
parser.add_argument("--load-bios", action="store_true", help="Load BIOS")
|
|
|
|
parser.add_argument("--set-sys-clk", default=None, help="Set sys_clk")
|
|
|
|
parser.add_argument("--test", action="store_true", help="Run Full Bench")
|
2020-08-24 15:56:11 -04:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2020-12-10 02:44:35 -05:00
|
|
|
soc = BenchSoC(uart=args.uart, with_bist=args.with_bist, with_analyzer=args.with_analyzer)
|
2020-08-27 12:41:54 -04:00
|
|
|
builder = Builder(soc, csr_csv="csr.csv")
|
|
|
|
builder.build(run=args.build)
|
2020-08-24 15:56:11 -04:00
|
|
|
|
|
|
|
if args.load:
|
|
|
|
prog = soc.platform.create_programmer()
|
|
|
|
prog.load_bitstream(os.path.join(builder.gateware_dir, soc.build_name + ".bit"))
|
|
|
|
|
2020-09-24 07:03:07 -04:00
|
|
|
if args.load_bios:
|
|
|
|
from common import s7_load_bios
|
|
|
|
s7_load_bios("build/kcu105/software/bios/bios.bin")
|
|
|
|
|
|
|
|
if args.set_sys_clk is not None:
|
|
|
|
from common import us_set_sys_clk
|
|
|
|
us_set_sys_clk(clk_freq=float(args.config), vco_freq=soc.crg.main_pll.compute_config()["vco"])
|
|
|
|
|
2020-08-24 15:56:11 -04:00
|
|
|
if args.test:
|
2020-08-28 11:57:59 -04:00
|
|
|
from common import us_bench_test
|
|
|
|
us_bench_test(
|
2020-08-28 13:03:44 -04:00
|
|
|
freq_min = 80e6,
|
2020-08-28 11:57:59 -04:00
|
|
|
freq_max = 180e6,
|
|
|
|
freq_step = 1e6,
|
|
|
|
vco_freq = soc.crg.pll.compute_config()["vco"],
|
|
|
|
bios_filename = "build/kcu105/software/bios/bios.bin")
|
2020-08-24 15:56:11 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|