2019-06-24 06:38:58 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2020-08-23 09:00:17 -04:00
|
|
|
#
|
|
|
|
# This file is part of LiteX-Boards.
|
|
|
|
#
|
2020-11-12 07:34:43 -05:00
|
|
|
# Copyright (c) 2014-2020 Florent Kermarrec <florent@enjoy-digital.fr>
|
2020-08-23 09:00:17 -04:00
|
|
|
# Copyright (c) 2013-2014 Sebastien Bourdeauducq <sb@m-labs.hk>
|
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
2019-06-24 06:38:58 -04:00
|
|
|
|
|
|
|
import importlib
|
|
|
|
|
|
|
|
from migen import *
|
2020-04-10 04:26:19 -04:00
|
|
|
|
2022-10-27 10:58:55 -04:00
|
|
|
from litex.gen import LiteXModule
|
|
|
|
|
2020-04-10 04:26:19 -04:00
|
|
|
from litex.build.io import CRG
|
2019-06-24 06:38:58 -04:00
|
|
|
|
|
|
|
from litex.soc.integration.soc_core import *
|
|
|
|
from litex.soc.integration.builder import *
|
|
|
|
|
2020-11-12 07:34:43 -05:00
|
|
|
from litex.soc.cores.led import LedChaser
|
2019-06-24 06:38:58 -04:00
|
|
|
|
|
|
|
# BaseSoC ------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class BaseSoC(SoCCore):
|
2021-07-06 17:39:37 -04:00
|
|
|
def __init__(self, platform, with_ethernet=False, with_led_chaser=True, **kwargs):
|
2019-06-24 06:38:58 -04:00
|
|
|
sys_clk_freq = int(1e9/platform.default_clk_period)
|
2019-12-03 03:07:09 -05:00
|
|
|
|
|
|
|
# CRG --------------------------------------------------------------------------------------
|
2022-10-27 10:58:55 -04:00
|
|
|
self.crg = CRG(platform.request(platform.default_clk_name))
|
2019-06-24 06:38:58 -04:00
|
|
|
|
2022-04-21 06:17:26 -04:00
|
|
|
# SoCCore ----------------------------------------------------------------------------------
|
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq, ident="LiteX Simple SoC", **kwargs)
|
|
|
|
|
2020-11-12 07:34:43 -05:00
|
|
|
# Leds -------------------------------------------------------------------------------------
|
2020-11-12 08:26:00 -05:00
|
|
|
try:
|
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 = platform.request_all("user_led"),
|
|
|
|
sys_clk_freq = sys_clk_freq)
|
2020-11-12 08:26:00 -05:00
|
|
|
except:
|
|
|
|
pass
|
2019-06-24 06:38:58 -04:00
|
|
|
|
|
|
|
# Build --------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def main():
|
2022-11-06 15:39:52 -05:00
|
|
|
from litex.build.parser import LiteXArgumentParser
|
2022-11-05 03:07:14 -04:00
|
|
|
parser = LiteXArgumentParser(description="Generic LiteX SoC")
|
2022-11-08 05:55:06 -05:00
|
|
|
target_group = parser.add_argument_group(title="Target options")
|
|
|
|
target_group.add_argument("platform", help="Module name of the platform to build for.")
|
|
|
|
target_group.add_argument("--build", action="store_true", help="Build design.")
|
|
|
|
target_group.add_argument("--load", action="store_true", help="Load bitstream.")
|
|
|
|
target_group.add_argument("--toolchain", default=None, help="FPGA toolchain.")
|
|
|
|
builder_args(parser)
|
|
|
|
soc_core_args(parser)
|
2019-06-24 06:38:58 -04:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
platform_module = importlib.import_module(args.platform)
|
2020-11-12 07:34:43 -05:00
|
|
|
platform_kwargs = {}
|
2020-06-02 07:45:05 -04:00
|
|
|
if args.toolchain is not None:
|
2020-11-12 07:34:43 -05:00
|
|
|
platform_kwargs["toolchain"] = args.toolchain
|
|
|
|
platform = platform_module.Platform(**platform_kwargs)
|
2022-11-08 05:55:06 -05:00
|
|
|
soc = BaseSoC(platform,**soc_core_argdict(args))
|
|
|
|
builder = Builder(soc, **builder_argdict(args))
|
2022-05-06 09:14:32 -04:00
|
|
|
if args.build:
|
2022-11-08 05:55:06 -05:00
|
|
|
builder.build()
|
2019-06-24 06:38:58 -04:00
|
|
|
|
2020-11-12 07:34:43 -05:00
|
|
|
if args.load:
|
|
|
|
prog = soc.platform.create_programmer()
|
2022-03-17 04:21:05 -04:00
|
|
|
prog.load_bitstream(builder.get_bitstream_filename(mode="sram"))
|
2019-06-24 06:38:58 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|