mirror of https://github.com/openXC7/prjxray.git
run make format
Signed-off-by: Alessandro Comodi <acomodi@antmicro.com>
This commit is contained in:
parent
f85e244ac6
commit
8736d80af3
|
|
@ -21,76 +21,89 @@ from litedram.phy import s7ddrphy
|
||||||
|
|
||||||
# CRG ----------------------------------------------------------------------------------------------
|
# CRG ----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
class _CRG(Module):
|
class _CRG(Module):
|
||||||
def __init__(self, platform, sys_clk_freq):
|
def __init__(self, platform, sys_clk_freq):
|
||||||
self.clock_domains.cd_sys = ClockDomain()
|
self.clock_domains.cd_sys = ClockDomain()
|
||||||
self.clock_domains.cd_sys4x = ClockDomain(reset_less=True)
|
self.clock_domains.cd_sys4x = ClockDomain(reset_less=True)
|
||||||
self.clock_domains.cd_sys4x_dqs = ClockDomain(reset_less=True)
|
self.clock_domains.cd_sys4x_dqs = ClockDomain(reset_less=True)
|
||||||
self.clock_domains.cd_clk200 = ClockDomain()
|
self.clock_domains.cd_clk200 = ClockDomain()
|
||||||
|
|
||||||
# # #
|
# # #
|
||||||
|
|
||||||
self.submodules.pll = pll = S7PLL(speedgrade=-1)
|
self.submodules.pll = pll = S7PLL(speedgrade=-1)
|
||||||
self.comb += pll.reset.eq(~platform.request("cpu_reset"))
|
self.comb += pll.reset.eq(~platform.request("cpu_reset"))
|
||||||
pll.register_clkin(platform.request("clk100"), 100e6)
|
pll.register_clkin(platform.request("clk100"), 100e6)
|
||||||
pll.create_clkout(self.cd_sys, sys_clk_freq)
|
pll.create_clkout(self.cd_sys, sys_clk_freq)
|
||||||
pll.create_clkout(self.cd_sys4x, 4*sys_clk_freq)
|
pll.create_clkout(self.cd_sys4x, 4 * sys_clk_freq)
|
||||||
pll.create_clkout(self.cd_sys4x_dqs, 4*sys_clk_freq, phase=90)
|
pll.create_clkout(self.cd_sys4x_dqs, 4 * sys_clk_freq, phase=90)
|
||||||
pll.create_clkout(self.cd_clk200, 200e6)
|
pll.create_clkout(self.cd_clk200, 200e6)
|
||||||
|
|
||||||
self.submodules.idelayctrl = S7IDELAYCTRL(self.cd_clk200)
|
self.submodules.idelayctrl = S7IDELAYCTRL(self.cd_clk200)
|
||||||
|
|
||||||
|
|
||||||
# BaseSoC ------------------------------------------------------------------------------------------
|
# BaseSoC ------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
class BaseSoC(SoCSDRAM):
|
class BaseSoC(SoCSDRAM):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
platform = arty.Platform()
|
platform = arty.Platform()
|
||||||
sys_clk_freq = int(50e6)
|
sys_clk_freq = int(50e6)
|
||||||
|
|
||||||
# SoCSDRAM ---------------------------------------------------------------------------------
|
# SoCSDRAM ---------------------------------------------------------------------------------
|
||||||
SoCSDRAM.__init__(self, platform, clk_freq=sys_clk_freq,
|
SoCSDRAM.__init__(
|
||||||
ident = "Minimal Arty DDR3 Design for tests with Project X-Ray", ident_version=True,
|
self,
|
||||||
cpu_type = None,
|
platform,
|
||||||
l2_size = 16,
|
clk_freq=sys_clk_freq,
|
||||||
uart_name = "bridge")
|
ident="Minimal Arty DDR3 Design for tests with Project X-Ray",
|
||||||
|
ident_version=True,
|
||||||
|
cpu_type=None,
|
||||||
|
l2_size=16,
|
||||||
|
uart_name="bridge")
|
||||||
|
|
||||||
# CRG --------------------------------------------------------------------------------------
|
# CRG --------------------------------------------------------------------------------------
|
||||||
self.submodules.crg = _CRG(platform, sys_clk_freq)
|
self.submodules.crg = _CRG(platform, sys_clk_freq)
|
||||||
|
|
||||||
# DDR3 SDRAM -------------------------------------------------------------------------------
|
# DDR3 SDRAM -------------------------------------------------------------------------------
|
||||||
if not self.integrated_main_ram_size:
|
if not self.integrated_main_ram_size:
|
||||||
self.submodules.ddrphy = s7ddrphy.A7DDRPHY(platform.request("ddram"),
|
self.submodules.ddrphy = s7ddrphy.A7DDRPHY(
|
||||||
memtype = "DDR3",
|
platform.request("ddram"),
|
||||||
nphases = 4,
|
memtype="DDR3",
|
||||||
sys_clk_freq = sys_clk_freq)
|
nphases=4,
|
||||||
|
sys_clk_freq=sys_clk_freq)
|
||||||
self.add_csr("ddrphy")
|
self.add_csr("ddrphy")
|
||||||
sdram_module = MT41K128M16(sys_clk_freq, "1:4")
|
sdram_module = MT41K128M16(sys_clk_freq, "1:4")
|
||||||
self.register_sdram(self.ddrphy,
|
self.register_sdram(
|
||||||
geom_settings = sdram_module.geom_settings,
|
self.ddrphy,
|
||||||
timing_settings = sdram_module.timing_settings)
|
geom_settings=sdram_module.geom_settings,
|
||||||
|
timing_settings=sdram_module.timing_settings)
|
||||||
|
|
||||||
def generate_sdram_phy_py_header(self):
|
def generate_sdram_phy_py_header(self):
|
||||||
f = open("sdram_init.py", "w")
|
f = open("sdram_init.py", "w")
|
||||||
f.write(get_sdram_phy_py_header(
|
f.write(
|
||||||
self.sdram.controller.settings.phy,
|
get_sdram_phy_py_header(
|
||||||
self.sdram.controller.settings.timing))
|
self.sdram.controller.settings.phy,
|
||||||
|
self.sdram.controller.settings.timing))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
# Load ---------------------------------------------------------------------------------------------
|
# Load ---------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def load():
|
def load():
|
||||||
prog = VivadoProgrammer()
|
prog = VivadoProgrammer()
|
||||||
prog.load_bitstream("build/gateware/top.bit")
|
prog.load_bitstream("build/gateware/top.bit")
|
||||||
|
|
||||||
|
|
||||||
# Build --------------------------------------------------------------------------------------------
|
# Build --------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def main():
|
|
||||||
parser = argparse.ArgumentParser(description="Minimal Arty DDR3 Design for tests with Project X-Ray")
|
|
||||||
parser.add_argument("--build", action="store_true", help="Build bitstream")
|
|
||||||
parser.add_argument("--load", action="store_true", help="Load bitstream")
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Minimal Arty DDR3 Design for tests with Project X-Ray")
|
||||||
|
parser.add_argument("--build", action="store_true", help="Build bitstream")
|
||||||
|
parser.add_argument("--load", action="store_true", help="Load bitstream")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.load:
|
if args.load:
|
||||||
load()
|
load()
|
||||||
|
|
@ -99,5 +112,6 @@ def main():
|
||||||
builder.build(run=args.build)
|
builder.build(run=args.build)
|
||||||
soc.generate_sdram_phy_py_header()
|
soc.generate_sdram_phy_py_header()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,33 @@
|
||||||
dfii_control_sel = 0x01
|
dfii_control_sel = 0x01
|
||||||
dfii_control_cke = 0x02
|
dfii_control_cke = 0x02
|
||||||
dfii_control_odt = 0x04
|
dfii_control_odt = 0x04
|
||||||
dfii_control_reset_n = 0x08
|
dfii_control_reset_n = 0x08
|
||||||
|
|
||||||
dfii_command_cs = 0x01
|
dfii_command_cs = 0x01
|
||||||
dfii_command_we = 0x02
|
dfii_command_we = 0x02
|
||||||
dfii_command_cas = 0x04
|
dfii_command_cas = 0x04
|
||||||
dfii_command_ras = 0x08
|
dfii_command_ras = 0x08
|
||||||
dfii_command_wrdata = 0x10
|
dfii_command_wrdata = 0x10
|
||||||
dfii_command_rddata = 0x20
|
dfii_command_rddata = 0x20
|
||||||
|
|
||||||
ddrx_mr1 = 0x6
|
ddrx_mr1 = 0x6
|
||||||
|
|
||||||
init_sequence = [
|
init_sequence = [
|
||||||
("Release reset", 0, 0, dfii_control_odt|dfii_control_reset_n, 50000),
|
("Release reset", 0, 0, dfii_control_odt | dfii_control_reset_n, 50000),
|
||||||
("Bring CKE high", 0, 0, dfii_control_cke|dfii_control_odt|dfii_control_reset_n, 10000),
|
(
|
||||||
("Load Mode Register 2, CWL=5", 512, 2, dfii_command_ras|dfii_command_cas|dfii_command_we|dfii_command_cs, 0),
|
"Bring CKE high", 0, 0,
|
||||||
("Load Mode Register 3", 0, 3, dfii_command_ras|dfii_command_cas|dfii_command_we|dfii_command_cs, 0),
|
dfii_control_cke | dfii_control_odt | dfii_control_reset_n, 10000),
|
||||||
("Load Mode Register 1", 6, 1, dfii_command_ras|dfii_command_cas|dfii_command_we|dfii_command_cs, 0),
|
(
|
||||||
("Load Mode Register 0, CL=6, BL=8", 2336, 0, dfii_command_ras|dfii_command_cas|dfii_command_we|dfii_command_cs, 200),
|
"Load Mode Register 2, CWL=5", 512, 2, dfii_command_ras
|
||||||
("ZQ Calibration", 1024, 0, dfii_command_we|dfii_command_cs, 200),
|
| dfii_command_cas | dfii_command_we | dfii_command_cs, 0),
|
||||||
|
(
|
||||||
|
"Load Mode Register 3", 0, 3, dfii_command_ras | dfii_command_cas
|
||||||
|
| dfii_command_we | dfii_command_cs, 0),
|
||||||
|
(
|
||||||
|
"Load Mode Register 1", 6, 1, dfii_command_ras | dfii_command_cas
|
||||||
|
| dfii_command_we | dfii_command_cs, 0),
|
||||||
|
(
|
||||||
|
"Load Mode Register 0, CL=6, BL=8", 2336, 0, dfii_command_ras
|
||||||
|
| dfii_command_cas | dfii_command_we | dfii_command_cs, 200),
|
||||||
|
("ZQ Calibration", 1024, 0, dfii_command_we | dfii_command_cs, 200),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ wb.open()
|
||||||
# get identifier
|
# get identifier
|
||||||
fpga_id = ""
|
fpga_id = ""
|
||||||
for i in range(256):
|
for i in range(256):
|
||||||
c = chr(wb.read(wb.bases.identifier_mem + 4*i) & 0xff)
|
c = chr(wb.read(wb.bases.identifier_mem + 4 * i) & 0xff)
|
||||||
fpga_id += c
|
fpga_id += c
|
||||||
if c == "\0":
|
if c == "\0":
|
||||||
break
|
break
|
||||||
|
|
@ -38,41 +38,51 @@ for i, (comment, a, ba, cmd, delay) in enumerate(init_sequence):
|
||||||
# hardware control
|
# hardware control
|
||||||
wb.regs.sdram_dfii_control.write(dfii_control_sel)
|
wb.regs.sdram_dfii_control.write(dfii_control_sel)
|
||||||
|
|
||||||
|
|
||||||
def seed_to_data(seed, random=True):
|
def seed_to_data(seed, random=True):
|
||||||
if random:
|
if random:
|
||||||
return (1664525*seed + 1013904223) & 0xffffffff
|
return (1664525 * seed + 1013904223) & 0xffffffff
|
||||||
else:
|
else:
|
||||||
return seed
|
return seed
|
||||||
|
|
||||||
|
|
||||||
def write_pattern(length):
|
def write_pattern(length):
|
||||||
for i in range(length):
|
for i in range(length):
|
||||||
wb.write(wb.mems.main_ram.base + 4*i, seed_to_data(i))
|
wb.write(wb.mems.main_ram.base + 4 * i, seed_to_data(i))
|
||||||
|
|
||||||
|
|
||||||
def check_pattern(length, debug=False):
|
def check_pattern(length, debug=False):
|
||||||
errors = 0
|
errors = 0
|
||||||
for i in range(length):
|
for i in range(length):
|
||||||
error = 0
|
error = 0
|
||||||
if wb.read(wb.mems.main_ram.base + 4*i) != seed_to_data(i):
|
if wb.read(wb.mems.main_ram.base + 4 * i) != seed_to_data(i):
|
||||||
error = 1
|
error = 1
|
||||||
if debug:
|
if debug:
|
||||||
print("{}: 0x{:08x}, 0x{:08x} KO".format(i, wb.read(wb.mems.main_ram.base + 4*i), seed_to_data(i)))
|
print(
|
||||||
|
"{}: 0x{:08x}, 0x{:08x} KO".format(
|
||||||
|
i, wb.read(wb.mems.main_ram.base + 4 * i),
|
||||||
|
seed_to_data(i)))
|
||||||
else:
|
else:
|
||||||
if debug:
|
if debug:
|
||||||
print("{}: 0x{:08x}, 0x{:08x} OK".format(i, wb.read(wb.mems.main_ram.base + 4*i), seed_to_data(i)))
|
print(
|
||||||
|
"{}: 0x{:08x}, 0x{:08x} OK".format(
|
||||||
|
i, wb.read(wb.mems.main_ram.base + 4 * i),
|
||||||
|
seed_to_data(i)))
|
||||||
errors += error
|
errors += error
|
||||||
return errors
|
return errors
|
||||||
|
|
||||||
|
|
||||||
# find working bitslips and delays
|
# find working bitslips and delays
|
||||||
nbitslips = 8
|
nbitslips = 8
|
||||||
ndelays = 32
|
ndelays = 32
|
||||||
nmodules = 2
|
nmodules = 2
|
||||||
nwords = 16
|
nwords = 16
|
||||||
|
|
||||||
for bitslip in range(nbitslips):
|
for bitslip in range(nbitslips):
|
||||||
print("bitslip {:d}: |".format(bitslip), end="")
|
print("bitslip {:d}: |".format(bitslip), end="")
|
||||||
for delay in range(ndelays):
|
for delay in range(ndelays):
|
||||||
for module in range(nmodules):
|
for module in range(nmodules):
|
||||||
wb.regs.ddrphy_dly_sel.write(1<<module)
|
wb.regs.ddrphy_dly_sel.write(1 << module)
|
||||||
wb.regs.ddrphy_rdly_dq_rst.write(1)
|
wb.regs.ddrphy_rdly_dq_rst.write(1)
|
||||||
wb.regs.ddrphy_rdly_dq_bitslip_rst.write(1)
|
wb.regs.ddrphy_rdly_dq_bitslip_rst.write(1)
|
||||||
for i in range(bitslip):
|
for i in range(bitslip):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue