2020-10-13 06:10:36 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
#
|
|
|
|
# This file is part of LiteX-Boards.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2020 David Corrigan <davidcorrigan714@gmail.com>
|
|
|
|
# Copyright (c) 2020 Alan Green <avg@google.com>
|
|
|
|
# Copyright (c) 2020 David Shah <dave@ds0.me>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
|
|
from migen import *
|
|
|
|
from migen.genlib.resetsync import AsyncResetSynchronizer
|
|
|
|
|
2022-05-02 06:42:04 -04:00
|
|
|
from litex_boards.platforms import lattice_crosslink_nx_vip
|
2020-10-21 09:08:32 -04:00
|
|
|
|
2022-03-01 03:10:19 -05:00
|
|
|
from litex.soc.cores.hyperbus import HyperRAM
|
2020-10-21 09:08:32 -04:00
|
|
|
|
2020-11-09 05:05:18 -05:00
|
|
|
from litex.soc.cores.ram import NXLRAM
|
2020-10-13 06:10:36 -04:00
|
|
|
from litex.build.io import CRG
|
|
|
|
from litex.build.generic_platform import *
|
|
|
|
|
|
|
|
from litex.soc.cores.clock import *
|
|
|
|
from litex.soc.integration.soc_core import *
|
2021-11-08 10:39:49 -05:00
|
|
|
from litex.soc.integration.soc import SoCRegion
|
2020-10-13 06:10:36 -04:00
|
|
|
from litex.soc.integration.builder import *
|
|
|
|
from litex.soc.cores.led import LedChaser
|
|
|
|
|
2020-11-25 04:45:25 -05:00
|
|
|
from litex.build.lattice.oxide import oxide_args, oxide_argdict
|
|
|
|
|
2020-10-13 06:10:36 -04:00
|
|
|
kB = 1024
|
|
|
|
mB = 1024*kB
|
|
|
|
|
|
|
|
|
|
|
|
# CRG ----------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class _CRG(Module):
|
|
|
|
def __init__(self, platform, sys_clk_freq):
|
2020-11-04 05:09:30 -05:00
|
|
|
self.rst = Signal()
|
2020-10-13 06:10:36 -04:00
|
|
|
self.clock_domains.cd_sys = ClockDomain()
|
|
|
|
self.clock_domains.cd_por = ClockDomain()
|
|
|
|
|
|
|
|
# TODO: replace with PLL
|
|
|
|
# Clocking
|
|
|
|
self.submodules.sys_clk = sys_osc = NXOSCA()
|
|
|
|
sys_osc.create_hf_clk(self.cd_sys, sys_clk_freq)
|
|
|
|
platform.add_period_constraint(self.cd_sys.clk, 1e9/sys_clk_freq)
|
|
|
|
rst_n = platform.request("gsrn")
|
|
|
|
|
|
|
|
# Power On Reset
|
|
|
|
por_cycles = 4096
|
|
|
|
por_counter = Signal(log2_int(por_cycles), reset=por_cycles-1)
|
|
|
|
self.comb += self.cd_por.clk.eq(self.cd_sys.clk)
|
|
|
|
self.sync.por += If(por_counter != 0, por_counter.eq(por_counter - 1))
|
|
|
|
self.specials += AsyncResetSynchronizer(self.cd_por, ~rst_n)
|
2020-11-04 05:09:30 -05:00
|
|
|
self.specials += AsyncResetSynchronizer(self.cd_sys, (por_counter != 0) | self.rst)
|
2020-10-13 06:10:36 -04:00
|
|
|
|
|
|
|
|
|
|
|
# BaseSoC ------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class BaseSoC(SoCCore):
|
2021-03-25 17:38:11 -04:00
|
|
|
mem_map = {
|
2021-03-29 09:28:04 -04:00
|
|
|
"rom": 0x00000000,
|
|
|
|
"sram": 0x40000000,
|
|
|
|
"csr": 0xf0000000,
|
2020-10-13 06:10:36 -04:00
|
|
|
}
|
2021-07-06 17:39:37 -04:00
|
|
|
def __init__(self, sys_clk_freq=int(75e6), hyperram="none", toolchain="radiant",
|
|
|
|
with_led_chaser=True, **kwargs):
|
2022-05-02 06:42:04 -04:00
|
|
|
platform = lattice_crosslink_nx_vip.Platform(toolchain=toolchain)
|
2020-10-13 06:10:36 -04:00
|
|
|
platform.add_platform_command("ldc_set_sysconfig {{MASTER_SPI_PORT=SERIAL}}")
|
|
|
|
|
|
|
|
# CRG --------------------------------------------------------------------------------------
|
|
|
|
self.submodules.crg = _CRG(platform, sys_clk_freq)
|
|
|
|
|
2022-04-21 06:17:26 -04:00
|
|
|
# SoCCore -----------------------------------------_----------------------------------------
|
|
|
|
# Disable Integrated SRAM since we want to instantiate LRAM specifically for it
|
|
|
|
kwargs["integrated_sram_size"] = 0
|
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq, ident="LiteX SoC on Crosslink-NX VIP Input Board", **kwargs)
|
|
|
|
|
|
|
|
# SRAM/HyperRAM ----------------------------------------------------------------------------
|
2020-10-21 09:08:32 -04:00
|
|
|
if hyperram == "none":
|
|
|
|
# 128KB LRAM (used as SRAM) ------------------------------------------------------------
|
|
|
|
size = 128*kB
|
|
|
|
self.submodules.spram = NXLRAM(32, size)
|
2021-11-08 10:39:49 -05:00
|
|
|
self.bus.add_slave("sram", slave=self.spram.bus, region=SoCRegion(size=size))
|
2020-10-21 09:08:32 -04:00
|
|
|
else:
|
|
|
|
# Use HyperRAM generic PHY as SRAM -----------------------------------------------------
|
|
|
|
size = 8*1024*kB
|
|
|
|
hr_pads = platform.request("hyperram", int(hyperram))
|
2022-05-02 10:43:52 -04:00
|
|
|
self.submodules.hyperram = HyperRAM(hr_pads, sys_clk_freq=sys_clk_freq)
|
2021-11-08 10:39:49 -05:00
|
|
|
self.bus.add_slave("sram", slave=self.hyperram.bus, region=SoCRegion(size=size))
|
2020-10-13 06:10:36 -04:00
|
|
|
|
|
|
|
# Leds -------------------------------------------------------------------------------------
|
2021-07-06 17:39:37 -04:00
|
|
|
if with_led_chaser:
|
|
|
|
self.submodules.leds = LedChaser(
|
|
|
|
pads = Cat(*[platform.request("user_led", i) for i in range(4)]),
|
|
|
|
sys_clk_freq = sys_clk_freq)
|
2020-10-13 06:10:36 -04:00
|
|
|
|
|
|
|
# Build --------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def main():
|
2022-03-21 11:59:40 -04:00
|
|
|
from litex.soc.integration.soc import LiteXSoCArgumentParser
|
|
|
|
parser = LiteXSoCArgumentParser(description="LiteX SoC on Crosslink-NX VIP Board")
|
2022-03-21 13:30:10 -04:00
|
|
|
target_group = parser.add_argument_group(title="Target options")
|
2022-05-06 09:14:32 -04:00
|
|
|
target_group.add_argument("--build", action="store_true", help="Build design.")
|
2022-03-21 13:30:10 -04:00
|
|
|
target_group.add_argument("--load", action="store_true", help="Load bitstream.")
|
|
|
|
target_group.add_argument("--toolchain", default="radiant", help="FPGA toolchain (radiant or prjoxide).")
|
|
|
|
target_group.add_argument("--sys-clk-freq", default=75e6, help="System clock frequency.")
|
|
|
|
target_group.add_argument("--with-hyperram", default="none", help="Enable use of HyperRAM chip (none, 0 or 1).")
|
|
|
|
target_group.add_argument("--prog-target", default="direct", help="Programming Target (direct or flash).")
|
2020-10-13 06:10:36 -04:00
|
|
|
builder_args(parser)
|
|
|
|
soc_core_args(parser)
|
2020-11-25 04:45:25 -05:00
|
|
|
oxide_args(parser)
|
2020-10-13 06:10:36 -04:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2020-11-12 12:07:28 -05:00
|
|
|
soc = BaseSoC(
|
|
|
|
sys_clk_freq = int(float(args.sys_clk_freq)),
|
|
|
|
hyperram = args.with_hyperram,
|
2020-11-25 04:45:25 -05:00
|
|
|
toolchain = args.toolchain,
|
2020-11-12 12:07:28 -05:00
|
|
|
**soc_core_argdict(args)
|
|
|
|
)
|
2020-10-13 06:10:36 -04:00
|
|
|
builder = Builder(soc, **builder_argdict(args))
|
2020-11-25 04:45:25 -05:00
|
|
|
builder_kargs = oxide_argdict(args) if args.toolchain == "oxide" else {}
|
2022-05-06 09:14:32 -04:00
|
|
|
if args.build:
|
|
|
|
builder.build(**builder_kargs)
|
2020-10-13 06:10:36 -04:00
|
|
|
|
|
|
|
if args.load:
|
|
|
|
prog = soc.platform.create_programmer(args.prog_target)
|
2022-03-17 04:21:05 -04:00
|
|
|
prog.load_bitstream(builder.get_bitstream_filename(mode="sram"))
|
2020-10-13 06:10:36 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|