2020-05-07 10:36:04 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2020-08-23 09:00:17 -04:00
|
|
|
#
|
|
|
|
# This file is part of LiteX-Boards.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2020 Florent Kermarrec <florent@enjoy-digital.fr>
|
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
2020-05-07 09:24:03 -04:00
|
|
|
|
2020-05-07 10:36:04 -04:00
|
|
|
import os
|
|
|
|
|
2020-05-07 09:22:22 -04:00
|
|
|
from migen import *
|
2020-05-07 10:36:04 -04:00
|
|
|
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
|
|
|
|
2020-05-07 10:36:04 -04:00
|
|
|
from litex_boards.platforms import pano_logic_g2
|
2020-05-07 09:22:22 -04:00
|
|
|
|
2020-05-07 10:36:04 -04:00
|
|
|
from litex.soc.cores.clock import *
|
|
|
|
from litex.soc.integration.soc_core import *
|
2020-05-07 09:22:22 -04:00
|
|
|
from litex.soc.integration.builder import *
|
2020-05-08 16:16:13 -04:00
|
|
|
from litex.soc.cores.led import LedChaser
|
2020-05-07 09:22:22 -04:00
|
|
|
|
2020-05-29 04:41:35 -04:00
|
|
|
from liteeth.phy import LiteEthPHY
|
2020-05-27 04:13:12 -04:00
|
|
|
|
2020-05-07 10:36:04 -04:00
|
|
|
# CRG ----------------------------------------------------------------------------------------------
|
2020-05-07 09:22:22 -04:00
|
|
|
|
2022-10-27 10:58:55 -04:00
|
|
|
class _CRG(LiteXModule):
|
2020-05-27 04:13:12 -04:00
|
|
|
def __init__(self, platform, clk_freq, with_ethernet=False):
|
2022-10-27 10:58:55 -04:00
|
|
|
self.rst = Signal()
|
|
|
|
self.cd_sys = ClockDomain()
|
2020-05-07 09:22:22 -04:00
|
|
|
|
2020-05-07 10:36:04 -04:00
|
|
|
# # #
|
2020-05-07 09:22:22 -04:00
|
|
|
|
2020-05-27 04:13:12 -04:00
|
|
|
if not with_ethernet:
|
|
|
|
# Take Ethernet PHY out of reset to enable 125MHz on clk125 (25MHz otherwise).
|
|
|
|
# See https://github.com/tomverbeure/panologic-g2#fpga-external-clocking-architecture
|
|
|
|
self.comb += platform.request("eth_rst_n").eq(1)
|
2020-05-26 02:36:06 -04:00
|
|
|
|
2022-10-27 10:58:55 -04:00
|
|
|
self.pll = pll = S6PLL(speedgrade=-2)
|
2020-11-04 05:09:30 -05:00
|
|
|
self.comb += pll.reset.eq(~platform.request("user_btn_n") | self.rst)
|
2020-05-07 10:36:04 -04:00
|
|
|
pll.register_clkin(platform.request("clk125"), 125e6)
|
|
|
|
pll.create_clkout(self.cd_sys, clk_freq)
|
2021-01-07 02:00:40 -05:00
|
|
|
platform.add_false_path_constraints(self.cd_sys.clk, pll.clkin) # Ignore sys_clk to pll.clkin path created by SoC's rst.
|
2020-05-07 09:22:22 -04:00
|
|
|
|
2020-05-07 10:36:04 -04:00
|
|
|
# BaseSoC ------------------------------------------------------------------------------------------
|
2020-05-07 09:22:22 -04:00
|
|
|
|
2020-05-07 10:36:04 -04:00
|
|
|
class BaseSoC(SoCCore):
|
2022-11-08 06:29:11 -05:00
|
|
|
def __init__(self, revision, sys_clk_freq=50e6,
|
|
|
|
with_ethernet = False,
|
|
|
|
with_etherbone = False,
|
|
|
|
eth_ip = "192.168.1.50",
|
|
|
|
with_led_chaser = True,
|
|
|
|
**kwargs):
|
2020-05-27 02:49:41 -04:00
|
|
|
platform = pano_logic_g2.Platform(revision=revision)
|
2020-05-27 04:13:12 -04:00
|
|
|
if with_etherbone:
|
|
|
|
sys_clk_freq = int(125e6)
|
2020-05-07 10:36:04 -04:00
|
|
|
|
2020-05-07 09:22:22 -04:00
|
|
|
# CRG --------------------------------------------------------------------------------------
|
2022-04-21 06:17:26 -04:00
|
|
|
with_ethernet = (with_ethernet or with_etherbone)
|
2022-10-27 10:58:55 -04:00
|
|
|
self.crg = _CRG(platform, sys_clk_freq, with_ethernet=with_ethernet)
|
2022-04-21 06:17:26 -04:00
|
|
|
|
|
|
|
# SoCCore ----------------------------------------------------------------------------------
|
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq, ident="LiteX SoC on Pano Logic G2", **kwargs)
|
2020-05-27 04:13:12 -04:00
|
|
|
|
2020-05-29 04:41:35 -04:00
|
|
|
# Ethernet / Etherbone ---------------------------------------------------------------------
|
|
|
|
if with_ethernet or with_etherbone:
|
2022-10-27 10:58:55 -04:00
|
|
|
self.ethphy = LiteEthPHY(
|
2020-05-27 04:13:12 -04:00
|
|
|
clock_pads = self.platform.request("eth_clocks"),
|
|
|
|
pads = self.platform.request("eth"),
|
2020-05-29 04:41:35 -04:00
|
|
|
clk_freq = sys_clk_freq,
|
2020-05-27 04:13:12 -04:00
|
|
|
with_hw_init_reset = False)
|
2020-05-29 04:41:35 -04:00
|
|
|
if with_ethernet:
|
|
|
|
self.add_ethernet(phy=self.ethphy)
|
|
|
|
if with_etherbone:
|
2021-01-07 18:44:15 -05:00
|
|
|
self.add_etherbone(phy=self.ethphy, ip_address=eth_ip)
|
2020-05-07 10:36:04 -04:00
|
|
|
|
2020-05-08 16:16:13 -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 = platform.request_all("user_led"),
|
|
|
|
sys_clk_freq = sys_clk_freq)
|
2020-05-08 16:16:13 -04:00
|
|
|
|
2020-05-07 10:36:04 -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=pano_logic_g2.Platform, description="LiteX SoC on Pano Logic G2.")
|
|
|
|
parser.add_target_argument("--revision", default="c", help="Board revision (b or c).")
|
|
|
|
parser.add_target_argument("--sys-clk-freq", default=50e6, type=float, help="System clock frequency.")
|
2022-11-05 03:07:14 -04:00
|
|
|
ethopts = parser.target_group.add_mutually_exclusive_group()
|
2022-11-08 04:41:35 -05:00
|
|
|
ethopts.add_argument("--with-ethernet", action="store_true", help="Enable Ethernet support.")
|
|
|
|
ethopts.add_argument("--with-etherbone", action="store_true", help="Enable Etherbone support.")
|
|
|
|
parser.add_target_argument("--eth-ip", default="192.168.1.50", help="Ethernet/Etherbone IP address.")
|
2020-05-07 10:36:04 -04:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2020-05-27 04:13:12 -04:00
|
|
|
soc = BaseSoC(
|
|
|
|
revision = args.revision,
|
2022-11-08 04:41:35 -05:00
|
|
|
sys_clk_freq = args.sys_clk_freq,
|
2020-05-27 04:13:12 -04:00
|
|
|
with_ethernet = args.with_ethernet,
|
|
|
|
with_etherbone = args.with_etherbone,
|
2021-01-07 18:44:15 -05:00
|
|
|
eth_ip = args.eth_ip,
|
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-05-07 10:36:04 -04: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"))
|
2020-05-07 10:36:04 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|