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-09 12:57:24 -05:00
|
|
|
def __init__(self, platform, is_eoss3_cpu=False):
|
|
|
|
self.rst = Signal()
|
2021-10-01 04:58:16 -04:00
|
|
|
self.clock_domains.cd_sys = ClockDomain()
|
|
|
|
|
|
|
|
# # #
|
|
|
|
|
|
|
|
class Open(Signal): pass
|
|
|
|
|
2021-11-09 12:57:24 -05:00
|
|
|
if is_eoss3_cpu:
|
|
|
|
self.comb += ClockSignal("sys").eq(ClockSignal("Sys_Clk0"))
|
|
|
|
self.comb += ResetSignal("sys").eq(ResetSignal("Sys_Clk0") | self.rst)
|
|
|
|
else:
|
|
|
|
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-12 05:43:28 -05:00
|
|
|
def __init__(self, sys_clk_freq=int(10e6), with_led_chaser=True, with_gpioin=True, **kwargs):
|
2021-10-01 04:58:16 -04:00
|
|
|
platform = quicklogic_quickfeather.Platform()
|
|
|
|
|
|
|
|
# SoCCore ----------------------------------------------------------------------------------
|
2021-11-09 12:57:24 -05:00
|
|
|
if kwargs.get("cpu_type", None) == "eos-s3":
|
|
|
|
is_eoss3_cpu = True
|
|
|
|
else:
|
|
|
|
is_eoss3_cpu = False
|
|
|
|
kwargs["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-09 12:57:24 -05:00
|
|
|
self.submodules.crg = _CRG(platform, is_eoss3_cpu)
|
2021-10-01 04:58:16 -04:00
|
|
|
|
2021-11-12 05:43:28 -05:00
|
|
|
# GPIOIn -> interrupt test
|
|
|
|
if with_gpioin:
|
|
|
|
self.submodules.gpio = GPIOIn(
|
|
|
|
pads = platform.request_all("user_btn_n"), with_irq=True)
|
|
|
|
self.add_csr("gpio")
|
|
|
|
self.irq.add("gpio", use_loc_if_exists=True)
|
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-12 05:43:28 -05:00
|
|
|
if is_eoss3_cpu:
|
|
|
|
self.add_csr("leds")
|
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()
|