2020-08-24 10:44:14 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
#
|
|
|
|
# This file is part of LiteX-Boards.
|
|
|
|
#
|
2020-08-24 16:33:58 -04:00
|
|
|
# Copyright (c) 2020 David Corrigan <davidcorrigan714@gmail.com>
|
2020-08-24 10:44:14 -04:00
|
|
|
# Copyright (c) 2020 Alan Green <avg@google.com>
|
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
|
|
import os
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
from migen import *
|
|
|
|
from migen.genlib.resetsync import AsyncResetSynchronizer
|
|
|
|
|
|
|
|
from litex_boards.platforms import crosslink_nx_evn
|
|
|
|
|
2020-11-09 05:05:18 -05:00
|
|
|
from litex.soc.cores.ram import NXLRAM
|
2020-11-09 04:25:30 -05:00
|
|
|
from litex.soc.cores.clock import NXPLL
|
2020-08-24 10:44:14 -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 *
|
|
|
|
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-08-24 10:44:14 -04:00
|
|
|
kB = 1024
|
|
|
|
mB = 1024*kB
|
|
|
|
|
|
|
|
|
|
|
|
# CRG ----------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class _CRG(Module):
|
|
|
|
def __init__(self, platform, sys_clk_freq):
|
|
|
|
self.clock_domains.cd_por = ClockDomain()
|
2020-11-08 21:34:46 -05:00
|
|
|
self.clock_domains.cd_sys = ClockDomain()
|
2020-08-24 10:44:14 -04:00
|
|
|
|
2020-11-08 21:34:46 -05:00
|
|
|
# Built in OSC
|
|
|
|
self.submodules.hf_clk = NXOSCA()
|
|
|
|
hf_clk_freq = 25e6
|
|
|
|
self.hf_clk.create_hf_clk(self.cd_por, hf_clk_freq)
|
|
|
|
|
|
|
|
# Power on reset
|
|
|
|
por_count = Signal(16, reset=2**16-1)
|
|
|
|
por_done = Signal()
|
|
|
|
self.comb += por_done.eq(por_count == 0)
|
|
|
|
self.sync.por += If(~por_done, por_count.eq(por_count - 1))
|
|
|
|
|
|
|
|
self.rst_n = platform.request("gsrn")
|
|
|
|
self.specials += AsyncResetSynchronizer(self.cd_por, ~self.rst_n)
|
|
|
|
|
|
|
|
# PLL
|
|
|
|
self.submodules.sys_pll = sys_pll = NXPLL(platform=platform, create_output_port_clocks=True)
|
|
|
|
sys_pll.register_clkin(self.cd_por.clk, hf_clk_freq)
|
|
|
|
sys_pll.create_clkout(self.cd_sys, sys_clk_freq)
|
|
|
|
self.specials += AsyncResetSynchronizer(self.cd_sys, ~self.sys_pll.locked | ~por_done )
|
2020-08-24 10:44:14 -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-08-24 10:44:14 -04:00
|
|
|
}
|
2021-07-06 17:39:37 -04:00
|
|
|
def __init__(self, sys_clk_freq=int(75e6), toolchain="radiant", with_led_chaser=True, **kwargs):
|
2020-11-25 04:45:25 -05:00
|
|
|
platform = crosslink_nx_evn.Platform(toolchain=toolchain)
|
2020-08-24 10:44:14 -04:00
|
|
|
platform.add_platform_command("ldc_set_sysconfig {{MASTER_SPI_PORT=SERIAL}}")
|
|
|
|
|
|
|
|
# Disable Integrated SRAM since we want to instantiate LRAM specifically for it
|
|
|
|
kwargs["integrated_sram_size"] = 0
|
|
|
|
|
|
|
|
# Make serial_pmods available
|
|
|
|
platform.add_extension(crosslink_nx_evn.serial_pmods)
|
|
|
|
|
|
|
|
# SoCCore -----------------------------------------_----------------------------------------
|
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq,
|
2020-11-12 12:07:28 -05:00
|
|
|
ident = "LiteX SoC on Crosslink-NX Evaluation Board",
|
|
|
|
ident_version = True,
|
2020-08-24 10:44:14 -04:00
|
|
|
**kwargs)
|
|
|
|
|
|
|
|
# CRG --------------------------------------------------------------------------------------
|
|
|
|
self.submodules.crg = _CRG(platform, sys_clk_freq)
|
|
|
|
|
|
|
|
# 128KB LRAM (used as SRAM) ---------------------------------------------------------------
|
|
|
|
size = 128*kB
|
|
|
|
self.submodules.spram = NXLRAM(32, size)
|
|
|
|
self.register_mem("sram", self.mem_map["sram"], self.spram.bus, size)
|
|
|
|
|
|
|
|
# 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(14)]),
|
|
|
|
sys_clk_freq = sys_clk_freq)
|
2020-08-24 10:44:14 -04:00
|
|
|
|
|
|
|
# Build --------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description="LiteX SoC on Crosslink-NX Eval Board")
|
2020-11-12 05:46:00 -05:00
|
|
|
parser.add_argument("--build", action="store_true", help="Build bitstream")
|
|
|
|
parser.add_argument("--load", action="store_true", help="Load bitstream")
|
2020-11-25 04:45:25 -05:00
|
|
|
parser.add_argument("--toolchain", default="radiant", help="FPGA toolchain: radiant (default) or prjoxide")
|
2020-11-12 05:46:00 -05:00
|
|
|
parser.add_argument("--sys-clk-freq", default=75e6, help="System clock frequency (default: 75MHz)")
|
|
|
|
parser.add_argument("--serial", default="serial", help="UART Pins: serial (default, requires R15 and R17 to be soldered) or serial_pmod[0-2]")
|
|
|
|
parser.add_argument("--prog-target", default="direct", help="Programming Target: direct or flash")
|
2020-08-24 10:44:14 -04:00
|
|
|
builder_args(parser)
|
|
|
|
soc_core_args(parser)
|
2020-11-25 04:45:25 -05:00
|
|
|
oxide_args(parser)
|
2020-08-24 10:44:14 -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)),
|
2020-11-25 04:45:25 -05:00
|
|
|
toolchain = args.toolchain,
|
2020-11-12 12:07:28 -05:00
|
|
|
**soc_core_argdict(args)
|
|
|
|
)
|
2020-08-24 10:44:14 -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 {}
|
2020-08-24 10:44:14 -04:00
|
|
|
builder.build(**builder_kargs, run=args.build)
|
|
|
|
|
|
|
|
if args.load:
|
|
|
|
prog = soc.platform.create_programmer(args.prog_target)
|
|
|
|
prog.load_bitstream(os.path.join(builder.gateware_dir, soc.build_name + ".bit"))
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|