2022-01-03 16:31:13 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
#
|
|
|
|
# This file is part of LiteX-Boards.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2022 Primesh Pinto <primeshp@gmail.com>
|
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
|
|
from migen import *
|
2022-03-21 11:59:40 -04:00
|
|
|
|
2022-10-27 10:58:55 -04:00
|
|
|
from litex.gen import LiteXModule
|
|
|
|
|
2022-01-03 16:31:13 -05:00
|
|
|
from litex.build.generic_platform import *
|
2022-03-21 11:59:40 -04:00
|
|
|
|
2022-05-02 06:42:04 -04:00
|
|
|
from litex_boards.platforms import seeedstudio_spartan_edge_accelerator
|
2022-03-21 11:59:40 -04:00
|
|
|
|
2022-01-03 16:31:13 -05:00
|
|
|
from litex.soc.cores.clock import *
|
|
|
|
from litex.soc.integration.soc import SoCRegion
|
|
|
|
from litex.soc.integration.soc_core import *
|
|
|
|
from litex.soc.integration.builder import *
|
|
|
|
from litex.soc.cores.led import LedChaser,WS2812
|
|
|
|
from litex.soc.cores.video import *
|
|
|
|
|
2022-01-06 03:37:46 -05:00
|
|
|
# Serial Port --------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
_serial_io = [
|
|
|
|
# Use J10 connectors 0/1 IOs + GND.
|
|
|
|
("serial", 0,
|
2022-01-03 16:31:13 -05:00
|
|
|
Subsignal("tx", Pins("j10:j10_0")),
|
|
|
|
Subsignal("rx", Pins("j10:j10_1")),
|
|
|
|
IOStandard("LVCMOS33")
|
|
|
|
),
|
|
|
|
]
|
|
|
|
|
|
|
|
# CRG ----------------------------------------------------------------------------------------------
|
|
|
|
|
2022-10-27 10:58:55 -04:00
|
|
|
class _CRG(LiteXModule):
|
2022-01-03 16:31:13 -05:00
|
|
|
def __init__(self, platform, sys_clk_freq, with_video_pll):
|
2022-10-27 10:58:55 -04:00
|
|
|
self.rst = Signal()
|
|
|
|
self.cd_sys = ClockDomain()
|
|
|
|
self.cd_hdmi = ClockDomain()
|
|
|
|
self.cd_hdmi5x = ClockDomain()
|
2022-01-03 16:31:13 -05:00
|
|
|
|
2022-01-06 03:37:46 -05:00
|
|
|
# # #
|
|
|
|
|
|
|
|
clk100 = platform.request("clk100")
|
|
|
|
rst_n = platform.request("rst_n")
|
|
|
|
|
2022-10-27 10:58:55 -04:00
|
|
|
self.pll = pll = S7PLL(speedgrade=-1)
|
2022-01-03 16:31:13 -05:00
|
|
|
self.comb += pll.reset.eq(~rst_n | self.rst)
|
|
|
|
pll.register_clkin(clk100, sys_clk_freq)
|
|
|
|
pll.create_clkout(self.cd_sys, sys_clk_freq)
|
|
|
|
|
|
|
|
if with_video_pll:
|
2022-10-27 10:58:55 -04:00
|
|
|
self.video_pll = video_pll = S7PLL(speedgrade=-1)
|
2022-01-03 16:31:13 -05:00
|
|
|
video_pll.reset.eq(~rst_n | self.rst)
|
|
|
|
video_pll.register_clkin(clk100, 100e6)
|
|
|
|
video_pll.create_clkout(self.cd_hdmi, 25e6)
|
|
|
|
video_pll.create_clkout(self.cd_hdmi5x, 5*25e6)
|
|
|
|
|
|
|
|
# BaseSoC ------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class BaseSoC(SoCCore):
|
|
|
|
|
2022-11-08 05:54:17 -05:00
|
|
|
def __init__(self, sys_clk_freq=100e6,
|
2022-01-06 03:37:46 -05:00
|
|
|
with_led_chaser = True,
|
|
|
|
with_jtagbone = False,
|
|
|
|
with_video_terminal = True,
|
|
|
|
with_neopixel = False,
|
|
|
|
**kwargs):
|
2022-05-02 06:42:04 -04:00
|
|
|
platform = seeedstudio_spartan_edge_accelerator.Platform()
|
2022-01-03 16:31:13 -05:00
|
|
|
platform.add_extension(_serial_io)
|
|
|
|
|
|
|
|
# CRG --------------------------------------------------------------------------------------
|
2022-10-27 10:58:55 -04:00
|
|
|
self.crg = _CRG(platform, sys_clk_freq, with_video_pll=with_video_terminal)
|
2022-01-03 16:31:13 -05:00
|
|
|
|
2022-04-21 06:17:26 -04:00
|
|
|
# SoCCore ----------------------------------------------------------------------------------
|
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq, ident = "LiteX SoC on Seeedstudio Spartan Edge Accelerator", **kwargs)
|
|
|
|
|
2022-01-03 16:31:13 -05:00
|
|
|
# Jtagbone ---------------------------------------------------------------------------------
|
|
|
|
if with_jtagbone:
|
|
|
|
self.add_jtagbone()
|
|
|
|
|
|
|
|
# Leds -------------------------------------------------------------------------------------
|
|
|
|
if with_led_chaser:
|
2022-10-27 10:58:55 -04:00
|
|
|
self.leds = LedChaser(
|
2022-01-03 16:31:13 -05:00
|
|
|
pads = platform.request_all("user_led"),
|
2022-01-06 03:37:46 -05:00
|
|
|
sys_clk_freq = sys_clk_freq
|
|
|
|
)
|
2022-01-03 16:31:13 -05:00
|
|
|
|
|
|
|
# Video ------------------------------------------------------------------------------------
|
|
|
|
if with_video_terminal:
|
2022-10-27 10:58:55 -04:00
|
|
|
self.videophy = VideoHDMIPHY(platform.request("hdmi"), clock_domain="hdmi")
|
2022-01-03 16:31:13 -05:00
|
|
|
self.add_video_colorbars(phy=self.videophy, timings="640x480@75Hz", clock_domain="hdmi")
|
|
|
|
#self.add_video_terminal(phy=self.videophy, timings="640x480@75Hz", clock_domain="hdmi") #Fixme Not enough BRAM
|
|
|
|
|
|
|
|
# Neopixel ---------------------------------------------------------------------------------
|
2022-01-06 03:37:46 -05:00
|
|
|
# To test Nexpixel with LiteX BIOS:
|
|
|
|
# - mem_list (to get ws2812_base).
|
|
|
|
# - mem_write <ws2812_base> 0x00100000
|
2022-01-03 16:31:13 -05:00
|
|
|
if with_neopixel:
|
2022-10-27 10:58:55 -04:00
|
|
|
self.ws2812 = WS2812(platform.request("rgb"), nleds=2, sys_clk_freq=sys_clk_freq)
|
2022-01-06 03:37:46 -05:00
|
|
|
self.bus.add_slave(name="ws2812", slave=self.ws2812.bus, region=SoCRegion(size=2*4))
|
2022-01-03 16:31:13 -05: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=seeedstudio_spartan_edge_accelerator.Platform, description="LiteX SoC on Spartan Edge Accelerator.")
|
|
|
|
parser.add_target_argument("--sys-clk-freq", default=100e6, type=float, help="System clock frequency.")
|
|
|
|
parser.add_target_argument("--with-jtagbone", action="store_true", help="Enable Jtagbone support.")
|
|
|
|
parser.add_target_argument("--with-video-terminal", action="store_true", help="Enable Video Colorbars (HDMI).")
|
|
|
|
parser.add_target_argument("--with-neopixel", action="store_true", help="Enable onboard 2 Neopixels Leds.")
|
2022-11-05 03:07:14 -04:00
|
|
|
|
2022-01-03 16:31:13 -05:00
|
|
|
args = parser.parse_args()
|
|
|
|
soc = BaseSoC(
|
2022-11-08 04:41:35 -05:00
|
|
|
sys_clk_freq = args.sys_clk_freq,
|
2022-01-06 03:37:46 -05:00
|
|
|
with_jtagbone = args.with_jtagbone,
|
|
|
|
with_video_terminal = args.with_video_terminal,
|
|
|
|
with_neopixel = args.with_neopixel,
|
2022-11-07 02:43:26 -05:00
|
|
|
**parser.soc_argdict
|
2022-01-03 16:31:13 -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)
|
2022-01-03 16:31:13 -05:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|