2022-02-25 08:22:19 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
#
|
|
|
|
# This file is part of LiteX-Boards.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2020 Florent Kermarrec <florent@enjoy-digital.fr>
|
|
|
|
# Copyright (c) 2021 Omkar Bhilare <ombhilare999@gmail.com>
|
|
|
|
# Copyright (c) 2021 Michael Welling <mwelling@ieee.org>
|
|
|
|
# Copyright (c) 2022 Lone Dynamics Corporation <info@lonedynamics.com>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
#
|
|
|
|
# Krote FPGA board: https://github.com/machdyne/krote
|
|
|
|
#
|
|
|
|
# TODO:
|
|
|
|
# - add support for QQSPI PSRAM (32MB) pmod
|
|
|
|
# - add support for SD card pmod
|
|
|
|
#
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from migen import *
|
|
|
|
|
2023-02-23 03:09:33 -05:00
|
|
|
from litex.gen import *
|
2022-10-27 10:58:55 -04:00
|
|
|
|
2022-02-25 08:22:19 -05:00
|
|
|
from litex.build.io import CRG
|
|
|
|
|
2022-07-15 11:13:00 -04:00
|
|
|
from litex_boards.platforms import machdyne_krote
|
2022-02-25 08:22:19 -05:00
|
|
|
|
|
|
|
from litex.soc.integration.soc_core import *
|
|
|
|
from litex.soc.integration.soc import SoCRegion
|
|
|
|
from litex.soc.integration.builder import *
|
|
|
|
from litex.soc.cores.clock import iCE40PLL
|
|
|
|
from litex.soc.cores.led import LedChaser
|
|
|
|
|
|
|
|
from migen.genlib.resetsync import AsyncResetSynchronizer
|
|
|
|
|
2022-11-08 04:41:35 -05:00
|
|
|
# _CRG ---------------------------------------------------------------------------------------------
|
|
|
|
|
2022-10-27 10:58:55 -04:00
|
|
|
class _CRG(LiteXModule):
|
2022-02-25 08:22:19 -05:00
|
|
|
def __init__(self, platform, sys_clk_freq):
|
2022-10-27 10:58:55 -04:00
|
|
|
self.rst = Signal()
|
|
|
|
self.cd_sys = ClockDomain()
|
|
|
|
self.cd_por = ClockDomain(reset_less=True)
|
2022-02-25 08:22:19 -05:00
|
|
|
|
|
|
|
# Clk/Rst
|
|
|
|
clk100 = platform.request("clk100")
|
|
|
|
platform.add_period_constraint(clk100, 1e9/100e6)
|
|
|
|
|
|
|
|
# Power On Reset
|
|
|
|
por_count = Signal(16, reset=2**16-1)
|
|
|
|
por_done = Signal()
|
|
|
|
self.comb += self.cd_por.clk.eq(clk100)
|
|
|
|
self.comb += por_done.eq(por_count == 0)
|
|
|
|
self.sync.por += If(~por_done, por_count.eq(por_count - 1))
|
|
|
|
|
|
|
|
# Sys Clk
|
2022-10-27 10:58:55 -04:00
|
|
|
self.pll = pll = iCE40PLL()
|
2022-02-25 08:22:19 -05:00
|
|
|
pll.register_clkin(clk100, 100e6)
|
|
|
|
pll.create_clkout(self.cd_sys, sys_clk_freq, with_reset=False)
|
|
|
|
self.specials += AsyncResetSynchronizer(self.cd_sys, ~por_done | ~pll.locked)
|
|
|
|
platform.add_period_constraint(self.cd_sys.clk, 1e9/sys_clk_freq)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# BaseSoC ------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class BaseSoC(SoCCore):
|
|
|
|
mem_map = {**SoCCore.mem_map, **{"spiflash": 0x20000000}}
|
2022-11-08 05:54:17 -05:00
|
|
|
def __init__(self, bios_flash_offset, sys_clk_freq=100e6, with_led_chaser=True, **kwargs):
|
2022-07-15 11:13:00 -04:00
|
|
|
platform = machdyne_krote.Platform()
|
2022-02-25 08:22:19 -05:00
|
|
|
|
|
|
|
# Disable Integrated ROM since too large for iCE40.
|
|
|
|
kwargs["integrated_rom_size"] = 0
|
2024-06-13 04:04:19 -04:00
|
|
|
kwargs["integrated_sram_size"] = 4 * KILOBYTE
|
2022-02-25 08:22:19 -05:00
|
|
|
|
|
|
|
# Set CPU variant / reset address
|
|
|
|
kwargs["cpu_reset_address"] = self.mem_map["spiflash"] + bios_flash_offset
|
|
|
|
|
|
|
|
# SoCCore ----------------------------------------------------------------------------------
|
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq,
|
|
|
|
ident = "LiteX SoC on Kr\xf6te",
|
|
|
|
**kwargs)
|
|
|
|
|
|
|
|
# CRG --------------------------------------------------------------------------------------
|
2022-10-27 10:58:55 -04:00
|
|
|
self.crg = _CRG(platform, sys_clk_freq)
|
2022-02-25 08:22:19 -05:00
|
|
|
|
|
|
|
# SPI Flash --------------------------------------------------------------------------------
|
|
|
|
from litespi.modules import W25Q32
|
|
|
|
from litespi.opcodes import SpiNorFlashOpCodes as Codes
|
|
|
|
self.add_spi_flash(mode="1x", module=W25Q32(Codes.READ_1_1_1), with_master=False)
|
|
|
|
|
|
|
|
# Add ROM linker region --------------------------------------------------------------------
|
|
|
|
self.bus.add_region("rom", SoCRegion(
|
|
|
|
origin = self.mem_map["spiflash"] + bios_flash_offset,
|
2024-06-13 04:04:19 -04:00
|
|
|
size = 32 * KILOBYTE,
|
2022-02-25 08:22:19 -05:00
|
|
|
linker = True)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Leds -------------------------------------------------------------------------------------
|
|
|
|
if with_led_chaser:
|
2022-10-27 10:58:55 -04:00
|
|
|
self.leds = LedChaser(
|
2022-02-25 08:22:19 -05:00
|
|
|
pads = platform.request_all("user_led"),
|
|
|
|
sys_clk_freq = sys_clk_freq)
|
|
|
|
|
|
|
|
# Build --------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def main():
|
2022-11-06 16:07:17 -05:00
|
|
|
from litex.build.parser import LiteXArgumentParser
|
2022-11-08 04:41:35 -05:00
|
|
|
parser = LiteXArgumentParser(platform=machdyne_krote.Platform, description="LiteX SoC on Kr\xf6te.")
|
|
|
|
parser.add_argument("--bios-flash-offset", default="0x021000", help="BIOS offset in SPI Flash (default: 0x21000)")
|
|
|
|
parser.add_argument("--sys-clk-freq", default=50e6, type=float, help="System clock frequency (default: 50MHz)")
|
|
|
|
parser.add_argument("--with-led-chaser", action="store_true", help="Enable LED Chaser.")
|
2022-02-25 08:22:19 -05:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
soc = BaseSoC(
|
|
|
|
bios_flash_offset = int(args.bios_flash_offset, 0),
|
2022-11-08 04:41:35 -05:00
|
|
|
sys_clk_freq = args.sys_clk_freq,
|
2022-11-07 02:43:26 -05:00
|
|
|
**parser.soc_argdict
|
2022-02-25 08:22:19 -05:00
|
|
|
)
|
2022-11-05 03:07:14 -04:00
|
|
|
builder = Builder(soc, **parser.builder_argdict)
|
2022-07-19 06:17:14 -04:00
|
|
|
if args.build:
|
2022-11-05 03:07:14 -04:00
|
|
|
builder.build(**parser.toolchain_argdict)
|
2022-02-25 08:22:19 -05:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|