2021-07-18 00:03:17 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
#
|
|
|
|
# This file is part of LiteX-Boards.
|
|
|
|
#
|
2021-07-27 06:21:23 -04:00
|
|
|
# Copyright (c) 2021 Michael T. Mayers <michael@tweakoz.com>
|
2021-07-18 00:03:17 -04:00
|
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
|
|
from migen import *
|
|
|
|
|
2023-02-23 03:09:33 -05:00
|
|
|
from litex.gen import *
|
2022-10-27 10:58:55 -04:00
|
|
|
|
2021-07-18 00:03:17 -04:00
|
|
|
from litex.build.io import CRG
|
|
|
|
|
|
|
|
from litex_boards.platforms import digilent_cmod_a7
|
|
|
|
|
|
|
|
from litex.soc.cores.clock import *
|
|
|
|
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.interconnect import wishbone
|
|
|
|
|
|
|
|
from litex.soc.integration.soc import colorer
|
|
|
|
|
2024-06-13 04:04:19 -04:00
|
|
|
# CRG ----------------------------------------------------------------------------------------------
|
2021-07-18 00:03:17 -04:00
|
|
|
|
2022-10-27 10:58:55 -04:00
|
|
|
class _CRG(LiteXModule):
|
2021-07-18 00:03:17 -04:00
|
|
|
def __init__(self, platform, sys_clk_freq):
|
2022-10-27 10:58:55 -04:00
|
|
|
self.rst = Signal()
|
|
|
|
self.cd_sys = ClockDomain()
|
2021-07-18 00:03:17 -04:00
|
|
|
|
|
|
|
# # #
|
|
|
|
|
2022-01-19 04:03:20 -05:00
|
|
|
# Clk/Rst.
|
|
|
|
clk12 = platform.request("clk12")
|
|
|
|
rst = platform.request("cpu_reset")
|
2021-07-18 00:03:17 -04:00
|
|
|
|
2022-01-19 04:03:20 -05:00
|
|
|
# PLL.
|
2022-10-27 10:58:55 -04:00
|
|
|
self.pll = pll = S7MMCM(speedgrade=-1)
|
2022-01-19 04:03:20 -05:00
|
|
|
self.comb += pll.reset.eq(rst | self.rst)
|
|
|
|
pll.register_clkin(clk12, 12e6)
|
|
|
|
pll.create_clkout(self.cd_sys, sys_clk_freq)
|
2021-07-18 00:03:17 -04:00
|
|
|
platform.add_false_path_constraints(self.cd_sys.clk, pll.clkin) # Ignore sys_clk to pll.clkin path created by SoC's rst.
|
|
|
|
|
|
|
|
# AsyncSRAM ------------------------------------------------------------------------------------------
|
|
|
|
|
2022-10-27 10:58:55 -04:00
|
|
|
class AsyncSRAM(LiteXModule):
|
2021-07-18 00:03:17 -04:00
|
|
|
def __init__(self, platform, size):
|
|
|
|
addr_width = size//8
|
|
|
|
data_width = 8
|
|
|
|
self.bus = wishbone.Interface(data_width=data_width,adr_width=addr_width)
|
|
|
|
issiram = platform.request("issiram")
|
|
|
|
addr = issiram.addr
|
|
|
|
data = issiram.data
|
|
|
|
wen = issiram.wen
|
|
|
|
cen = issiram.cen
|
2023-08-05 13:56:32 -04:00
|
|
|
oe = issiram.oe
|
2021-07-18 00:03:17 -04:00
|
|
|
########################
|
|
|
|
tristate_data = TSTriple(data_width)
|
|
|
|
self.specials += tristate_data.get_tristate(data)
|
|
|
|
########################
|
|
|
|
chip_ena = self.bus.cyc & self.bus.stb & self.bus.sel[0]
|
|
|
|
write_ena = (chip_ena & self.bus.we)
|
|
|
|
########################
|
|
|
|
# external write enable,
|
|
|
|
# external chip enable,
|
|
|
|
# internal tristate write enable
|
|
|
|
########################
|
|
|
|
self.comb += [
|
|
|
|
cen.eq(~chip_ena),
|
|
|
|
wen.eq(~write_ena),
|
2023-08-05 13:56:15 -04:00
|
|
|
tristate_data.oe.eq(write_ena),
|
|
|
|
oe.eq(tristate_data.oe),
|
2021-07-18 00:03:17 -04:00
|
|
|
]
|
|
|
|
########################
|
|
|
|
# address and data
|
|
|
|
########################
|
|
|
|
self.comb += [
|
|
|
|
addr.eq(self.bus.adr[:addr_width]),
|
|
|
|
self.bus.dat_r.eq(tristate_data.i[:data_width]),
|
|
|
|
tristate_data.o.eq(self.bus.dat_w[:data_width])
|
|
|
|
]
|
|
|
|
########################
|
|
|
|
# generate ack
|
|
|
|
########################
|
|
|
|
self.sync += [
|
|
|
|
self.bus.ack.eq(self.bus.cyc & self.bus.stb & ~self.bus.ack),
|
|
|
|
]
|
|
|
|
########################
|
|
|
|
|
|
|
|
def addAsyncSram(soc, platform, name, origin, size):
|
|
|
|
ram_bus = wishbone.Interface(data_width=soc.bus.data_width)
|
|
|
|
ram = AsyncSRAM(platform,size)
|
|
|
|
soc.bus.add_slave(name, ram.bus, SoCRegion(origin=origin, size=size, mode="rw"))
|
|
|
|
soc.check_if_exists(name)
|
|
|
|
soc.logger.info("ISSIRAM {} {} {}.".format(
|
|
|
|
colorer(name),
|
|
|
|
colorer("added", color="green"),
|
|
|
|
soc.bus.regions[name]))
|
|
|
|
setattr(soc.submodules, name, ram)
|
|
|
|
|
|
|
|
# BaseSoC ------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class BaseSoC(SoCCore):
|
2021-07-27 08:55:19 -04:00
|
|
|
def __init__(self, variant="a7-35",
|
2022-01-18 11:13:02 -05:00
|
|
|
toolchain = "vivado",
|
2022-11-08 05:54:17 -05:00
|
|
|
sys_clk_freq = 100e6,
|
2022-01-18 11:13:02 -05:00
|
|
|
with_led_chaser = True,
|
2022-01-22 21:50:12 -05:00
|
|
|
with_spi_flash = False,
|
2022-01-18 11:13:02 -05:00
|
|
|
**kwargs):
|
2021-07-18 00:03:17 -04:00
|
|
|
|
2022-01-16 05:58:14 -05:00
|
|
|
platform = digilent_cmod_a7.Platform(variant=variant, toolchain=toolchain)
|
2021-07-18 00:03:17 -04:00
|
|
|
|
|
|
|
# CRG --------------------------------------------------------------------------------------
|
2022-10-27 10:58:55 -04:00
|
|
|
self.crg = _CRG(platform, sys_clk_freq)
|
2021-07-18 00:03:17 -04:00
|
|
|
|
2022-04-21 06:17:26 -04:00
|
|
|
# SoCCore ----------------------------------------------------------------------------------
|
|
|
|
SoCCore.__init__(self, platform, sys_clk_freq, ident="LiteX SoC on Digilent CmodA7", **kwargs)
|
|
|
|
|
|
|
|
# Async RAM --------------------------------------------------------------------------------
|
2024-08-29 06:17:24 -04:00
|
|
|
addAsyncSram(self,platform,"main_ram", 0x40000000, 512 * KILOBYTE)
|
2021-07-18 00:03:17 -04:00
|
|
|
|
|
|
|
# Leds -------------------------------------------------------------------------------------
|
2021-07-27 09:00:18 -04:00
|
|
|
if with_led_chaser:
|
2022-10-27 10:58:55 -04:00
|
|
|
self.leds = LedChaser(
|
2021-07-27 09:00:18 -04:00
|
|
|
pads = platform.request_all("user_led"),
|
|
|
|
sys_clk_freq = sys_clk_freq)
|
2021-07-18 00:03:17 -04:00
|
|
|
|
2022-01-22 21:50:12 -05:00
|
|
|
# SPI Flash --------------------------------------------------------------------------------
|
|
|
|
if with_spi_flash:
|
|
|
|
from litespi.modules import MX25U3235F
|
|
|
|
from litespi.opcodes import SpiNorFlashOpCodes as Codes
|
|
|
|
self.add_spi_flash(mode="4x", module=MX25U3235F(Codes.READ_1_1_4), with_master=True)
|
|
|
|
|
2021-07-18 00:03:17 -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=digilent_cmod_a7.Platform, description="LiteX SoC on CMOD A7.")
|
|
|
|
parser.add_target_argument("--flash", action="store_true", help="Flash bitstream.")
|
|
|
|
parser.add_target_argument("--variant", default="a7-35", help="Board variant (a7-35 or a7-100).")
|
|
|
|
parser.add_target_argument("--sys-clk-freq", default=48e6, type=float, help="System clock frequency.")
|
|
|
|
parser.add_target_argument("--with-spi-flash", action="store_true", help="Enable SPI Flash (MMAPed).")
|
2022-11-05 03:07:14 -04:00
|
|
|
|
|
|
|
|
2021-07-18 00:03:17 -04:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
soc = BaseSoC(
|
2022-11-08 04:41:35 -05:00
|
|
|
variant = args.variant,
|
|
|
|
toolchain = args.toolchain,
|
|
|
|
sys_clk_freq = args.sys_clk_freq,
|
|
|
|
with_spi_flash = args.with_spi_flash,
|
2022-11-07 02:43:26 -05:00
|
|
|
**parser.soc_argdict
|
2021-07-18 00:03:17 -04:00
|
|
|
)
|
|
|
|
|
2022-11-05 03:07:14 -04:00
|
|
|
builder_argd = parser.builder_argdict
|
2021-07-18 00:03:17 -04:00
|
|
|
|
|
|
|
builder = Builder(soc, **builder_argd)
|
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-07-18 00:03:17 -04:00
|
|
|
|
2022-01-20 23:54:03 -05:00
|
|
|
if args.load:
|
|
|
|
prog = soc.platform.create_programmer()
|
2022-03-17 04:21:05 -04:00
|
|
|
prog.load_bitstream(builder.get_bitstream_filename(mode="sram"))
|
2022-01-20 23:54:03 -05:00
|
|
|
|
2022-01-22 21:50:12 -05:00
|
|
|
if args.flash:
|
|
|
|
prog = soc.platform.create_programmer()
|
2022-03-17 04:21:05 -04:00
|
|
|
prog.flash(0, builder.get_bitstream_filename(mode="flash"))
|
2022-01-22 21:50:12 -05:00
|
|
|
|
2021-07-18 00:03:17 -04:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|