2021-10-01 04:58:16 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
#
|
|
|
|
# This file is part of LiteX-Boards.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2021 Florent Kermarrec <florent@enjoy-digital.fr>
|
2021-11-09 12:57:24 -05:00
|
|
|
# Copyright (c) 2021 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
|
2021-10-01 04:58:16 -04:00
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
|
|
import os
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
from migen import *
|
|
|
|
|
|
|
|
from litex_boards.platforms import quicklogic_quickfeather
|
|
|
|
|
|
|
|
from litex.soc.cores.clock import *
|
|
|
|
from litex.soc.integration.soc_core import *
|
|
|
|
from litex.soc.integration.builder import *
|
|
|
|
from litex.soc.cores.led import LedChaser
|
2021-11-12 05:43:28 -05:00
|
|
|
from litex.soc.cores.gpio import *
|
2021-10-01 04:58:16 -04:00
|
|
|
|
|
|
|
# CRG ----------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class _CRG(Module):
|
2021-11-14 03:26:29 -05:00
|
|
|
def __init__(self, platform, with_eos_s3=False):
|
2021-11-09 12:57:24 -05:00
|
|
|
self.rst = Signal()
|
2021-10-01 04:58:16 -04:00
|
|
|
self.clock_domains.cd_sys = ClockDomain()
|
|
|
|
|
|
|
|
# # #
|
|
|
|
|
2021-11-14 03:26:29 -05:00
|
|
|
if with_eos_s3:
|
|
|
|
# Use clocks generated by the EOS-S3 CPU.
|
2021-11-14 03:19:19 -05:00
|
|
|
self.comb += ClockSignal("sys").eq(ClockSignal("eos_s3_0"))
|
|
|
|
self.comb += ResetSignal("sys").eq(ResetSignal("eos_s3_0") | self.rst)
|
2021-11-09 12:57:24 -05:00
|
|
|
else:
|
2021-11-14 03:26:29 -05:00
|
|
|
# Use clocks generated by the qlal4s3b_cell_macro.
|
|
|
|
class Open(Signal): pass
|
2021-11-09 12:57:24 -05:00
|
|
|
self.specials += Instance("qlal4s3b_cell_macro",
|
|
|
|
o_Sys_Clk0 = self.cd_sys.clk,
|
|
|
|
o_Sys_Clk0_Rst = self.cd_sys.rst,
|
|
|
|
o_Sys_Clk1 = Open(),
|
|
|
|
o_Sys_Clk1_Rst = Open(),
|
|
|
|
)
|
2021-10-01 04:58:16 -04:00
|
|
|
|
|
|
|
# BaseSoC ------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class BaseSoC(SoCCore):
|
2021-11-14 03:30:52 -05:00
|
|
|
def __init__(self, sys_clk_freq=int(10e6), with_led_chaser=True, with_gpio_in=True, **kwargs):
|
2021-10-01 04:58:16 -04:00
|
|
|
platform = quicklogic_quickfeather.Platform()
|
|
|
|
|
|
|
|
# SoCCore ----------------------------------------------------------------------------------
|
2021-11-14 03:26:29 -05:00
|
|
|
kwargs["cpu_type"] = kwargs.get("cpu_type", None)
|
2021-10-01 04:58:16 -04:00
|
|
|
kwargs["with_uart"] = False
|
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq,
|
|
|
|
ident = "LiteX SoC on QuickLogic QuickFeather",
|
|
|
|
ident_version = True,
|
|
|
|
**kwargs)
|
|
|
|
|
|
|
|
# CRG --------------------------------------------------------------------------------------
|
2021-11-14 03:26:29 -05:00
|
|
|
self.submodules.crg = _CRG(platform, with_eos_s3=kwargs["cpu_type"] == "eos-s3")
|
2021-10-01 04:58:16 -04:00
|
|
|
|
|
|
|
# Leds -------------------------------------------------------------------------------------
|
|
|
|
if with_led_chaser:
|
|
|
|
self.submodules.leds = LedChaser(
|
|
|
|
pads = platform.request_all("user_led"),
|
|
|
|
sys_clk_freq = sys_clk_freq)
|
|
|
|
|
2021-11-14 03:30:52 -05:00
|
|
|
# GPIOIn (Interrupt test) ------------------------------------------------------------------
|
|
|
|
if with_gpio_in:
|
|
|
|
self.submodules.gpio = GPIOIn(platform.request_all("user_btn_n"), with_irq=True)
|
|
|
|
if kwargs["cpu_type"] == "eos-s3":
|
|
|
|
self.irq.add("gpio", use_loc_if_exists=True)
|
|
|
|
|
2021-10-01 04:58:16 -04:00
|
|
|
# Build --------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description="LiteX SoC on Quicklogic QuickFeather")
|
|
|
|
parser.add_argument("--build", action="store_true", help="Build bitstream")
|
|
|
|
soc_core_args(parser)
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
soc = BaseSoC(**soc_core_argdict(args))
|
|
|
|
builder = Builder(soc, compile_software=False)
|
|
|
|
builder.build(run=args.build)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|