2020-07-23 09:26:22 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2020-08-23 09:00:17 -04:00
|
|
|
#
|
|
|
|
# This file is part of LiteX-Boards.
|
|
|
|
#
|
2022-12-12 16:05:47 -05:00
|
|
|
# Copyright (c) 2019-2020 Florent Kermarrec <florent@enjoy-digital.fr>
|
|
|
|
# Copyright (c) 2022 Oliver Szabo <16oliver16@gmail.com>
|
2020-08-23 09:00:17 -04:00
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
2020-07-23 09:26:22 -04:00
|
|
|
|
|
|
|
from migen import *
|
|
|
|
|
2023-02-23 03:09:33 -05:00
|
|
|
from litex.gen import *
|
2022-10-27 10:58:55 -04:00
|
|
|
|
2022-05-02 06:42:04 -04:00
|
|
|
from litex_boards.platforms import digilent_zybo_z7
|
|
|
|
|
2020-07-23 11:45:21 -04:00
|
|
|
from litex.soc.interconnect import axi
|
|
|
|
from litex.soc.interconnect import wishbone
|
|
|
|
|
2020-07-23 09:26:22 -04:00
|
|
|
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
|
2022-11-23 11:20:25 -05:00
|
|
|
from litex.soc.integration.soc import SoCRegion
|
|
|
|
|
|
|
|
from litex.soc.cores import cpu
|
2020-07-23 09:26:22 -04:00
|
|
|
# CRG ----------------------------------------------------------------------------------------------
|
|
|
|
|
2022-10-27 10:58:55 -04:00
|
|
|
class _CRG(LiteXModule):
|
2020-07-23 11:45:21 -04:00
|
|
|
def __init__(self, platform, sys_clk_freq, use_ps7_clk=False):
|
2022-10-27 10:58:55 -04:00
|
|
|
self.rst = Signal()
|
|
|
|
self.cd_sys = ClockDomain()
|
2020-07-23 09:26:22 -04:00
|
|
|
# # #
|
|
|
|
|
2020-07-23 11:45:21 -04:00
|
|
|
if use_ps7_clk:
|
2022-11-23 11:20:25 -05:00
|
|
|
self.comb += ClockSignal("sys").eq(ClockSignal("ps7"))
|
|
|
|
self.comb += ResetSignal("sys").eq(ResetSignal("ps7") | self.rst)
|
2020-07-23 11:45:21 -04:00
|
|
|
else:
|
2022-11-23 11:20:25 -05:00
|
|
|
self.pll = pll = S7PLL(speedgrade=-1)
|
|
|
|
self.comb += pll.reset.eq(self.rst)
|
2020-07-23 11:45:21 -04:00
|
|
|
pll.register_clkin(platform.request("clk125"), 125e6)
|
2021-01-06 18:01:45 -05:00
|
|
|
pll.create_clkout(self.cd_sys, sys_clk_freq)
|
2021-01-07 02:00:40 -05:00
|
|
|
platform.add_false_path_constraints(self.cd_sys.clk, pll.clkin) # Ignore sys_clk to pll.clkin path created by SoC's rst.
|
2020-07-23 09:26:22 -04:00
|
|
|
|
|
|
|
# BaseSoC ------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class BaseSoC(SoCCore):
|
2022-11-23 11:20:25 -05:00
|
|
|
def __init__(self, sys_clk_freq=100e6, variant="z7-10", with_ps7=False, with_led_chaser=True, **kwargs):
|
2022-12-14 01:47:09 -05:00
|
|
|
platform = digilent_zybo_z7.Platform(variant=variant)
|
2022-11-23 11:20:25 -05:00
|
|
|
self.builder = None
|
2022-04-21 06:17:26 -04:00
|
|
|
# CRG --------------------------------------------------------------------------------------
|
2022-11-23 11:20:25 -05:00
|
|
|
use_ps7_clk = (kwargs.get("cpu_type", None) == "zynq7000")
|
|
|
|
self.crg = _CRG(platform, sys_clk_freq, use_ps7_clk)
|
2020-07-23 11:45:21 -04:00
|
|
|
|
|
|
|
# SoCCore ----------------------------------------------------------------------------------
|
2022-04-21 06:17:26 -04:00
|
|
|
if kwargs["uart_name"] == "serial":
|
|
|
|
kwargs["uart_name"] = "usb_uart" # Use USB-UART Pmod on JB.
|
2022-11-18 05:19:57 -05:00
|
|
|
if kwargs.get("cpu_type", None) == "zynq7000":
|
|
|
|
kwargs["integrated_sram_size"] = 0x0
|
|
|
|
kwargs["with_uart"] = False
|
|
|
|
self.mem_map = {
|
|
|
|
'csr': 0x4000_0000, # Zynq GP0 default
|
|
|
|
}
|
2022-12-12 16:05:47 -05:00
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq, ident="LiteX SoC on Zybo Z7/original Zybo", **kwargs)
|
2022-11-23 11:20:25 -05:00
|
|
|
|
2020-07-23 11:45:21 -04:00
|
|
|
# Zynq7000 Integration ---------------------------------------------------------------------
|
|
|
|
if kwargs.get("cpu_type", None) == "zynq7000":
|
2022-11-18 05:19:57 -05:00
|
|
|
self.cpu.use_rom = True
|
2022-12-12 16:05:47 -05:00
|
|
|
if variant in ["z7-20", "original"]:
|
2022-11-18 05:19:57 -05:00
|
|
|
# Get and set the pre-generated .xci FIXME: change location? add it to the repository? Make config
|
|
|
|
os.makedirs("xci", exist_ok=True)
|
|
|
|
os.system("wget https://github.com/litex-hub/litex-boards/files/8339591/zybo_z7_ps7.txt")
|
|
|
|
os.system("mv zybo_z7_ps7.txt xci/zybo_z7_ps7.xci")
|
|
|
|
self.cpu.set_ps7_xci("xci/zybo_z7_ps7.xci")
|
2022-11-23 11:20:25 -05:00
|
|
|
else:
|
2022-11-18 05:19:57 -05:00
|
|
|
self.cpu.set_ps7(name="ps", config = platform.ps7_config)
|
2020-07-23 11:45:21 -04:00
|
|
|
|
2022-11-18 05:19:57 -05:00
|
|
|
# Connect AXI GP0 to the SoC with base address of 0x40000000 (default one)
|
2020-07-23 11:45:21 -04:00
|
|
|
wb_gp0 = wishbone.Interface()
|
|
|
|
self.submodules += axi.AXI2Wishbone(
|
|
|
|
axi = self.cpu.add_axi_gp_master(),
|
|
|
|
wishbone = wb_gp0,
|
2022-11-18 05:19:57 -05:00
|
|
|
base_address = 0x40000000)
|
2022-04-21 09:32:19 -04:00
|
|
|
self.bus.add_master(master=wb_gp0)
|
2022-11-18 05:19:57 -05:00
|
|
|
#TODO memory size dependend on board variant
|
|
|
|
self.bus.add_region("sram", SoCRegion(
|
|
|
|
origin = self.cpu.mem_map["sram"],
|
|
|
|
size = 512 * 1024 * 1024 - self.cpu.mem_map["sram"])
|
|
|
|
)
|
|
|
|
self.bus.add_region("rom", SoCRegion(
|
|
|
|
origin = self.cpu.mem_map["rom"],
|
|
|
|
size = 256 * 1024 * 1024 // 8,
|
|
|
|
linker = True)
|
|
|
|
)
|
|
|
|
self.constants["CONFIG_CLOCK_FREQUENCY"] = 666666687
|
2022-11-23 11:20:25 -05:00
|
|
|
self.bus.add_region("flash", SoCRegion(
|
|
|
|
origin = 0xFC00_0000,
|
|
|
|
size = 0x4_0000,
|
|
|
|
mode = "rwx")
|
|
|
|
)
|
|
|
|
|
2022-11-18 05:19:57 -05:00
|
|
|
# PS7 as Slave Integration ---------------------------------------------------------------------
|
|
|
|
elif with_ps7:
|
2022-12-12 16:05:47 -05:00
|
|
|
if variant in ["z7-20", "original"]:
|
2022-11-23 11:20:25 -05:00
|
|
|
cpu_cls = cpu.CPUS["zynq7000"]
|
|
|
|
zynq = cpu_cls(self.platform, "standard") # zynq7000 has no variants
|
|
|
|
zynq.set_ps7(name="ps", config = platform.ps7_config)
|
|
|
|
axi_gp_slave0 = zynq.add_axi_gp_slave(clock_domain = self.crg.cd_sys.name)
|
|
|
|
self.submodules += zynq
|
|
|
|
self.bus.add_slave(
|
|
|
|
name="ps",slave=axi_gp_slave0,
|
|
|
|
region=SoCRegion(
|
|
|
|
origin=0x2000_0000,
|
|
|
|
size=0x2000_0000,
|
|
|
|
mode="rwx"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
#TODO: make config for zybo-z7-10
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2020-07-23 09:26:22 -04:00
|
|
|
# Leds -------------------------------------------------------------------------------------
|
2021-07-06 17:39:37 -04:00
|
|
|
if with_led_chaser:
|
2022-10-27 10:58:55 -04:00
|
|
|
self.leds = LedChaser(
|
2021-07-06 17:39:37 -04:00
|
|
|
pads = platform.request_all("user_led"),
|
|
|
|
sys_clk_freq = sys_clk_freq)
|
2020-07-23 09:26:22 -04:00
|
|
|
|
2022-11-18 05:19:57 -05:00
|
|
|
def finalize(self, *args, **kwargs):
|
|
|
|
super(BaseSoC, self).finalize(*args, **kwargs)
|
|
|
|
if self.cpu_type != "zynq7000":
|
|
|
|
return
|
|
|
|
libxil_path = os.path.join(self.builder.software_dir, 'libxil')
|
|
|
|
os.makedirs(os.path.realpath(libxil_path), exist_ok=True)
|
|
|
|
lib = os.path.join(libxil_path, 'embeddedsw')
|
|
|
|
if not os.path.exists(lib):
|
|
|
|
os.system("git clone --depth 1 https://github.com/Xilinx/embeddedsw {}".format(lib))
|
|
|
|
|
|
|
|
os.makedirs(os.path.realpath(self.builder.include_dir), exist_ok=True)
|
|
|
|
for header in [
|
|
|
|
'XilinxProcessorIPLib/drivers/uartps/src/xuartps_hw.h',
|
|
|
|
'lib/bsp/standalone/src/common/xil_types.h',
|
|
|
|
'lib/bsp/standalone/src/common/xil_assert.h',
|
|
|
|
'lib/bsp/standalone/src/common/xil_io.h',
|
|
|
|
'lib/bsp/standalone/src/common/xil_printf.h',
|
|
|
|
'lib/bsp/standalone/src/common/xstatus.h',
|
|
|
|
'lib/bsp/standalone/src/common/xdebug.h',
|
|
|
|
'lib/bsp/standalone/src/arm/cortexa9/xpseudo_asm.h',
|
|
|
|
'lib/bsp/standalone/src/arm/cortexa9/xreg_cortexa9.h',
|
|
|
|
'lib/bsp/standalone/src/arm/cortexa9/xil_cache.h',
|
|
|
|
'lib/bsp/standalone/src/arm/cortexa9/xparameters_ps.h',
|
|
|
|
'lib/bsp/standalone/src/arm/cortexa9/xil_errata.h',
|
|
|
|
'lib/bsp/standalone/src/arm/cortexa9/xtime_l.h',
|
|
|
|
'lib/bsp/standalone/src/arm/common/xil_exception.h',
|
|
|
|
'lib/bsp/standalone/src/arm/common/gcc/xpseudo_asm_gcc.h',
|
|
|
|
]:
|
|
|
|
shutil.copy(os.path.join(lib, header), self.builder.include_dir)
|
|
|
|
write_to_file(os.path.join(self.builder.include_dir, 'bspconfig.h'),
|
|
|
|
'#define FPU_HARD_FLOAT_ABI_ENABLED 1')
|
|
|
|
write_to_file(os.path.join(self.builder.include_dir, 'xparameters.h'), '''
|
|
|
|
#ifndef __XPARAMETERS_H
|
|
|
|
#define __XPARAMETERS_H
|
|
|
|
|
|
|
|
#include "xparameters_ps.h"
|
|
|
|
|
|
|
|
#define STDOUT_BASEADDRESS XPS_UART1_BASEADDR
|
|
|
|
#define XPAR_PS7_DDR_0_S_AXI_BASEADDR 0x00100000
|
|
|
|
#define XPAR_PS7_DDR_0_S_AXI_HIGHADDR 0x3FFFFFFF
|
|
|
|
#endif
|
|
|
|
''')
|
|
|
|
|
2020-07-23 09:26:22 -04:00
|
|
|
# Build --------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def main():
|
2022-11-23 11:20:25 -05:00
|
|
|
from litex.build.parser import LiteXArgumentParser
|
2022-12-12 16:05:47 -05:00
|
|
|
parser = LiteXArgumentParser(platform=digilent_zybo_z7.Platform, description="LiteX SoC on Zybo Z7/original Zybo")
|
2022-11-24 10:03:12 -05:00
|
|
|
parser.add_target_argument("--sys-clk-freq", default=125e6, type=float, help="System clock frequency.")
|
2022-12-12 16:05:47 -05:00
|
|
|
parser.add_target_argument("--variant", default="z7-10", help="Board variant (z7-10, z7-20 or original).")
|
2022-11-24 10:03:12 -05:00
|
|
|
parser.add_target_argument("--with-ps7", action="store_true", help="Add the PS7 as slave for soft CPUs.")
|
2020-07-23 09:26:22 -04:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2020-11-12 12:07:28 -05:00
|
|
|
soc = BaseSoC(
|
2022-11-23 11:20:25 -05:00
|
|
|
sys_clk_freq = args.sys_clk_freq,
|
2022-11-18 05:19:57 -05:00
|
|
|
variant = args.variant,
|
|
|
|
with_ps7 = args.with_ps7,
|
|
|
|
**soc_core_argdict(args)
|
2020-11-12 12:07:28 -05:00
|
|
|
)
|
2022-11-18 05:19:57 -05:00
|
|
|
builder = Builder(soc, **builder_argdict(args))
|
|
|
|
if args.cpu_type == "zynq7000":
|
|
|
|
soc.builder = builder
|
|
|
|
builder.add_software_package('libxil')
|
|
|
|
builder.add_software_library('libxil')
|
2022-05-06 09:14:32 -04:00
|
|
|
if args.build:
|
2022-11-05 03:07:14 -04:00
|
|
|
builder.build(**parser.toolchain_argdict)
|
2020-07-23 09:26:22 -04:00
|
|
|
if args.load:
|
|
|
|
prog = soc.platform.create_programmer()
|
2022-03-17 04:21:05 -04:00
|
|
|
prog.load_bitstream(builder.get_bitstream_filename(mode="sram"), device=1)
|
2020-07-23 09:26:22 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|