Skip to content

Commit 1a58411

Browse files
committed
Added Digilent Genesys2 target
1 parent 4d180bf commit 1a58411

File tree

1 file changed

+164
-0
lines changed

1 file changed

+164
-0
lines changed

misoc/targets/digilent_genesys2.py

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#!/usr/bin/env python3
2+
3+
#
4+
# This file is based on LiteX-Boards Digilent Genesys 2 target.
5+
#
6+
# Copyright (c) 2019 Florent Kermarrec <florent@enjoy-digital.fr>
7+
# Copyright (c) 2023 Mikolaj Sowinski <msowinski@technosystem.com.pl>
8+
# SPDX-License-Identifier: BSD-2-Clause
9+
10+
import argparse
11+
12+
from migen import *
13+
from migen.genlib.resetsync import AsyncResetSynchronizer
14+
from migen.build.platforms import digilent_genesys2
15+
from migen.genlib.cdc import MultiReg
16+
17+
from misoc.cores.sdram_settings import MT41J256M16
18+
from misoc.cores.sdram_phy import k7ddrphy
19+
from misoc.cores import spi_flash, icap
20+
from misoc.cores.liteeth_mini.phy.s7rgmii import LiteEthPHYRGMII
21+
from misoc.cores.liteeth_mini.mac import LiteEthMAC
22+
from misoc.integration.soc_sdram import *
23+
from misoc.integration.builder import *
24+
from misoc.interconnect.csr import *
25+
26+
27+
class _SysCRG(Module):
28+
def __init__(self, platform):
29+
self.clock_domains.cd_sys = ClockDomain()
30+
self.clock_domains.cd_sys4x = ClockDomain(reset_less=True)
31+
self.clock_domains.cd_clk200 = ClockDomain()
32+
33+
clk200 = platform.request("clk200")
34+
clk200_se = Signal()
35+
self.specials += Instance("IBUFDS", i_I=clk200.p, i_IB=clk200.n, o_O=clk200_se)
36+
37+
rst_n = platform.request("cpu_reset_n")
38+
39+
pll_locked = Signal()
40+
pll_fb = Signal()
41+
pll_sys = Signal()
42+
pll_sys4x = Signal()
43+
pll_clk200 = Signal()
44+
self.specials += [
45+
Instance("PLLE2_BASE",
46+
p_STARTUP_WAIT="FALSE", o_LOCKED=pll_locked,
47+
48+
# VCO @ 1GHz
49+
p_REF_JITTER1=0.01, p_CLKIN1_PERIOD=5.0,
50+
p_CLKFBOUT_MULT=5, p_DIVCLK_DIVIDE=1,
51+
i_CLKIN1=clk200_se, i_CLKFBIN=pll_fb, o_CLKFBOUT=pll_fb,
52+
53+
# 125MHz
54+
p_CLKOUT0_DIVIDE=8, p_CLKOUT0_PHASE=0.0, o_CLKOUT0=pll_sys,
55+
56+
# 500MHz
57+
p_CLKOUT1_DIVIDE=2, p_CLKOUT1_PHASE=0.0, o_CLKOUT1=pll_sys4x,
58+
59+
# 200MHz
60+
p_CLKOUT2_DIVIDE=5, p_CLKOUT2_PHASE=0.0, o_CLKOUT2=pll_clk200,
61+
62+
p_CLKOUT3_DIVIDE=2, p_CLKOUT3_PHASE=0.0, #o_CLKOUT3=,
63+
64+
p_CLKOUT4_DIVIDE=4, p_CLKOUT4_PHASE=0.0, #o_CLKOUT4=
65+
),
66+
Instance("BUFG", i_I=pll_sys, o_O=self.cd_sys.clk),
67+
Instance("BUFG", i_I=pll_sys4x, o_O=self.cd_sys4x.clk),
68+
Instance("BUFG", i_I=pll_clk200, o_O=self.cd_clk200.clk),
69+
AsyncResetSynchronizer(self.cd_sys, ~pll_locked | ~rst_n),
70+
AsyncResetSynchronizer(self.cd_clk200, ~pll_locked | ~rst_n),
71+
]
72+
73+
reset_counter = Signal(4, reset=15)
74+
ic_reset = Signal(reset=1)
75+
self.sync.clk200 += \
76+
If(reset_counter != 0,
77+
reset_counter.eq(reset_counter - 1)
78+
).Else(
79+
ic_reset.eq(0)
80+
)
81+
self.specials += Instance("IDELAYCTRL", i_REFCLK=ClockSignal("clk200"), i_RST=ic_reset)
82+
83+
84+
class BaseSoC(SoCSDRAM):
85+
def __init__(self, sdram_controller_type="minicon", clk_freq=125e6, **kwargs):
86+
platform = digilent_genesys2.Platform()
87+
SoCSDRAM.__init__(self, platform,
88+
clk_freq=clk_freq, cpu_reset_address=0xaf0000,
89+
**kwargs)
90+
91+
self.submodules.crg = _SysCRG(platform)
92+
93+
self.submodules.ddrphy = k7ddrphy.K7DDRPHY(platform.request("ddram"))
94+
self.config["DDRPHY_WLEVEL"] = None
95+
sdram_module = MT41J256M16(self.clk_freq, "1:4")
96+
self.register_sdram(self.ddrphy, sdram_controller_type,
97+
sdram_module.geom_settings, sdram_module.timing_settings)
98+
self.csr_devices.append("ddrphy")
99+
100+
if not self.integrated_rom_size:
101+
spiflash_pads = platform.request("spiflash")
102+
spiflash_pads.clk = Signal()
103+
self.specials += Instance("STARTUPE2",
104+
i_CLK=0, i_GSR=0, i_GTS=0, i_KEYCLEARB=0, i_PACK=0,
105+
i_USRCCLKO=spiflash_pads.clk, i_USRCCLKTS=0, i_USRDONEO=1, i_USRDONETS=1)
106+
self.submodules.spiflash = spi_flash.SpiFlash(
107+
spiflash_pads, dummy=8, div=4,
108+
endianness=self.cpu.endianness, dw=self.cpu_dw)
109+
self.config["SPIFLASH_PAGE_SIZE"] = 256
110+
self.config["SPIFLASH_SECTOR_SIZE"] = 0x10000
111+
self.flash_boot_address = 0xb40000
112+
self.register_rom(self.spiflash.bus, 16*1024*1024)
113+
self.csr_devices.append("spiflash")
114+
self.submodules.icap = icap.ICAP("7series")
115+
self.csr_devices.append("icap")
116+
117+
118+
class MiniSoC(BaseSoC):
119+
mem_map = {
120+
"ethmac": 0x30000000, # (shadow @0xb0000000)
121+
}
122+
mem_map.update(BaseSoC.mem_map)
123+
124+
def __init__(self, *args, ethmac_nrxslots=2, ethmac_ntxslots=2, **kwargs):
125+
BaseSoC.__init__(self, *args, **kwargs)
126+
127+
self.csr_devices += ["ethphy", "ethmac"]
128+
self.interrupt_devices.append("ethmac")
129+
130+
eth_clocks = self.platform.request("eth_clocks")
131+
eth_pads = self.platform.request("eth")
132+
self.comb += eth_pads.rst_n.eq(1)
133+
self.submodules.ethphy = LiteEthPHYRGMII(eth_clocks, eth_pads)
134+
self.platform.add_period_constraint(self.ethphy.crg.cd_eth_tx.clk, 8.)
135+
self.platform.add_period_constraint(self.ethphy.crg.cd_eth_rx.clk, 8.)
136+
self.submodules.ethmac = LiteEthMAC(phy=self.ethphy, dw=self.cpu_dw, interface="wishbone",
137+
endianness=self.cpu.endianness,
138+
nrxslots=ethmac_nrxslots, ntxslots=ethmac_ntxslots)
139+
ethmac_len = (ethmac_nrxslots + ethmac_ntxslots) * 0x800
140+
self.add_wb_slave(self.mem_map["ethmac"], ethmac_len, self.ethmac.bus)
141+
self.add_memory_region("ethmac", self.mem_map["ethmac"] | self.shadow_base,
142+
ethmac_len)
143+
144+
self.platform.add_false_path_constraints(
145+
self.crg.cd_sys.clk,
146+
self.ethphy.crg.cd_eth_tx.clk, eth_clocks.rx)
147+
148+
149+
def main():
150+
parser = argparse.ArgumentParser(description="MiSoC port to the Digilent Genesys2")
151+
builder_args(parser)
152+
soc_sdram_args(parser)
153+
parser.add_argument("--with-ethernet", action="store_true",
154+
help="enable Ethernet support")
155+
args = parser.parse_args()
156+
157+
cls = MiniSoC if args.with_ethernet else BaseSoC
158+
soc = cls(**soc_sdram_argdict(args)(args))
159+
builder = Builder(soc, **builder_argdict(args))
160+
builder.build()
161+
162+
163+
if __name__ == "__main__":
164+
main()

0 commit comments

Comments
 (0)