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>
|
2022-01-24 00:06:34 -05:00
|
|
|
# Copyright (c) 2022 Victor Suarez Rovere <suarezvictor@gmail.com>
|
2020-08-23 09:00:17 -04:00
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
2019-07-12 13:19:01 -04:00
|
|
|
|
2022-01-24 13:16:07 -05:00
|
|
|
# Note: For now, with --toolchain=yosys+nextpnr, DDR3 should be disabled and sys_clk_freq lowered, ex:
|
|
|
|
# python3 -m litex_boards.targets.digilent_arty.py --sys-clk-freq=50e6 --integrated-main-ram-size=8192 --toolchain=yosys+nextpnr --build
|
2022-01-24 00:06:34 -05: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
|
2021-07-21 07:50:12 -04:00
|
|
|
from litex.soc.cores.gpio import GPIOTristate
|
2019-06-10 11:09:51 -04:00
|
|
|
|
|
|
|
from litedram.modules import MT41K128M16
|
|
|
|
from litedram.phy import s7ddrphy
|
|
|
|
|
|
|
|
from liteeth.phy.mii import LiteEthPHYMII
|
|
|
|
|
|
|
|
# CRG ----------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class _CRG(Module):
|
2022-01-24 13:16:07 -05:00
|
|
|
def __init__(self, platform, sys_clk_freq, with_dram=True, with_rst=True):
|
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_eth = ClockDomain()
|
2022-01-24 13:16:07 -05:00
|
|
|
if with_dram:
|
|
|
|
self.clock_domains.cd_sys4x = ClockDomain(reset_less=True)
|
|
|
|
self.clock_domains.cd_sys4x_dqs = ClockDomain(reset_less=True)
|
|
|
|
self.clock_domains.cd_idelay = ClockDomain()
|
|
|
|
|
2019-06-10 11:09:51 -04:00
|
|
|
|
|
|
|
# # #
|
|
|
|
|
2022-01-24 13:16:07 -05:00
|
|
|
# Clk/Rst.
|
2022-01-07 08:11:52 -05:00
|
|
|
clk100 = platform.request("clk100")
|
|
|
|
rst = ~platform.request("cpu_reset") if with_rst else 0
|
|
|
|
|
2022-01-24 13:16:07 -05:00
|
|
|
# PLL.
|
2019-06-10 11:09:51 -04:00
|
|
|
self.submodules.pll = pll = S7PLL(speedgrade=-1)
|
2022-01-07 08:11:52 -05:00
|
|
|
self.comb += pll.reset.eq(rst | self.rst)
|
|
|
|
pll.register_clkin(clk100, 100e6)
|
2022-01-24 13:16:07 -05:00
|
|
|
pll.create_clkout(self.cd_sys, sys_clk_freq)
|
|
|
|
pll.create_clkout(self.cd_eth, 25e6)
|
|
|
|
self.comb += platform.request("eth_ref_clk").eq(self.cd_eth.clk)
|
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.
|
2022-01-24 13:16:07 -05:00
|
|
|
if with_dram:
|
|
|
|
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_idelay, 200e6)
|
2019-06-10 11:09:51 -04:00
|
|
|
|
2022-01-24 13:16:07 -05:00
|
|
|
# IdelayCtrl.
|
|
|
|
if with_dram:
|
|
|
|
self.submodules.idelayctrl = S7IDELAYCTRL(self.cd_idelay)
|
2019-06-10 11:09:51 -04:00
|
|
|
|
|
|
|
# BaseSoC ------------------------------------------------------------------------------------------
|
|
|
|
|
2020-03-21 07:43:39 -04:00
|
|
|
class BaseSoC(SoCCore):
|
2021-07-06 17:39:37 -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",
|
2022-01-18 10:47:38 -05:00
|
|
|
eth_dynamic_ip=False, with_led_chaser=True, with_jtagbone=True,
|
2021-07-28 05:21:51 -04:00
|
|
|
with_spi_flash=False, with_pmod_gpio=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,
|
2022-01-18 11:13:02 -05:00
|
|
|
ident = "LiteX SoC on Arty A7",
|
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 --------------------------------------------------------------------------------------
|
2022-01-24 13:16:07 -05:00
|
|
|
self.submodules.crg = _CRG(platform, sys_clk_freq, with_dram=not self.integrated_main_ram_size)
|
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-07-27 13:39:50 -04:00
|
|
|
# SPI Flash --------------------------------------------------------------------------------
|
2021-07-28 05:21:51 -04:00
|
|
|
if with_spi_flash:
|
2021-07-27 13:30:38 -04:00
|
|
|
from litespi.modules import S25FL128L
|
|
|
|
from litespi.opcodes import SpiNorFlashOpCodes as Codes
|
2021-09-07 09:04:38 -04:00
|
|
|
self.add_spi_flash(mode="4x", module=S25FL128L(Codes.READ_1_1_4), rate="1:2", with_master=True)
|
2021-04-25 14:42:02 -04:00
|
|
|
|
2020-05-08 16:16:13 -04:00
|
|
|
# Leds -------------------------------------------------------------------------------------
|
2021-07-06 17:39:37 -04:00
|
|
|
if with_led_chaser:
|
|
|
|
self.submodules.leds = LedChaser(
|
|
|
|
pads = platform.request_all("user_led"),
|
|
|
|
sys_clk_freq = sys_clk_freq)
|
2020-05-08 16:16:13 -04:00
|
|
|
|
2021-07-21 07:50:12 -04:00
|
|
|
# GPIOs ------------------------------------------------------------------------------------
|
|
|
|
if with_pmod_gpio:
|
|
|
|
platform.add_extension(arty.raw_pmod_io("pmoda"))
|
|
|
|
self.submodules.gpio = GPIOTristate(platform.request("pmoda"))
|
|
|
|
|
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")
|
2022-01-24 13:16:07 -05:00
|
|
|
parser.add_argument("--toolchain", default="vivado", help="FPGA toolchain (vivado, symbiflow or yosys+nextpnr).")
|
2022-01-05 11:06:22 -05:00
|
|
|
parser.add_argument("--build", action="store_true", help="Build bitstream.")
|
|
|
|
parser.add_argument("--load", action="store_true", help="Load bitstream.")
|
2022-02-09 11:51:56 -05:00
|
|
|
parser.add_argument("--flash", action="store_true", help="Flash bitstream.")
|
2022-01-05 11:06:22 -05:00
|
|
|
parser.add_argument("--variant", default="a7-35", help="Board variant (a7-35 or a7-100).")
|
|
|
|
parser.add_argument("--sys-clk-freq", default=100e6, help="System clock frequency.")
|
2021-01-29 20:08:38 -05:00
|
|
|
ethopts = parser.add_mutually_exclusive_group()
|
2022-01-05 11:06:22 -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()
|
2022-01-05 11:06:22 -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 or numato).")
|
|
|
|
parser.add_argument("--with-jtagbone", action="store_true", help="Enable JTAGbone support.")
|
|
|
|
parser.add_argument("--with-spi-flash", action="store_true", help="Enable SPI Flash (MMAPed).")
|
|
|
|
parser.add_argument("--with-pmod-gpio", action="store_true", help="Enable GPIOs through PMOD.") # FIXME: Temporary test.
|
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-07-28 05:21:51 -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,
|
|
|
|
with_jtagbone = args.with_jtagbone,
|
|
|
|
with_spi_flash = args.with_spi_flash,
|
|
|
|
with_pmod_gpio = args.with_pmod_gpio,
|
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()
|
2021-07-28 05:21:51 -04:00
|
|
|
|
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
|
|
|
|
2022-02-09 11:51:56 -05:00
|
|
|
if args.flash:
|
|
|
|
prog = soc.platform.create_programmer()
|
|
|
|
prog.flash(0, os.path.join(builder.gateware_dir, soc.build_name + ".bin"))
|
|
|
|
|
2019-06-10 11:09:51 -04:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|