2019-08-05 12:34:56 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
2020-08-23 13:00:17 +00: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 12:34:56 +00:00
|
|
|
|
|
|
|
|
from migen import *
|
|
|
|
|
from migen.genlib.resetsync import AsyncResetSynchronizer
|
|
|
|
|
|
2023-02-23 08:09:33 +00:00
|
|
|
from litex.gen import *
|
2022-10-27 14:58:55 +00:00
|
|
|
|
2022-05-02 10:42:04 +00:00
|
|
|
from litex_boards.platforms import lattice_ecp5_evn
|
2019-08-05 12:34:56 +00:00
|
|
|
|
|
|
|
|
from litex.soc.cores.clock import *
|
|
|
|
|
from litex.soc.integration.soc_core import *
|
|
|
|
|
from litex.soc.integration.builder import *
|
2020-05-08 20:16:13 +00:00
|
|
|
from litex.soc.cores.led import LedChaser
|
2019-08-05 12:34:56 +00:00
|
|
|
|
|
|
|
|
# CRG ----------------------------------------------------------------------------------------------
|
|
|
|
|
|
2022-10-27 14:58:55 +00:00
|
|
|
class _CRG(LiteXModule):
|
2019-08-09 07:42:17 +00:00
|
|
|
def __init__(self, platform, sys_clk_freq, x5_clk_freq):
|
2022-10-27 14:58:55 +00:00
|
|
|
self.rst = Signal()
|
|
|
|
|
self.cd_sys = ClockDomain()
|
2019-08-05 12:34:56 +00:00
|
|
|
|
|
|
|
|
# # #
|
|
|
|
|
|
2022-02-15 09:58:38 +00:00
|
|
|
# Clk / Rst.
|
2019-08-09 07:42:17 +00:00
|
|
|
clk = clk12 = platform.request("clk12")
|
2019-08-05 12:34:56 +00:00
|
|
|
rst_n = platform.request("rst_n")
|
2019-08-09 07:42:17 +00: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 12:34:56 +00:00
|
|
|
|
2022-02-15 09:58:38 +00:00
|
|
|
# PLL.
|
2022-10-27 14:58:55 +00:00
|
|
|
self.pll = pll = ECP5PLL()
|
2020-11-04 10:09:30 +00:00
|
|
|
self.comb += pll.reset.eq(~rst_n | self.rst)
|
2019-08-09 07:42:17 +00:00
|
|
|
pll.register_clkin(clk, x5_clk_freq or 12e6)
|
|
|
|
|
pll.create_clkout(self.cd_sys, sys_clk_freq)
|
2019-08-05 12:34:56 +00:00
|
|
|
|
|
|
|
|
# BaseSoC ------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
class BaseSoC(SoCCore):
|
2022-11-08 11:29:11 +00:00
|
|
|
def __init__(self, sys_clk_freq=50e6, toolchain="trellis", x5_clk_freq=None,
|
|
|
|
|
with_led_chaser = True,
|
|
|
|
|
**kwargs):
|
2022-05-02 10:42:04 +00:00
|
|
|
platform = lattice_ecp5_evn.Platform(toolchain=toolchain)
|
2019-12-03 08:33:08 +00:00
|
|
|
|
|
|
|
|
# CRG --------------------------------------------------------------------------------------
|
2022-10-27 14:58:55 +00:00
|
|
|
self.crg = _CRG(platform, sys_clk_freq, x5_clk_freq)
|
2022-04-21 10:17:26 +00:00
|
|
|
|
|
|
|
|
# SoCCore ----------------------------------------------------------------------------------
|
|
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq, ident="LiteX SoC on ECP5 Evaluation Board", **kwargs)
|
2019-08-05 12:34:56 +00:00
|
|
|
|
2020-05-08 20:16:13 +00:00
|
|
|
# Leds -------------------------------------------------------------------------------------
|
2021-07-06 21:39:37 +00:00
|
|
|
if with_led_chaser:
|
2022-10-27 14:58:55 +00:00
|
|
|
self.leds = LedChaser(
|
2021-07-06 21:39:37 +00:00
|
|
|
pads = platform.request_all("user_led"),
|
|
|
|
|
sys_clk_freq = sys_clk_freq)
|
2020-05-08 20:16:13 +00:00
|
|
|
|
2019-08-05 12:34:56 +00:00
|
|
|
# Build --------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
def main():
|
2022-11-06 20:39:52 +00:00
|
|
|
from litex.build.parser import LiteXArgumentParser
|
2022-11-08 09:41:35 +00:00
|
|
|
parser = LiteXArgumentParser(platform=lattice_ecp5_evn.Platform, description="LiteX SoC on ECP5 Evaluation Board.")
|
|
|
|
|
parser.add_target_argument("--sys-clk-freq", default=60e6, type=float, help="System clock frequency.")
|
|
|
|
|
parser.add_target_argument("--x5-clk-freq", type=int, help="Use X5 oscillator as system clock at the specified frequency.")
|
2019-08-05 12:34:56 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
2022-11-08 09:41:35 +00:00
|
|
|
soc = BaseSoC(
|
|
|
|
|
toolchain = args.toolchain,
|
|
|
|
|
sys_clk_freq = args.sys_clk_freq,
|
2019-12-03 08:33:08 +00:00
|
|
|
x5_clk_freq = args.x5_clk_freq,
|
2022-11-07 07:43:26 +00:00
|
|
|
**parser.soc_argdict)
|
2022-11-05 07:07:14 +00:00
|
|
|
builder = Builder(soc, **parser.builder_argdict)
|
2022-05-06 13:14:32 +00:00
|
|
|
if args.build:
|
2022-11-05 07:07:14 +00:00
|
|
|
builder.build(**parser.toolchain_argdict)
|
2020-05-05 13:11:38 +00:00
|
|
|
|
|
|
|
|
if args.load:
|
|
|
|
|
prog = soc.platform.create_programmer()
|
2022-03-17 08:21:05 +00:00
|
|
|
prog.load_bitstream(builder.get_bitstream_filename(mode="sram", ext=".svf")) # FIXME
|
2019-08-05 12:34:56 +00:00
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|