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
|
|
|
|
|
|
|
|
from migen import *
|
|
|
|
from migen.genlib.resetsync import AsyncResetSynchronizer
|
|
|
|
|
2023-02-23 03:09:33 -05:00
|
|
|
from litex.gen import *
|
2022-10-27 10:58:55 -04:00
|
|
|
|
2022-05-02 06:42:04 -04:00
|
|
|
from litex_boards.platforms import lattice_crosslink_nx_evn
|
2020-08-24 10:44:14 -04:00
|
|
|
|
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 *
|
2023-08-09 12:05:22 -04:00
|
|
|
from litex.soc.integration.soc import SoCRegion
|
2020-08-24 10:44:14 -04:00
|
|
|
from litex.soc.integration.builder import *
|
|
|
|
from litex.soc.cores.led import LedChaser
|
|
|
|
|
|
|
|
kB = 1024
|
|
|
|
mB = 1024*kB
|
|
|
|
|
|
|
|
|
|
|
|
# CRG ----------------------------------------------------------------------------------------------
|
|
|
|
|
2022-10-27 10:58:55 -04:00
|
|
|
class _CRG(LiteXModule):
|
2020-08-24 10:44:14 -04:00
|
|
|
def __init__(self, platform, sys_clk_freq):
|
2023-07-26 10:56:27 -04:00
|
|
|
self.rst = Signal()
|
2022-10-27 10:58:55 -04:00
|
|
|
self.cd_por = ClockDomain()
|
|
|
|
self.cd_sys = ClockDomain()
|
2020-08-24 10:44:14 -04:00
|
|
|
|
2020-11-08 21:34:46 -05:00
|
|
|
# Built in OSC
|
2022-10-27 10:58:55 -04:00
|
|
|
self.hf_clk = NXOSCA()
|
2020-11-08 21:34:46 -05:00
|
|
|
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
|
2022-10-27 10:58:55 -04:00
|
|
|
self.sys_pll = sys_pll = NXPLL(platform=platform, create_output_port_clocks=True)
|
2023-07-26 10:56:27 -04:00
|
|
|
self.comb += sys_pll.reset.eq(self.rst)
|
2020-11-08 21:34:46 -05:00
|
|
|
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
|
|
|
}
|
2022-11-08 06:29:11 -05:00
|
|
|
def __init__(self, sys_clk_freq=75e6, device="LIFCL-40-9BG400C", toolchain="radiant",
|
|
|
|
with_led_chaser = True,
|
2023-08-09 12:05:22 -04:00
|
|
|
with_uartbone = False,
|
2022-11-08 06:29:11 -05:00
|
|
|
**kwargs):
|
2022-05-02 06:42:04 -04:00
|
|
|
platform = lattice_crosslink_nx_evn.Platform(device=device, toolchain=toolchain)
|
2020-08-24 10:44:14 -04:00
|
|
|
|
2022-04-21 06:17:26 -04:00
|
|
|
# CRG --------------------------------------------------------------------------------------
|
2022-10-27 10:58:55 -04:00
|
|
|
self.crg = _CRG(platform, sys_clk_freq)
|
2022-04-21 06:17:26 -04:00
|
|
|
|
|
|
|
# SoCCore -----------------------------------------_----------------------------------------
|
2020-08-24 10:44:14 -04:00
|
|
|
# Disable Integrated SRAM since we want to instantiate LRAM specifically for it
|
|
|
|
kwargs["integrated_sram_size"] = 0
|
|
|
|
# Make serial_pmods available
|
2022-05-02 06:42:04 -04:00
|
|
|
platform.add_extension(lattice_crosslink_nx_evn.serial_pmods)
|
2022-04-21 06:17:26 -04:00
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq, ident="LiteX SoC on Crosslink-NX Evaluation Board", **kwargs)
|
2020-08-24 10:44:14 -04:00
|
|
|
|
|
|
|
# 128KB LRAM (used as SRAM) ---------------------------------------------------------------
|
|
|
|
size = 128*kB
|
2022-10-27 10:58:55 -04:00
|
|
|
self.spram = NXLRAM(32, size)
|
2023-08-09 12:05:22 -04:00
|
|
|
self.bus.add_slave("sram", self.spram.bus, SoCRegion(origin=self.mem_map["sram"], size=size))
|
2020-08-24 10:44:14 -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 = 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
|
|
|
|
2023-08-04 14:47:32 -04:00
|
|
|
# UARTBone ---------------------------------------------------------------------------------
|
2023-08-09 12:05:22 -04:00
|
|
|
if with_uartbone:
|
2023-08-04 14:47:32 -04:00
|
|
|
self.add_uartbone()
|
|
|
|
|
|
|
|
|
2020-08-24 10:44:14 -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=lattice_crosslink_nx_evn.Platform, description="LiteX SoC on Crosslink-NX Eval Board.")
|
2022-11-05 03:07:14 -04:00
|
|
|
parser.add_target_argument("--device", default="LIFCL-40-9BG400C", help="FPGA device (LIFCL-40-9BG400C, LIFCL-40-8BG400CES, or LIFCL-40-8BG400CES2).")
|
2022-11-08 04:41:35 -05:00
|
|
|
parser.add_target_argument("--sys-clk-freq", default=75e6, type=float, help="System clock frequency.")
|
2022-11-05 03:07:14 -04:00
|
|
|
parser.add_target_argument("--serial", default="serial", help="UART Pins (serial (requires R15 and R17 to be soldered) or serial_pmod[0-2]).")
|
|
|
|
parser.add_target_argument("--programmer", default="radiant", help="Programmer (radiant or ecpprog).")
|
|
|
|
parser.add_target_argument("--address", default=0x0, help="Flash address to program bitstream at.")
|
|
|
|
parser.add_target_argument("--prog-target", default="direct", help="Programming Target (direct or flash).")
|
2023-08-09 12:05:22 -04:00
|
|
|
parser.add_target_argument("--with-uartbone", action="store_true", help="Add UartBone on 1st serial.")
|
2020-08-24 10:44:14 -04:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2020-11-12 12:07:28 -05:00
|
|
|
soc = BaseSoC(
|
2022-11-08 04:41:35 -05:00
|
|
|
sys_clk_freq = args.sys_clk_freq,
|
2021-08-17 04:23:24 -04:00
|
|
|
device = args.device,
|
2020-11-25 04:45:25 -05:00
|
|
|
toolchain = args.toolchain,
|
2023-08-09 12:05:22 -04:00
|
|
|
with_uartbone = args.with_uartbone,
|
2022-11-07 02:43:26 -05:00
|
|
|
**parser.soc_argdict
|
2020-11-12 12:07:28 -05: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)
|
2020-08-24 10:44:14 -04:00
|
|
|
|
|
|
|
if args.load:
|
2022-09-15 15:27:08 -04:00
|
|
|
prog = soc.platform.create_programmer(args.prog_target, args.programmer)
|
|
|
|
if args.programmer == "ecpprog" and args.prog_target == "flash":
|
|
|
|
prog.flash(address=args.address, bitstream=builder.get_bitstream_filename(mode="sram"))
|
|
|
|
else:
|
|
|
|
prog.load_bitstream(builder.get_bitstream_filename(mode="sram"))
|
2020-08-24 10:44:14 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|