2019-06-10 11:09:51 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2020-08-23 09:00:17 -04:00
|
|
|
#
|
|
|
|
# This file is part of LiteX-Boards.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2015-2019 Florent Kermarrec <florent@enjoy-digital.fr>
|
2020-12-04 04:28:01 -05:00
|
|
|
# Copyright (c) 2020 Antmicro <www.antmicro.com>
|
2020-08-23 09:00:17 -04:00
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
2019-07-12 13:19:01 -04:00
|
|
|
|
2020-05-05 09:11:38 -04:00
|
|
|
import os
|
2019-06-10 11:09:51 -04:00
|
|
|
import argparse
|
|
|
|
|
|
|
|
from migen import *
|
|
|
|
|
2019-08-26 03:09:40 -04:00
|
|
|
from litex_boards.platforms import arty
|
2019-10-29 12:17:51 -04:00
|
|
|
from litex.build.xilinx.vivado import vivado_build_args, vivado_build_argdict
|
2019-06-10 11:09:51 -04:00
|
|
|
|
|
|
|
from litex.soc.cores.clock import *
|
2021-04-25 14:42:02 -04:00
|
|
|
from litex.soc.integration.soc import SoCRegion
|
2020-03-21 07:43:39 -04:00
|
|
|
from litex.soc.integration.soc_core import *
|
2019-06-10 11:09:51 -04:00
|
|
|
from litex.soc.integration.builder import *
|
2020-05-08 16:16:13 -04:00
|
|
|
from litex.soc.cores.led import LedChaser
|
2019-06-10 11:09:51 -04:00
|
|
|
|
|
|
|
from litedram.modules import MT41K128M16
|
|
|
|
from litedram.phy import s7ddrphy
|
|
|
|
|
|
|
|
from liteeth.phy.mii import LiteEthPHYMII
|
|
|
|
|
2021-04-26 10:26:19 -04:00
|
|
|
from litespi.modules import S25FL128L
|
2021-04-25 14:42:02 -04:00
|
|
|
from litespi.opcodes import SpiNorFlashOpCodes as Codes
|
|
|
|
from litespi.phy.generic import LiteSPIPHY
|
|
|
|
from litespi import LiteSPI
|
|
|
|
|
2019-06-10 11:09:51 -04:00
|
|
|
# CRG ----------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class _CRG(Module):
|
2021-04-26 06:51:11 -04:00
|
|
|
def __init__(self, platform, sys_clk_freq, with_mapped_flash):
|
2020-11-04 05:09:30 -05:00
|
|
|
self.rst = Signal()
|
2019-12-03 03:07:09 -05:00
|
|
|
self.clock_domains.cd_sys = ClockDomain()
|
|
|
|
self.clock_domains.cd_sys4x = ClockDomain(reset_less=True)
|
2019-06-10 11:09:51 -04:00
|
|
|
self.clock_domains.cd_sys4x_dqs = ClockDomain(reset_less=True)
|
2020-10-13 06:10:29 -04:00
|
|
|
self.clock_domains.cd_idelay = ClockDomain()
|
2019-12-03 03:07:09 -05:00
|
|
|
self.clock_domains.cd_eth = ClockDomain()
|
2019-06-10 11:09:51 -04:00
|
|
|
|
|
|
|
# # #
|
|
|
|
|
|
|
|
self.submodules.pll = pll = S7PLL(speedgrade=-1)
|
2020-11-04 05:09:30 -05:00
|
|
|
self.comb += pll.reset.eq(~platform.request("cpu_reset") | self.rst)
|
2019-06-10 11:09:51 -04:00
|
|
|
pll.register_clkin(platform.request("clk100"), 100e6)
|
2019-12-03 03:07:09 -05:00
|
|
|
pll.create_clkout(self.cd_sys, sys_clk_freq)
|
|
|
|
pll.create_clkout(self.cd_sys4x, 4*sys_clk_freq)
|
2019-06-10 11:09:51 -04:00
|
|
|
pll.create_clkout(self.cd_sys4x_dqs, 4*sys_clk_freq, phase=90)
|
2020-10-13 06:10:29 -04:00
|
|
|
pll.create_clkout(self.cd_idelay, 200e6)
|
2019-12-03 03:07:09 -05:00
|
|
|
pll.create_clkout(self.cd_eth, 25e6)
|
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.
|
2019-06-10 11:09:51 -04:00
|
|
|
|
2020-10-13 06:10:29 -04:00
|
|
|
self.submodules.idelayctrl = S7IDELAYCTRL(self.cd_idelay)
|
2019-06-10 11:09:51 -04:00
|
|
|
|
|
|
|
self.comb += platform.request("eth_ref_clk").eq(self.cd_eth.clk)
|
|
|
|
|
|
|
|
# BaseSoC ------------------------------------------------------------------------------------------
|
|
|
|
|
2020-03-21 07:43:39 -04:00
|
|
|
class BaseSoC(SoCCore):
|
2021-04-25 14:42:02 -04:00
|
|
|
def __init__(self, variant="a7-35", toolchain="vivado", sys_clk_freq=int(100e6), with_ethernet=False, with_etherbone=False, eth_ip="192.168.1.50", eth_dynamic_ip=False, ident_version=True, with_jtagbone=True, with_mapped_flash=False, **kwargs):
|
2020-12-29 12:41:58 -05:00
|
|
|
platform = arty.Platform(variant=variant, toolchain=toolchain)
|
2019-12-03 03:07:09 -05:00
|
|
|
|
2020-03-21 07:43:39 -04:00
|
|
|
# SoCCore ----------------------------------------------------------------------------------
|
2020-06-30 12:11:04 -04:00
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq,
|
|
|
|
ident = "LiteX SoC on Arty A7",
|
2020-12-04 04:28:01 -05:00
|
|
|
ident_version = ident_version,
|
2020-06-30 12:11:04 -04:00
|
|
|
**kwargs)
|
2019-06-10 11:09:51 -04:00
|
|
|
|
2019-12-03 03:07:09 -05:00
|
|
|
# CRG --------------------------------------------------------------------------------------
|
2021-04-26 06:51:11 -04:00
|
|
|
self.submodules.crg = _CRG(platform, sys_clk_freq, with_mapped_flash)
|
2019-06-10 11:09:51 -04:00
|
|
|
|
2019-12-03 03:07:09 -05:00
|
|
|
# DDR3 SDRAM -------------------------------------------------------------------------------
|
|
|
|
if not self.integrated_main_ram_size:
|
|
|
|
self.submodules.ddrphy = s7ddrphy.A7DDRPHY(platform.request("ddram"),
|
2020-03-20 13:59:17 -04:00
|
|
|
memtype = "DDR3",
|
|
|
|
nphases = 4,
|
2020-06-25 05:21:24 -04:00
|
|
|
sys_clk_freq = sys_clk_freq)
|
2020-03-21 07:43:39 -04:00
|
|
|
self.add_sdram("sdram",
|
2021-03-29 09:28:04 -04:00
|
|
|
phy = self.ddrphy,
|
|
|
|
module = MT41K128M16(sys_clk_freq, "1:4"),
|
|
|
|
l2_cache_size = kwargs.get("l2_size", 8192)
|
2020-03-21 07:43:39 -04:00
|
|
|
)
|
2019-06-10 11:09:51 -04:00
|
|
|
|
2020-05-29 13:20:27 -04:00
|
|
|
# Ethernet / Etherbone ---------------------------------------------------------------------
|
|
|
|
if with_ethernet or with_etherbone:
|
2020-03-21 13:29:52 -04:00
|
|
|
self.submodules.ethphy = LiteEthPHYMII(
|
|
|
|
clock_pads = self.platform.request("eth_clocks"),
|
|
|
|
pads = self.platform.request("eth"))
|
2020-05-29 13:20:27 -04:00
|
|
|
if with_ethernet:
|
2021-02-25 03:33:27 -05:00
|
|
|
self.add_ethernet(phy=self.ethphy, dynamic_ip=eth_dynamic_ip)
|
2020-05-29 13:20:27 -04:00
|
|
|
if with_etherbone:
|
2021-01-07 18:44:15 -05:00
|
|
|
self.add_etherbone(phy=self.ethphy, ip_address=eth_ip)
|
2020-01-16 04:28:09 -05:00
|
|
|
|
2021-03-07 16:50:58 -05:00
|
|
|
# Jtagbone ---------------------------------------------------------------------------------
|
|
|
|
if with_jtagbone:
|
|
|
|
self.add_jtagbone()
|
|
|
|
|
2021-04-26 10:26:19 -04:00
|
|
|
# Flash (through LiteSPI, experimental).
|
2021-04-25 14:42:02 -04:00
|
|
|
if with_mapped_flash:
|
2021-04-26 10:26:19 -04:00
|
|
|
self.submodules.spiflash_phy = LiteSPIPHY(platform.request("spiflash4x"), S25FL128L(Codes.READ_1_1_4))
|
|
|
|
self.submodules.spiflash_mmap = LiteSPI(self.spiflash_phy, clk_freq=sys_clk_freq, mmap_endianness=self.cpu.endianness)
|
|
|
|
spiflash_region = SoCRegion(origin=self.mem_map.get("spiflash", None), size=S25FL128L.total_size, cached=False)
|
2021-04-25 14:42:02 -04:00
|
|
|
self.bus.add_slave(name="spiflash", slave=self.spiflash_mmap.bus, region=spiflash_region)
|
|
|
|
|
2020-05-08 16:16:13 -04:00
|
|
|
# Leds -------------------------------------------------------------------------------------
|
|
|
|
self.submodules.leds = LedChaser(
|
2020-08-06 14:04:03 -04:00
|
|
|
pads = platform.request_all("user_led"),
|
2020-05-08 16:16:13 -04:00
|
|
|
sys_clk_freq = sys_clk_freq)
|
|
|
|
|
2019-06-10 11:09:51 -04:00
|
|
|
# Build --------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def main():
|
2020-05-05 09:11:38 -04:00
|
|
|
parser = argparse.ArgumentParser(description="LiteX SoC on Arty A7")
|
2021-02-25 03:33:27 -05:00
|
|
|
parser.add_argument("--toolchain", default="vivado", help="Toolchain use to build (default: vivado)")
|
|
|
|
parser.add_argument("--build", action="store_true", help="Build bitstream")
|
|
|
|
parser.add_argument("--load", action="store_true", help="Load bitstream")
|
|
|
|
parser.add_argument("--variant", default="a7-35", help="Board variant: a7-35 (default) or a7-100")
|
|
|
|
parser.add_argument("--sys-clk-freq", default=100e6, help="System clock frequency (default: 100MHz)")
|
2021-01-29 20:08:38 -05:00
|
|
|
ethopts = parser.add_mutually_exclusive_group()
|
2021-02-25 03:33:27 -05:00
|
|
|
ethopts.add_argument("--with-ethernet", action="store_true", help="Enable Ethernet support")
|
|
|
|
ethopts.add_argument("--with-etherbone", action="store_true", help="Enable Etherbone support")
|
|
|
|
parser.add_argument("--eth-ip", default="192.168.1.50", type=str, help="Ethernet/Etherbone IP address")
|
|
|
|
parser.add_argument("--eth-dynamic-ip", action="store_true", help="Enable dynamic Ethernet IP addresses setting")
|
2021-01-29 20:08:38 -05:00
|
|
|
sdopts = parser.add_mutually_exclusive_group()
|
2021-02-25 03:33:27 -05:00
|
|
|
sdopts.add_argument("--with-spi-sdcard", action="store_true", help="Enable SPI-mode SDCard support")
|
|
|
|
sdopts.add_argument("--with-sdcard", action="store_true", help="Enable SDCard support")
|
|
|
|
parser.add_argument("--sdcard-adapter", type=str, help="SDCard PMOD adapter: digilent (default) or numato")
|
|
|
|
parser.add_argument("--no-ident-version", action="store_false", help="Disable build time output")
|
2021-04-26 10:26:19 -04:00
|
|
|
parser.add_argument("--with-jtagbone", action="store_true", help="Enable Jtagbone support")
|
|
|
|
parser.add_argument("--with-mapped-flash", action="store_true", help="Enable Memory Mapped Flash")
|
2020-11-12 05:46:00 -05:00
|
|
|
builder_args(parser)
|
2021-03-24 10:01:23 -04:00
|
|
|
soc_core_args(parser)
|
2020-11-12 05:46:00 -05:00
|
|
|
vivado_build_args(parser)
|
2019-06-10 11:09:51 -04:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2021-02-25 03:33:27 -05:00
|
|
|
assert not (args.with_etherbone and args.eth_dynamic_ip)
|
|
|
|
|
2020-11-12 12:07:28 -05:00
|
|
|
soc = BaseSoC(
|
2021-04-26 10:26:19 -04:00
|
|
|
variant = args.variant,
|
|
|
|
toolchain = args.toolchain,
|
|
|
|
sys_clk_freq = int(float(args.sys_clk_freq)),
|
|
|
|
with_ethernet = args.with_ethernet,
|
|
|
|
with_etherbone = args.with_etherbone,
|
|
|
|
eth_ip = args.eth_ip,
|
|
|
|
eth_dynamic_ip = args.eth_dynamic_ip,
|
|
|
|
ident_version = args.no_ident_version,
|
|
|
|
with_jtagbone = args.with_jtagbone,
|
2021-04-25 14:42:02 -04:00
|
|
|
with_mapped_flash = args.with_mapped_flash,
|
2021-03-24 10:01:23 -04:00
|
|
|
**soc_core_argdict(args)
|
2020-11-12 12:07:28 -05:00
|
|
|
)
|
2021-02-25 03:33:27 -05:00
|
|
|
if args.sdcard_adapter == "numato":
|
2021-02-23 23:22:43 -05:00
|
|
|
soc.platform.add_extension(arty._numato_sdcard_pmod_io)
|
|
|
|
else:
|
|
|
|
soc.platform.add_extension(arty._sdcard_pmod_io)
|
2020-07-24 10:29:35 -04:00
|
|
|
if args.with_spi_sdcard:
|
|
|
|
soc.add_spi_sdcard()
|
|
|
|
if args.with_sdcard:
|
|
|
|
soc.add_sdcard()
|
2019-06-10 11:09:51 -04:00
|
|
|
builder = Builder(soc, **builder_argdict(args))
|
2020-12-04 04:28:01 -05:00
|
|
|
builder_kwargs = vivado_build_argdict(args) if args.toolchain == "vivado" else {}
|
|
|
|
builder.build(**builder_kwargs, run=args.build)
|
2019-06-10 11:09:51 -04:00
|
|
|
|
2020-05-05 09:11:38 -04:00
|
|
|
if args.load:
|
|
|
|
prog = soc.platform.create_programmer()
|
2020-05-21 03:12:29 -04:00
|
|
|
prog.load_bitstream(os.path.join(builder.gateware_dir, soc.build_name + ".bit"))
|
2019-06-10 11:09:51 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|