493fc23c9bbd6d88761cadba8fd5e08b3d7de992
3 # This file is Copyright (c) 2014-2015 Sebastien Bourdeauducq <sb@m-labs.hk>
4 # This file is Copyright (c) 2014-2019 Florent Kermarrec <florent@enjoy-digital.fr>
5 # This file is Copyright (c) 2014-2015 Yann Sionneau <ys@m-labs.hk>
13 from litex
.boards
.platforms
import kc705
15 from litex
.soc
.cores
.clock
import *
16 from litex
.soc
.integration
.soc_core
import *
17 from litex
.soc
.integration
.soc_sdram
import *
18 from litex
.soc
.integration
.builder
import *
19 from litex
.soc
.cores
.led
import LedChaser
21 from litedram
.modules
import MT8JTF12864
22 from litedram
.phy
import s7ddrphy
24 from liteeth
.phy
import LiteEthPHY
26 # CRG ----------------------------------------------------------------------------------------------
29 def __init__(self
, platform
, sys_clk_freq
):
30 self
.clock_domains
.cd_sys
= ClockDomain()
31 self
.clock_domains
.cd_sys4x
= ClockDomain(reset_less
=True)
32 self
.clock_domains
.cd_clk200
= ClockDomain()
36 self
.submodules
.pll
= pll
= S7MMCM(speedgrade
=-2)
37 self
.comb
+= pll
.reset
.eq(platform
.request("cpu_reset"))
38 pll
.register_clkin(platform
.request("clk200"), 200e6
)
39 pll
.create_clkout(self
.cd_sys
, sys_clk_freq
)
40 pll
.create_clkout(self
.cd_sys4x
, 4*sys_clk_freq
)
41 pll
.create_clkout(self
.cd_clk200
, 200e6
)
43 self
.submodules
.idelayctrl
= S7IDELAYCTRL(self
.cd_clk200
)
45 # BaseSoC ------------------------------------------------------------------------------------------
47 class BaseSoC(SoCCore
):
48 def __init__(self
, sys_clk_freq
=int(125e6
), with_ethernet
=False, **kwargs
):
49 platform
= kc705
.Platform()
51 # SoCCore ----------------------------------------------------------------------------------
52 SoCCore
.__init
__(self
, platform
, sys_clk_freq
,
53 ident
= "LiteX SoC on KC705",
57 # CRG --------------------------------------------------------------------------------------
58 self
.submodules
.crg
= _CRG(platform
, sys_clk_freq
)
60 # DDR3 SDRAM -------------------------------------------------------------------------------
61 if not self
.integrated_main_ram_size
:
62 self
.submodules
.ddrphy
= s7ddrphy
.K7DDRPHY(platform
.request("ddram"),
65 sys_clk_freq
= sys_clk_freq
,
67 self
.add_csr("ddrphy")
68 self
.add_sdram("sdram",
70 module
= MT8JTF12864(sys_clk_freq
, "1:4"),
71 origin
= self
.mem_map
["main_ram"],
72 size
= kwargs
.get("max_sdram_size", 0x40000000),
73 l2_cache_size
= kwargs
.get("l2_size", 8192),
74 l2_cache_min_data_width
= kwargs
.get("min_l2_data_width", 128),
75 l2_cache_reverse
= True
78 # Ethernet ---------------------------------------------------------------------------------
80 self
.submodules
.ethphy
= LiteEthPHY(
81 clock_pads
= self
.platform
.request("eth_clocks"),
82 pads
= self
.platform
.request("eth"),
83 clk_freq
= self
.clk_freq
)
84 self
.add_csr("ethphy")
85 self
.add_ethernet(phy
=self
.ethphy
)
87 # Leds -------------------------------------------------------------------------------------
88 self
.submodules
.leds
= LedChaser(
89 pads
= Cat(*[platform
.request("user_led", i
) for i
in range(8)]),
90 sys_clk_freq
= sys_clk_freq
)
93 # Build --------------------------------------------------------------------------------------------
96 parser
= argparse
.ArgumentParser(description
="LiteX SoC on KC705")
97 parser
.add_argument("--build", action
="store_true", help="Build bitstream")
98 parser
.add_argument("--load", action
="store_true", help="Load bitstream")
100 soc_sdram_args(parser
)
101 parser
.add_argument("--with-ethernet", action
="store_true", help="Enable Ethernet support")
102 args
= parser
.parse_args()
104 soc
= BaseSoC(with_ethernet
=args
.with_ethernet
, **soc_sdram_argdict(args
))
105 builder
= Builder(soc
, **builder_argdict(args
))
106 builder
.build(run
=args
.build
)
109 prog
= soc
.platform
.create_programmer()
110 prog
.load_bitstream(os
.path
.join(builder
.gateware_dir
, soc
.build_name
+ ".bit"))
112 if __name__
== "__main__":