Skip to content

Commit 750cbf8

Browse files
committed
Added Digilent Genesys2 target
1 parent 912f983 commit 750cbf8

File tree

1 file changed

+167
-0
lines changed

1 file changed

+167
-0
lines changed

misoc/targets/digilent_genesys2.py

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
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 <[email protected]>
7+
# Copyright (c) 2022 Mikolaj Sowinski <[email protected]>
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+
16+
from misoc.cores.sdram_settings import MT41J256M16
17+
from misoc.cores.sdram_phy import k7ddrphy
18+
from misoc.cores import spi_flash, icap
19+
from misoc.cores.liteeth_mini.phy.s7rgmii import LiteEthPHYRGMII
20+
from misoc.cores.liteeth_mini.mac import LiteEthMAC
21+
from misoc.integration.soc_sdram import *
22+
from misoc.integration.builder import *
23+
24+
25+
class _CRG(Module):
26+
def __init__(self, platform):
27+
self.clock_domains.cd_sys = ClockDomain()
28+
self.clock_domains.cd_sys4x = ClockDomain(reset_less=True)
29+
self.clock_domains.cd_clk200 = ClockDomain()
30+
31+
clk200 = platform.request("clk200")
32+
clk200_se = Signal()
33+
self.specials += Instance("IBUFDS", i_I=clk200.p, i_IB=clk200.n, o_O=clk200_se)
34+
35+
rst = platform.request("cpu_reset_n")
36+
37+
pll_locked = Signal()
38+
pll_fb = Signal()
39+
pll_sys = Signal()
40+
pll_sys4x = Signal()
41+
pll_clk200 = Signal()
42+
self.specials += [
43+
Instance("PLLE2_BASE",
44+
p_STARTUP_WAIT="FALSE", o_LOCKED=pll_locked,
45+
46+
# VCO @ 1GHz
47+
p_REF_JITTER1=0.01, p_CLKIN1_PERIOD=5.0,
48+
p_CLKFBOUT_MULT=5, p_DIVCLK_DIVIDE=1,
49+
i_CLKIN1=clk200_se, i_CLKFBIN=pll_fb, o_CLKFBOUT=pll_fb,
50+
51+
# 125MHz
52+
p_CLKOUT0_DIVIDE=8, p_CLKOUT0_PHASE=0.0, o_CLKOUT0=pll_sys,
53+
54+
# 500MHz
55+
p_CLKOUT1_DIVIDE=2, p_CLKOUT1_PHASE=0.0, o_CLKOUT1=pll_sys4x,
56+
57+
# 200MHz
58+
p_CLKOUT2_DIVIDE=5, p_CLKOUT2_PHASE=0.0, o_CLKOUT2=pll_clk200,
59+
60+
p_CLKOUT3_DIVIDE=2, p_CLKOUT3_PHASE=0.0, #o_CLKOUT3=,
61+
62+
p_CLKOUT4_DIVIDE=4, p_CLKOUT4_PHASE=0.0, #o_CLKOUT4=
63+
),
64+
Instance("BUFG", i_I=pll_sys, o_O=self.cd_sys.clk),
65+
Instance("BUFG", i_I=pll_sys4x, o_O=self.cd_sys4x.clk),
66+
Instance("BUFG", i_I=pll_clk200, o_O=self.cd_clk200.clk),
67+
AsyncResetSynchronizer(self.cd_sys, ~pll_locked | ~rst),
68+
AsyncResetSynchronizer(self.cd_clk200, ~pll_locked | ~rst),
69+
]
70+
71+
reset_counter = Signal(4, reset=15)
72+
ic_reset = Signal(reset=1)
73+
self.sync.clk200 += \
74+
If(reset_counter != 0,
75+
reset_counter.eq(reset_counter - 1)
76+
).Else(
77+
ic_reset.eq(0)
78+
)
79+
self.specials += Instance("IDELAYCTRL", i_REFCLK=ClockSignal("clk200"), i_RST=ic_reset)
80+
81+
self.comb += platform.request("user_led", 7).eq(ResetSignal())
82+
83+
84+
class BaseSoC(SoCSDRAM):
85+
def __init__(self, sdram_controller_type="minicon", **kwargs):
86+
platform = digilent_genesys2.Platform()
87+
SoCSDRAM.__init__(self, platform,
88+
clk_freq=125*1000000, cpu_reset_address=0xaf0000,
89+
**kwargs)
90+
91+
self.submodules.crg = _CRG(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+
115+
self.submodules.icap = icap.ICAP("7series")
116+
self.csr_devices.append("icap")
117+
118+
119+
class MiniSoC(BaseSoC):
120+
mem_map = {
121+
"ethmac": 0x30000000, # (shadow @0xb0000000)
122+
}
123+
mem_map.update(BaseSoC.mem_map)
124+
125+
def __init__(self, *args, ethmac_nrxslots=2, ethmac_ntxslots=2, **kwargs):
126+
BaseSoC.__init__(self, *args, **kwargs)
127+
128+
self.csr_devices += ["ethphy", "ethmac"]
129+
self.interrupt_devices.append("ethmac")
130+
131+
eth_clocks = self.platform.request("eth_clocks")
132+
eth_pads = self.platform.request("eth")
133+
134+
self.comb += eth_pads.rst_n.eq(1)
135+
136+
self.submodules.ethphy = LiteEthPHYRGMII(eth_clocks, eth_pads)
137+
self.platform.add_false_path_constraints(
138+
self.crg.cd_sys.clk,
139+
self.ethphy.crg.cd_eth_tx.clk, eth_clocks.rx)
140+
self.platform.add_period_constraint(self.ethphy.crg.cd_eth_tx.clk, 8.)
141+
self.platform.add_period_constraint(self.ethphy.crg.cd_eth_rx.clk, 8.)
142+
143+
self.submodules.ethmac = LiteEthMAC(phy=self.ethphy, dw=self.cpu_dw, interface="wishbone",
144+
endianness=self.cpu.endianness,
145+
nrxslots=ethmac_nrxslots, ntxslots=ethmac_ntxslots)
146+
ethmac_len = (ethmac_nrxslots + ethmac_ntxslots) * 0x800
147+
self.add_wb_slave(self.mem_map["ethmac"], ethmac_len, self.ethmac.bus)
148+
self.add_memory_region("ethmac", self.mem_map["ethmac"] | self.shadow_base,
149+
ethmac_len)
150+
151+
152+
def main():
153+
parser = argparse.ArgumentParser(description="MiSoC port to the Digilent Genesys2")
154+
builder_args(parser)
155+
soc_sdram_args(parser)
156+
parser.add_argument("--with-ethernet", action="store_true",
157+
help="enable Ethernet support")
158+
args = parser.parse_args()
159+
160+
cls = MiniSoC if args.with_ethernet else BaseSoC
161+
soc = cls(**soc_sdram_argdict(args)(args))
162+
builder = Builder(soc, **builder_argdict(args))
163+
builder.build()
164+
165+
166+
if __name__ == "__main__":
167+
main()

0 commit comments

Comments
 (0)