2021-08-16 10:44:45 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
#
|
|
|
|
# This file is part of LiteX-Boards.
|
|
|
|
# Copyright (c) 2021 Omkar Bhilare <ombhilare999@gmail.com>
|
|
|
|
# Copyright (c) 2021 Michael Welling <mwelling@ieee.org>
|
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
from migen import *
|
|
|
|
from migen.genlib.resetsync import AsyncResetSynchronizer
|
|
|
|
|
2022-10-27 10:58:55 -04:00
|
|
|
from litex.gen import LiteXModule
|
|
|
|
|
2022-05-02 06:42:04 -04:00
|
|
|
from litex_boards.platforms import qwertyembedded_beaglewire
|
2021-08-16 10:44:45 -04:00
|
|
|
|
2021-09-01 04:18:11 -04:00
|
|
|
from litex.build.io import DDROutput
|
|
|
|
|
2021-08-16 10:44:45 -04:00
|
|
|
from litex.soc.cores.clock import iCE40PLL
|
|
|
|
from litex.soc.integration.soc_core import *
|
|
|
|
from litex.soc.integration.soc import SoCRegion
|
|
|
|
from litex.soc.integration.builder import *
|
|
|
|
from litex.soc.cores.led import LedChaser
|
|
|
|
from litex.soc.cores.uart import UARTWishboneBridge
|
2021-09-01 04:18:11 -04:00
|
|
|
|
2021-08-16 10:44:45 -04:00
|
|
|
from litedram.phy import GENSDRPHY
|
|
|
|
from litedram.modules import MT48LC32M8
|
|
|
|
|
|
|
|
kB = 1024
|
|
|
|
mB = 1024*kB
|
|
|
|
|
|
|
|
# CRG ----------------------------------------------------------------------------------------------
|
|
|
|
|
2022-10-27 10:58:55 -04:00
|
|
|
class _CRG(LiteXModule):
|
2021-08-16 10:44:45 -04: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()
|
2021-08-16 10:44:45 -04:00
|
|
|
|
|
|
|
# # #
|
|
|
|
|
|
|
|
# Clk/Rst
|
|
|
|
clk100 = platform.request("clk100")
|
2021-09-01 04:18:11 -04:00
|
|
|
rst_n = platform.request("user_btn_n")
|
2021-08-16 10:44:45 -04:00
|
|
|
|
|
|
|
# Power On Reset
|
|
|
|
por_count = Signal(16, reset=2**16-1)
|
|
|
|
por_done = Signal()
|
|
|
|
self.comb += self.cd_por.clk.eq(ClockSignal())
|
|
|
|
self.comb += por_done.eq(por_count == 0)
|
|
|
|
self.sync.por += If(~por_done, por_count.eq(por_count - 1))
|
|
|
|
|
|
|
|
# PLL
|
2022-10-27 10:58:55 -04:00
|
|
|
self.pll = pll = iCE40PLL()
|
2021-08-16 10:44:45 -04:00
|
|
|
self.comb += pll.reset.eq(rst_n) # FIXME: Add proper iCE40PLL reset support and add back | self.rst.
|
|
|
|
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)
|
|
|
|
|
|
|
|
# SDRAM clock
|
|
|
|
self.specials += DDROutput(0, 1, platform.request("sdram_clock"), ClockSignal("sys"))
|
|
|
|
|
|
|
|
# BaseSoC ------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class BaseSoC(SoCCore):
|
2022-11-08 05:54:17 -05:00
|
|
|
def __init__(self, bios_flash_offset, sys_clk_freq=50e6, **kwargs):
|
2022-05-02 06:42:04 -04:00
|
|
|
platform = qwertyembedded_beaglewire.Platform()
|
2021-08-16 10:44:45 -04:00
|
|
|
|
|
|
|
# Disable Integrated ROM since too large for iCE40.
|
|
|
|
kwargs["integrated_rom_size"] = 0
|
2021-09-01 04:18:11 -04:00
|
|
|
kwargs["integrated_sram_size"] = 2*kB
|
2021-08-16 10:44:45 -04:00
|
|
|
|
|
|
|
# CRG --------------------------------------------------------------------------------------
|
2022-10-27 10:58:55 -04:00
|
|
|
self.crg = _CRG(platform, sys_clk_freq)
|
2021-08-16 10:44:45 -04:00
|
|
|
|
2022-04-21 06:17:26 -04:00
|
|
|
# SoCCore ----------------------------------------------------------------------------------
|
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq, ident="LiteX SoC on Beaglewire", **kwargs)
|
|
|
|
|
2021-09-01 04:18:11 -04:00
|
|
|
# SDR SDRAM --------------------------------------------------------------------------------
|
|
|
|
if not self.integrated_main_ram_size:
|
2022-10-27 10:58:55 -04:00
|
|
|
self.sdrphy = GENSDRPHY(platform.request("sdram"), sys_clk_freq)
|
2021-09-01 04:18:11 -04:00
|
|
|
self.add_sdram("sdram",
|
|
|
|
phy = self.sdrphy,
|
|
|
|
module = MT48LC32M8(sys_clk_freq, "1:1"),
|
|
|
|
l2_cache_size = kwargs.get("l2_size", 1024)
|
|
|
|
)
|
2021-08-16 10:44:45 -04:00
|
|
|
|
|
|
|
# SPI Flash --------------------------------------------------------------------------------
|
2022-01-07 13:07:14 -05:00
|
|
|
from litespi.modules import M25PX32
|
|
|
|
from litespi.opcodes import SpiNorFlashOpCodes as Codes
|
|
|
|
self.add_spi_flash(mode="1x", module=M25PX32(Codes.READ_1_1_1), with_master=False)
|
2021-08-16 10:44:45 -04:00
|
|
|
|
|
|
|
# Add ROM linker region --------------------------------------------------------------------
|
|
|
|
self.bus.add_region("rom", SoCRegion(
|
2022-01-07 04:34:47 -05:00
|
|
|
origin = self.bus.regions["spiflash"].origin + bios_flash_offset,
|
2021-08-16 10:44:45 -04:00
|
|
|
size = 32*kB,
|
|
|
|
linker = True)
|
|
|
|
)
|
2022-01-07 09:19:23 -05:00
|
|
|
self.cpu.set_reset_address(self.bus.regions["rom"].origin)
|
2021-08-16 10:44:45 -04:00
|
|
|
|
|
|
|
# Leds -------------------------------------------------------------------------------------
|
2022-10-27 10:58:55 -04:00
|
|
|
self.leds = LedChaser(
|
2021-08-16 10:44:45 -04:00
|
|
|
pads = platform.request_all("user_led"),
|
|
|
|
sys_clk_freq = sys_clk_freq)
|
|
|
|
|
|
|
|
# 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=qwertyembedded_beaglewire.Platform, description="LiteX SoC on Beaglewire.")
|
|
|
|
parser.add_target_argument("--bios-flash-offset", default="0x60000", help="BIOS offset in SPI Flash.")
|
|
|
|
parser.add_target_argument("--sys-clk-freq", default=50e6, type=float, help="System clock frequency.")
|
2021-08-16 10:44:45 -04:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
soc = BaseSoC(
|
2021-12-20 15:41:12 -05:00
|
|
|
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
|
2021-08-16 10:44:45 -04: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)
|
2021-08-16 10:44:45 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|