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-08-05 07:00:07 -04:00
|
|
|
# Note: For now with --toolchain=yosys+nextpnr:
|
|
|
|
# - DDR3 should be disabled: ex --integrated-main-ram-size=8192
|
|
|
|
# - Clk Freq should be lowered: ex --sys-clk-freq=50e6
|
2022-01-24 00:06:34 -05:00
|
|
|
|
2019-06-10 11:09:51 -04:00
|
|
|
from migen import *
|
|
|
|
|
2022-10-28 04:35:57 -04:00
|
|
|
from litex.gen import LiteXModule
|
2022-10-27 10:58:55 -04:00
|
|
|
|
2022-05-02 06:42:04 -04:00
|
|
|
from litex_boards.platforms import digilent_arty
|
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
|
2022-08-05 09:25:42 -04:00
|
|
|
from litex.soc.cores.gpio import GPIOIn, GPIOTristate
|
2022-08-05 07:00:07 -04:00
|
|
|
from litex.soc.cores.xadc import XADC
|
|
|
|
from litex.soc.cores.dna import DNA
|
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 ----------------------------------------------------------------------------------------------
|
|
|
|
|
2022-10-27 10:58:55 -04:00
|
|
|
class _CRG(LiteXModule):
|
2022-01-24 13:16:07 -05:00
|
|
|
def __init__(self, platform, sys_clk_freq, with_dram=True, with_rst=True):
|
2022-10-27 10:58:55 -04:00
|
|
|
self.rst = Signal()
|
|
|
|
self.cd_sys = ClockDomain()
|
|
|
|
self.cd_eth = ClockDomain()
|
2022-01-24 13:16:07 -05:00
|
|
|
if with_dram:
|
2022-10-27 10:58:55 -04:00
|
|
|
self.cd_sys4x = ClockDomain()
|
|
|
|
self.cd_sys4x_dqs = ClockDomain()
|
|
|
|
self.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.
|
2022-10-27 10:58:55 -04:00
|
|
|
self.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:
|
2022-10-27 10:58:55 -04:00
|
|
|
self.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):
|
2022-11-08 05:54:17 -05:00
|
|
|
def __init__(self, variant="a7-35", toolchain="vivado", sys_clk_freq=100e6,
|
2023-01-23 02:55:10 -05:00
|
|
|
with_xadc = False,
|
|
|
|
with_dna = False,
|
2022-08-05 07:00:07 -04:00
|
|
|
with_ethernet = False,
|
|
|
|
with_etherbone = False,
|
|
|
|
eth_ip = "192.168.1.50",
|
|
|
|
eth_dynamic_ip = False,
|
|
|
|
with_led_chaser = True,
|
|
|
|
with_jtagbone = True,
|
|
|
|
with_spi_flash = False,
|
2022-09-23 04:07:17 -04:00
|
|
|
with_buttons = False,
|
2022-08-05 07:00:07 -04:00
|
|
|
with_pmod_gpio = False,
|
|
|
|
**kwargs):
|
2022-05-02 06:42:04 -04:00
|
|
|
platform = digilent_arty.Platform(variant=variant, toolchain=toolchain)
|
2019-12-03 03:07:09 -05:00
|
|
|
|
|
|
|
# CRG --------------------------------------------------------------------------------------
|
2022-04-21 06:29:54 -04:00
|
|
|
with_dram = (kwargs.get("integrated_main_ram_size", 0) == 0)
|
2022-10-27 10:58:55 -04:00
|
|
|
self.crg = _CRG(platform, sys_clk_freq, with_dram)
|
2022-04-21 06:17:26 -04:00
|
|
|
|
|
|
|
# SoCCore ----------------------------------------------------------------------------------
|
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq, ident="LiteX SoC on Arty A7", **kwargs)
|
2019-06-10 11:09:51 -04:00
|
|
|
|
2022-08-05 07:00:07 -04:00
|
|
|
# XADC -------------------------------------------------------------------------------------
|
2023-01-23 02:55:10 -05:00
|
|
|
if with_xadc:
|
2023-01-06 17:09:56 -05:00
|
|
|
self.xadc = XADC()
|
2022-08-05 07:00:07 -04:00
|
|
|
|
|
|
|
# DNA --------------------------------------------------------------------------------------
|
2023-01-23 02:55:10 -05:00
|
|
|
if with_dna:
|
2023-01-06 17:09:56 -05:00
|
|
|
self.dna = DNA()
|
|
|
|
self.dna.add_timing_constraints(platform, sys_clk_freq, self.crg.cd_sys.clk)
|
2022-08-05 07:00:07 -04:00
|
|
|
|
2019-12-03 03:07:09 -05:00
|
|
|
# DDR3 SDRAM -------------------------------------------------------------------------------
|
|
|
|
if not self.integrated_main_ram_size:
|
2022-10-27 10:58:55 -04:00
|
|
|
self.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:
|
2022-10-27 10:58:55 -04:00
|
|
|
self.ethphy = LiteEthPHYMII(
|
2020-03-21 13:29:52 -04:00
|
|
|
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:
|
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"),
|
2022-08-05 07:00:07 -04:00
|
|
|
sys_clk_freq = sys_clk_freq,
|
|
|
|
)
|
2020-05-08 16:16:13 -04:00
|
|
|
|
2022-08-05 09:25:42 -04:00
|
|
|
# Buttons ----------------------------------------------------------------------------------
|
|
|
|
if with_buttons:
|
2022-10-27 10:58:55 -04:00
|
|
|
self.buttons = GPIOIn(
|
2022-08-24 09:17:06 -04:00
|
|
|
pads = platform.request_all("user_btn"),
|
|
|
|
with_irq = self.irq.enabled
|
|
|
|
)
|
2022-08-05 09:25:42 -04:00
|
|
|
|
2021-07-21 07:50:12 -04:00
|
|
|
# GPIOs ------------------------------------------------------------------------------------
|
|
|
|
if with_pmod_gpio:
|
2022-05-02 06:42:04 -04:00
|
|
|
platform.add_extension(digilent_arty.raw_pmod_io("pmoda"))
|
2022-10-27 10:58:55 -04:00
|
|
|
self.gpio = GPIOTristate(
|
2022-08-24 09:17:06 -04:00
|
|
|
pads = platform.request("pmoda"),
|
|
|
|
with_irq = self.irq.enabled
|
|
|
|
)
|
2021-07-21 07:50:12 -04:00
|
|
|
|
2019-06-10 11:09:51 -04:00
|
|
|
# Build --------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def main():
|
2022-11-06 15:39:52 -05:00
|
|
|
from litex.build.parser import LiteXArgumentParser
|
2022-11-08 04:41:35 -05:00
|
|
|
parser = LiteXArgumentParser(platform=digilent_arty.Platform, description="LiteX SoC on Arty A7.")
|
2022-11-08 05:54:17 -05:00
|
|
|
parser.add_target_argument("--flash", action="store_true", help="Flash bitstream.")
|
|
|
|
parser.add_target_argument("--variant", default="a7-35", help="Board variant (a7-35 or a7-100).")
|
2022-11-08 04:41:35 -05:00
|
|
|
parser.add_target_argument("--sys-clk-freq", default=100e6, type=float, help="System clock frequency.")
|
2023-01-23 02:55:10 -05:00
|
|
|
parser.add_target_argument("--with-xadc", action="store_true", help="Enable 7-Series XADC.")
|
|
|
|
parser.add_target_argument("--with-dna", action="store_true", help="Enable 7-Series DNA.")
|
2022-11-05 03:07:14 -04:00
|
|
|
ethopts = parser.target_group.add_mutually_exclusive_group()
|
2022-11-08 04:41:35 -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_target_argument("--eth-ip", default="192.168.1.50", help="Ethernet/Etherbone IP address.")
|
|
|
|
parser.add_target_argument("--eth-dynamic-ip", action="store_true", help="Enable dynamic Ethernet IP addresses setting.")
|
2022-11-05 03:07:14 -04:00
|
|
|
sdopts = parser.target_group.add_mutually_exclusive_group()
|
2022-11-08 04:41:35 -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_target_argument("--sdcard-adapter", help="SDCard PMOD adapter (digilent or numato).")
|
|
|
|
parser.add_target_argument("--with-jtagbone", action="store_true", help="Enable JTAGbone support.")
|
|
|
|
parser.add_target_argument("--with-spi-flash", action="store_true", help="Enable SPI Flash (MMAPed).")
|
|
|
|
parser.add_target_argument("--with-pmod-gpio", action="store_true", help="Enable GPIOs through PMOD.") # FIXME: Temporary test.
|
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,
|
2022-11-08 04:41:35 -05:00
|
|
|
sys_clk_freq = args.sys_clk_freq,
|
2023-01-23 02:55:10 -05:00
|
|
|
with_xadc = args.with_xadc,
|
|
|
|
with_dna = args.with_dna,
|
2021-07-28 05:21:51 -04:00
|
|
|
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,
|
2022-11-07 02:43:26 -05:00
|
|
|
**parser.soc_argdict
|
2020-11-12 12:07:28 -05:00
|
|
|
)
|
2021-02-25 03:33:27 -05:00
|
|
|
if args.sdcard_adapter == "numato":
|
2022-05-02 06:42:04 -04:00
|
|
|
soc.platform.add_extension(digilent_arty._numato_sdcard_pmod_io)
|
2021-02-23 23:22:43 -05:00
|
|
|
else:
|
2022-05-02 06:42:04 -04:00
|
|
|
soc.platform.add_extension(digilent_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
|
|
|
|
2022-11-05 03:07:14 -04:00
|
|
|
builder = Builder(soc, **parser.builder_argdict)
|
2022-05-06 09:14:32 -04:00
|
|
|
if args.build:
|
2022-11-05 03:07:14 -04:00
|
|
|
builder.build(**parser.toolchain_argdict)
|
2019-06-10 11:09:51 -04:00
|
|
|
|
2020-05-05 09:11:38 -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"))
|
2019-06-10 11:09:51 -04:00
|
|
|
|
2022-02-09 11:51:56 -05:00
|
|
|
if args.flash:
|
|
|
|
prog = soc.platform.create_programmer()
|
2022-03-17 04:21:05 -04:00
|
|
|
prog.flash(0, builder.get_bitstream_filename(mode="flash"))
|
2022-02-09 11:51:56 -05:00
|
|
|
|
2019-06-10 11:09:51 -04:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|