2020-05-07 10:36:04 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
# This file is Copyright (c) 2020 Florent Kermarrec <florent@enjoy-digital.fr>
|
2020-05-07 09:24:03 -04:00
|
|
|
# License: BSD
|
|
|
|
|
2020-05-07 10:36:04 -04:00
|
|
|
import os
|
|
|
|
import argparse
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-05-07 10:36:04 -04:00
|
|
|
class _CRG(Module):
|
2020-05-27 04:13:12 -04:00
|
|
|
def __init__(self, platform, clk_freq, with_ethernet=False):
|
2020-05-07 10:36:04 -04:00
|
|
|
self.clock_domains.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
|
|
|
|
2020-05-07 10:36:04 -04:00
|
|
|
self.submodules.pll = pll = S6PLL(speedgrade=-2)
|
2020-05-27 04:13:12 -04:00
|
|
|
self.comb += pll.reset.eq(~platform.request("user_btn_n"))
|
2020-05-07 10:36:04 -04:00
|
|
|
pll.register_clkin(platform.request("clk125"), 125e6)
|
|
|
|
pll.create_clkout(self.cd_sys, clk_freq)
|
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):
|
2020-05-27 04:13:12 -04:00
|
|
|
def __init__(self, revision, sys_clk_freq=int(50e6), with_ethernet=False, with_etherbone=False, **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
|
|
|
|
|
|
|
# SoCCore ----------------------------------------------------------------------------------
|
2020-06-30 12:11:04 -04:00
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq,
|
|
|
|
ident = "LiteX SoC on Pano Logic G2",
|
|
|
|
ident_version = True,
|
|
|
|
**kwargs)
|
2020-05-07 09:22:22 -04:00
|
|
|
|
|
|
|
# CRG --------------------------------------------------------------------------------------
|
2020-05-27 04:13:12 -04:00
|
|
|
self.submodules.crg = _CRG(platform, sys_clk_freq, with_ethernet=with_ethernet or with_etherbone)
|
|
|
|
|
2020-05-29 04:41:35 -04:00
|
|
|
# Ethernet / Etherbone ---------------------------------------------------------------------
|
|
|
|
if with_ethernet or with_etherbone:
|
|
|
|
self.submodules.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)
|
|
|
|
self.add_csr("ethphy")
|
2020-05-29 04:41:35 -04:00
|
|
|
if with_ethernet:
|
|
|
|
self.add_ethernet(phy=self.ethphy)
|
|
|
|
if with_etherbone:
|
|
|
|
self.add_etherbone(phy=self.ethphy)
|
2020-05-07 10:36:04 -04:00
|
|
|
|
2020-05-08 16:16:13 -04:00
|
|
|
# Leds -------------------------------------------------------------------------------------
|
|
|
|
self.submodules.leds = LedChaser(
|
|
|
|
pads = Cat(*[platform.request("user_led", i) for i in range(3)]),
|
|
|
|
sys_clk_freq = sys_clk_freq)
|
|
|
|
self.add_csr("leds")
|
|
|
|
|
2020-05-07 10:36:04 -04:00
|
|
|
# Build --------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description="LiteX SoC on Pano Logic G2")
|
2020-05-27 02:49:41 -04:00
|
|
|
parser.add_argument("--build", action="store_true", help="Build bitstream")
|
|
|
|
parser.add_argument("--load", action="store_true", help="Load bitstream")
|
|
|
|
parser.add_argument("--revision", default="c", help="Board revision c (default) or b")
|
2020-05-07 10:36:04 -04:00
|
|
|
builder_args(parser)
|
|
|
|
soc_core_args(parser)
|
2020-05-27 04:13:12 -04:00
|
|
|
parser.add_argument("--with-ethernet", action="store_true", help="Enable Ethernet support")
|
|
|
|
parser.add_argument("--with-etherbone", action="store_true", help="Enable Etherbone support")
|
2020-05-07 10:36:04 -04:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2020-05-27 04:13:12 -04:00
|
|
|
assert not (args.with_ethernet and args.with_etherbone)
|
|
|
|
soc = BaseSoC(
|
|
|
|
revision = args.revision,
|
|
|
|
with_ethernet = args.with_ethernet,
|
|
|
|
with_etherbone = args.with_etherbone,
|
|
|
|
**soc_core_argdict(args))
|
2020-05-07 10:36:04 -04:00
|
|
|
builder = Builder(soc, **builder_argdict(args))
|
|
|
|
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 + ".bit"))
|
2020-05-07 10:36:04 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|