2019-08-05 08:34:56 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2020-08-23 09:00:17 -04:00
|
|
|
#
|
|
|
|
# This file is part of LiteX-Boards.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2019 Arnaud Durand <arnaud.durand@unifr.ch>
|
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
2019-08-05 08:34:56 -04:00
|
|
|
|
2020-05-05 09:11:38 -04:00
|
|
|
import os
|
2019-08-05 08:34:56 -04:00
|
|
|
import argparse
|
|
|
|
|
|
|
|
from migen import *
|
|
|
|
from migen.genlib.resetsync import AsyncResetSynchronizer
|
|
|
|
|
2019-08-26 03:09:40 -04:00
|
|
|
from litex_boards.platforms import ecp5_evn
|
2019-08-05 08:34:56 -04:00
|
|
|
|
|
|
|
from litex.soc.cores.clock import *
|
|
|
|
from litex.soc.integration.soc_core import *
|
|
|
|
from litex.soc.integration.builder import *
|
2020-05-08 16:16:13 -04:00
|
|
|
from litex.soc.cores.led import LedChaser
|
2019-08-05 08:34:56 -04:00
|
|
|
|
|
|
|
# CRG ----------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class _CRG(Module):
|
2019-08-09 03:42:17 -04:00
|
|
|
def __init__(self, platform, sys_clk_freq, x5_clk_freq):
|
2019-08-05 08:34:56 -04:00
|
|
|
self.clock_domains.cd_sys = ClockDomain()
|
|
|
|
|
|
|
|
# # #
|
|
|
|
|
|
|
|
# clk / rst
|
2019-08-09 03:42:17 -04:00
|
|
|
clk = clk12 = platform.request("clk12")
|
2019-08-05 08:34:56 -04:00
|
|
|
rst_n = platform.request("rst_n")
|
2019-08-09 03:42:17 -04:00
|
|
|
if x5_clk_freq is not None:
|
|
|
|
clk = clk50 = platform.request("ext_clk50")
|
|
|
|
self.comb += platform.request("ext_clk50_en").eq(1)
|
|
|
|
platform.add_period_constraint(clk50, 1e9/x5_clk_freq)
|
2019-08-05 08:34:56 -04:00
|
|
|
|
|
|
|
# pll
|
2019-08-09 03:42:17 -04:00
|
|
|
self.submodules.pll = pll = ECP5PLL()
|
|
|
|
self.comb += pll.reset.eq(~rst_n)
|
|
|
|
pll.register_clkin(clk, x5_clk_freq or 12e6)
|
|
|
|
pll.create_clkout(self.cd_sys, sys_clk_freq)
|
|
|
|
self.specials += AsyncResetSynchronizer(self.cd_sys, ~rst_n)
|
2019-08-05 08:34:56 -04:00
|
|
|
|
|
|
|
# BaseSoC ------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class BaseSoC(SoCCore):
|
2020-03-05 04:57:59 -05:00
|
|
|
def __init__(self, sys_clk_freq=int(50e6), x5_clk_freq=None, toolchain="trellis", **kwargs):
|
2019-08-05 08:34:56 -04:00
|
|
|
platform = ecp5_evn.Platform(toolchain=toolchain)
|
2019-12-03 03:33:08 -05:00
|
|
|
|
|
|
|
# SoCCore ----------------------------------------------------------------------------------
|
2020-06-30 12:11:04 -04:00
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq,
|
|
|
|
ident = "LiteX SoC on ECP5 Evaluation Board",
|
|
|
|
ident_version = True,
|
|
|
|
**kwargs)
|
2019-08-05 08:34:56 -04:00
|
|
|
|
2019-12-03 03:33:08 -05:00
|
|
|
# CRG --------------------------------------------------------------------------------------
|
2019-08-09 03:42:17 -04:00
|
|
|
crg = _CRG(platform, sys_clk_freq, x5_clk_freq)
|
2019-08-05 08:34:56 -04:00
|
|
|
self.submodules.crg = crg
|
|
|
|
|
2020-05-08 16:16:13 -04:00
|
|
|
# Leds -------------------------------------------------------------------------------------
|
|
|
|
self.submodules.leds = LedChaser(
|
2020-08-06 14:04:03 -04:00
|
|
|
pads = platform.request_all("user_led"),
|
2020-05-08 16:16:13 -04:00
|
|
|
sys_clk_freq = sys_clk_freq)
|
|
|
|
self.add_csr("leds")
|
|
|
|
|
2019-08-05 08:34:56 -04:00
|
|
|
# Build --------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description="LiteX SoC on ECP5 Evaluation Board")
|
2020-05-05 09:11:38 -04:00
|
|
|
parser.add_argument("--build", action="store_true", help="Build bitstream")
|
|
|
|
parser.add_argument("--load", action="store_true", help="Load bitstream")
|
2020-06-02 07:45:05 -04:00
|
|
|
parser.add_argument("--toolchain", default="trellis", help="Gateware toolchain to use, trellis (default) or diamond")
|
2019-08-05 08:34:56 -04:00
|
|
|
builder_args(parser)
|
|
|
|
soc_core_args(parser)
|
2020-05-05 09:11:38 -04:00
|
|
|
parser.add_argument("--sys-clk-freq", default=60e6, help="System clock frequency (default=60MHz)")
|
|
|
|
parser.add_argument("--x5-clk-freq", type=int, help="Use X5 oscillator as system clock at the specified frequency")
|
2019-08-05 08:34:56 -04:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2020-05-05 09:11:38 -04:00
|
|
|
soc = BaseSoC(toolchain=args.toolchain,
|
2019-12-03 03:33:08 -05:00
|
|
|
sys_clk_freq = int(float(args.sys_clk_freq)),
|
|
|
|
x5_clk_freq = args.x5_clk_freq,
|
2019-08-09 03:42:17 -04:00
|
|
|
**soc_core_argdict(args))
|
2019-08-05 08:34:56 -04:00
|
|
|
builder = Builder(soc, **builder_argdict(args))
|
2020-05-05 09:11:38 -04:00
|
|
|
builder.build(run=args.build)
|
|
|
|
|
|
|
|
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 + ".svf"))
|
2019-08-05 08:34:56 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|