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
|
|
|
|
|
2022-01-17 04:00:58 -05:00
|
|
|
import os
|
|
|
|
|
|
|
|
from migen import *
|
2021-10-01 04:58:16 -04:00
|
|
|
|
2023-02-23 03:09:33 -05:00
|
|
|
from litex.gen import *
|
2022-10-27 10:58:55 -04:00
|
|
|
|
2021-10-01 04:58:16 -04:00
|
|
|
from litex_boards.platforms import quicklogic_quickfeather
|
|
|
|
|
2022-01-15 11:33:29 -05:00
|
|
|
from litex.soc.integration.soc import SoCRegion
|
2022-01-17 04:00:58 -05:00
|
|
|
from litex.soc.integration.soc_core import *
|
2021-10-01 04:58:16 -04:00
|
|
|
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 ----------------------------------------------------------------------------------------------
|
|
|
|
|
2022-10-27 10:58:55 -04:00
|
|
|
class _CRG(LiteXModule):
|
2021-11-14 03:26:29 -05:00
|
|
|
def __init__(self, platform, with_eos_s3=False):
|
2022-10-27 10:58:55 -04:00
|
|
|
self.rst = Signal()
|
|
|
|
self.cd_sys = ClockDomain()
|
2021-10-01 04:58:16 -04:00
|
|
|
|
|
|
|
# # #
|
|
|
|
|
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):
|
2022-11-08 05:54:17 -05:00
|
|
|
def __init__(self, sys_clk_freq=10e6, with_led_chaser=True, with_gpio_in=True, **kwargs):
|
2021-10-01 04:58:16 -04:00
|
|
|
platform = quicklogic_quickfeather.Platform()
|
|
|
|
|
2022-04-21 06:17:26 -04:00
|
|
|
# CRG --------------------------------------------------------------------------------------
|
2022-10-27 10:58:55 -04:00
|
|
|
self.crg = _CRG(platform, with_eos_s3=kwargs["cpu_type"] == "eos_s3")
|
2022-04-21 06:17:26 -04:00
|
|
|
|
2021-10-01 04:58:16 -04:00
|
|
|
# SoCCore ----------------------------------------------------------------------------------
|
|
|
|
kwargs["with_uart"] = False
|
2022-01-15 11:33:29 -05:00
|
|
|
if kwargs.get("cpu_type", None) == "eos_s3":
|
2022-04-21 09:48:29 -04:00
|
|
|
kwargs["integrated_sram_size"] = 0
|
2022-04-21 06:17:26 -04:00
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq, ident="LiteX SoC on QuickLogic QuickFeather", **kwargs)
|
2022-01-15 11:33:29 -05:00
|
|
|
|
2022-04-21 06:17:26 -04:00
|
|
|
# EOS-S3 Integration -----------------------------------------------------------------------
|
2022-01-15 11:33:29 -05:00
|
|
|
if kwargs.get("cpu_type", None) == "eos_s3":
|
|
|
|
# in fact SRAM starts at 0x2000_0000 - but for some reason
|
|
|
|
# this does not work and most QORC SDK linker scripts
|
|
|
|
# use 0x2002_7000 + 0x0003_c800
|
|
|
|
self.bus.add_region("sram", SoCRegion(
|
2022-04-21 06:17:26 -04:00
|
|
|
origin = 0x2002_7000,
|
|
|
|
size = 0x0003_c800)
|
2022-01-15 11:33:29 -05:00
|
|
|
)
|
|
|
|
self.bus.add_region("rom", SoCRegion(
|
2022-04-21 06:17:26 -04:00
|
|
|
origin = self.mem_map["rom"],
|
|
|
|
size = 4 * 128 * 1024,
|
|
|
|
linker = True)
|
2022-01-15 11:33:29 -05:00
|
|
|
)
|
|
|
|
|
2021-10-01 04:58:16 -04:00
|
|
|
# Leds -------------------------------------------------------------------------------------
|
|
|
|
if with_led_chaser:
|
2022-10-27 10:58:55 -04:00
|
|
|
self.leds = LedChaser(
|
2021-10-01 04:58:16 -04:00
|
|
|
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:
|
2022-10-27 10:58:55 -04:00
|
|
|
self.gpio = GPIOIn(platform.request_all("user_btn_n"), with_irq=True)
|
2022-01-15 11:33:29 -05:00
|
|
|
if kwargs["cpu_type"] == "eos_s3":
|
2021-11-14 03:30:52 -05:00
|
|
|
self.irq.add("gpio", use_loc_if_exists=True)
|
|
|
|
|
2021-10-01 04:58:16 -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=quicklogic_quickfeather.Platform, description="LiteX SoC on QuickLogic QuickFeather.")
|
2022-01-15 11:33:29 -05:00
|
|
|
parser.set_defaults(cpu_type="eos_s3")
|
2021-10-01 04:58:16 -04:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2022-11-07 02:43:26 -05:00
|
|
|
soc = BaseSoC(**parser.soc_argdict)
|
2022-01-15 11:33:29 -05:00
|
|
|
builder = Builder(soc)
|
|
|
|
if args.cpu_type == "eos_s3":
|
2022-01-20 12:43:59 -05:00
|
|
|
libeos_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "libeos")
|
|
|
|
if not os.path.exists(libeos_path):
|
|
|
|
os.system("wget -nc https://github.com/litex-hub/litex-boards/files/7880350/libeos.zip")
|
|
|
|
os.system(f"unzip libeos.zip -d {libeos_path}")
|
|
|
|
builder.add_software_package("libeos", src_dir=libeos_path)
|
2022-01-15 11:33:29 -05:00
|
|
|
builder.add_software_library("libeos")
|
2022-05-06 09:14:32 -04:00
|
|
|
if args.build:
|
2022-11-05 03:07:14 -04:00
|
|
|
builder.build(**parser.toolchain_argdict)
|
2021-10-01 04:58:16 -04:00
|
|
|
|
2022-01-15 11:33:29 -05:00
|
|
|
|
2021-10-01 04:58:16 -04:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|