Unverified Commit e545b15f authored by enjoy-digital's avatar enjoy-digital Committed by GitHub

Merge pull request #196 from msloniewski/de10lite_support

De10lite support
parents 77805a5e 04ce4790
from litex.build.generic_platform import *
from litex.build.altera import AlteraPlatform
from litex.build.altera.programmer import USBBlaster
_io = [
("clk10", 0, Pins("N5"), IOStandard("3.3-V LVTTL")),
("clk50", 0, Pins("P11"), IOStandard("3.3-V LVTTL")),
("clk50", 1, Pins("N14"), IOStandard("3.3-V LVTTL")),
("serial", 0,
Subsignal("tx", Pins("V10"), IOStandard("3.3-V LVTTL")), # JP1 GPIO[0]
Subsignal("rx", Pins("W10"), IOStandard("3.3-V LVTTL")) # JP1 GPIO[1]
),
("user_led", 0, Pins("A8"), IOStandard("3.3-V LVTTL")),
("user_led", 1, Pins("A9"), IOStandard("3.3-V LVTTL")),
("user_led", 2, Pins("A10"), IOStandard("3.3-V LVTTL")),
("user_led", 3, Pins("B10"), IOStandard("3.3-V LVTTL")),
("user_led", 4, Pins("D13"), IOStandard("3.3-V LVTTL")),
("user_led", 5, Pins("C13"), IOStandard("3.3-V LVTTL")),
("user_led", 6, Pins("E14"), IOStandard("3.3-V LVTTL")),
("user_led", 7, Pins("D14"), IOStandard("3.3-V LVTTL")),
("user_led", 8, Pins("A11"), IOStandard("3.3-V LVTTL")),
("user_led", 9, Pins("B11"), IOStandard("3.3-V LVTTL")),
("user_btn", 0, Pins("B8"), IOStandard("3.3-V LVTTL")),
("user_btn", 1, Pins("A7"), IOStandard("3.3-V LVTTL")),
("user_sw", 0, Pins("C10"), IOStandard("3.3-V LVTTL")),
("user_sw", 1, Pins("C11"), IOStandard("3.3-V LVTTL")),
("user_sw", 2, Pins("D12"), IOStandard("3.3-V LVTTL")),
("user_sw", 3, Pins("C12"), IOStandard("3.3-V LVTTL")),
("user_sw", 4, Pins("A12"), IOStandard("3.3-V LVTTL")),
("user_sw", 5, Pins("B12"), IOStandard("3.3-V LVTTL")),
("user_sw", 6, Pins("A13"), IOStandard("3.3-V LVTTL")),
("user_sw", 7, Pins("A14"), IOStandard("3.3-V LVTTL")),
("user_sw", 8, Pins("B14"), IOStandard("3.3-V LVTTL")),
("user_sw", 9, Pins("F15"), IOStandard("3.3-V LVTTL")),
# 7-segment displays
("seven_seg", 0, Pins("C14 E15 C15 C16 E16 D17 C17 D15"), IOStandard("3.3-V LVTTL")),
("seven_seg", 1, Pins("C18 D18 E18 B16 A17 A18 B17 A16"), IOStandard("3.3-V LVTTL")),
("seven_seg", 2, Pins("B20 A20 B19 A21 B21 C22 B22 A19"), IOStandard("3.3-V LVTTL")),
("seven_seg", 3, Pins("F21 E22 E21 C19 C20 D19 E17 D22"), IOStandard("3.3-V LVTTL")),
("seven_seg", 4, Pins("F18 E20 E19 J18 H19 F19 F20 F17"), IOStandard("3.3-V LVTTL")),
("seven_seg", 5, Pins("J20 K20 L18 N18 M20 N19 N20 L19"), IOStandard("3.3-V LVTTL")),
("gpio_0", 0,
Pins("V10 W10 V9 W9 V8 W8 V7 W7 W6 V5 W5 AA15 AA14 W13 W12 AB13 AB12 Y11 AB11 W11 AB10 AA10 AA9 Y8 AA8 Y7 AA7 Y6 AA6 Y5 AA5 Y4 AB3 Y3 AB2 AA2"),
IOStandard("3.3-V LVTTL")
),
("gpio_1", 0,
Pins("AB5 AB6 AB7 AB8 AB9 Y10 AA11 AA12 AB17 AA17 AB19 AA19 Y19 AB20 AB21 AA20 F16"),
IOStandard("3.3-V LVTTL")
),
("vga_out", 0,
Subsignal("hsync_n", Pins("N3")),
Subsignal("vsync_n", Pins("N1")),
Subsignal("r", Pins("AA1 V1 Y2 Y1")),
Subsignal("g", Pins("W1 T2 R2 R1")),
Subsignal("b", Pins("P1 T1 P4 N2")),
IOStandard("3.3-V LVTTL")
),
("sdram_clock", 0, Pins("L14"), IOStandard("3.3-V LVTTL")),
("sdram", 0,
Subsignal("a", Pins("U17 W19 V18 U18 U19 T18 T19 R18 P18 P19 T20 P20 R20")),
Subsignal("ba", Pins("T21 T22")),
Subsignal("cs_n", Pins("U20")),
Subsignal("cke", Pins("N22")),
Subsignal("ras_n", Pins("U22")),
Subsignal("cas_n", Pins("U21")),
Subsignal("we_n", Pins("V20")),
Subsignal("dq", Pins("Y21 Y20 AA22 AA21 Y22 W22 W20 V21 P21 J22 H21 H22 G22 G20 G19 F22")),
Subsignal("dm", Pins("V22 J21")),
IOStandard("3.3-V LVTTL")
),
("accelerometer", 0,
Subsignal("int1", Pins("Y14")),
Subsignal("int1", Pins("Y13")),
Subsignal("mosi", Pins("V11")),
Subsignal("miso", Pins("V12")),
Subsignal("clk", Pins("AB15")),
Subsignal("cs_n", Pins("AB16")),
IOStandard("3.3-V LVTTL")
)
]
class Platform(AlteraPlatform):
default_clk_name = "clk50"
default_clk_period = 20
create_rbf = False
def __init__(self):
AlteraPlatform.__init__(self, "10M50DAF484C7G", _io)
def create_programmer(self):
return USBBlaster()
#!/usr/bin/env python3
import argparse
from migen import *
from litex.boards.platforms import de10lite
from litex.soc.integration.soc_sdram import *
from litex.soc.integration.builder import *
from litedram.modules import IS42S16320
from litedram.phy import GENSDRPHY
# CRG ----------------------------------------------------------------------------------------------
class _CRG(Module):
def __init__(self, platform):
self.clock_domains.cd_sys = ClockDomain()
self.clock_domains.cd_sys_ps = ClockDomain()
self.clock_domains.cd_por = ClockDomain(reset_less=True)
# # #
self.cd_sys.clk.attr.add("keep")
self.cd_sys_ps.clk.attr.add("keep")
self.cd_por.clk.attr.add("keep")
# power on rst
rst_n = Signal()
self.sync.por += rst_n.eq(1)
self.comb += [
self.cd_por.clk.eq(self.cd_sys.clk),
self.cd_sys.rst.eq(~rst_n),
self.cd_sys_ps.rst.eq(~rst_n)
]
# sys clk / sdram clk
clk50 = platform.request("clk50")
self.comb += self.cd_sys.clk.eq(clk50)
self.specials += \
Instance("ALTPLL",
p_BANDWIDTH_TYPE="AUTO",
p_CLK0_DIVIDE_BY=1,
p_CLK0_DUTY_CYCLE=50,
p_CLK0_MULTIPLY_BY=1,
p_CLK0_PHASE_SHIFT="-10000",
p_COMPENSATE_CLOCK="CLK0",
p_INCLK0_INPUT_FREQUENCY=20000,
p_INTENDED_DEVICE_FAMILY="MAX 10",
p_LPM_TYPE = "altpll",
p_OPERATION_MODE = "NORMAL",
i_INCLK=clk50,
o_CLK=self.cd_sys_ps.clk,
i_ARESET=~rst_n,
i_CLKENA=0x3f,
i_EXTCLKENA=0xf,
i_FBIN=1,
i_PFDENA=1,
i_PLLENA=1,
)
self.comb += platform.request("sdram_clock").eq(self.cd_sys_ps.clk)
# BaseSoC ------------------------------------------------------------------------------------------
class BaseSoC(SoCSDRAM):
def __init__(self, sys_clk_freq=int(50e6), **kwargs):
assert sys_clk_freq == int(50e6)
platform = de10lite.Platform()
SoCSDRAM.__init__(self, platform, clk_freq=sys_clk_freq,
integrated_rom_size=0x8000,
**kwargs)
self.submodules.crg = _CRG(platform)
if not self.integrated_main_ram_size:
self.submodules.sdrphy = GENSDRPHY(platform.request("sdram"))
sdram_module = IS42S16320(self.clk_freq, "1:1")
self.register_sdram(self.sdrphy,
sdram_module.geom_settings,
sdram_module.timing_settings)
# Build --------------------------------------------------------------------------------------------
def main():
parser = argparse.ArgumentParser(description="LiteX SoC on DE10 Lite")
builder_args(parser)
soc_sdram_args(parser)
args = parser.parse_args()
soc = BaseSoC(**soc_sdram_argdict(args))
builder = Builder(soc, **builder_argdict(args))
builder.build()
if __name__ == "__main__":
main()
......@@ -4,6 +4,7 @@ from litex.build.altera import common, quartus
class AlteraPlatform(GenericPlatform):
bitstream_ext = ".sof"
create_rbf = True
def __init__(self, *args, toolchain="quartus", **kwargs):
GenericPlatform.__init__(self, *args, **kwargs)
......
......@@ -110,7 +110,7 @@ def _build_files(device, sources, vincpaths, named_sc, named_pc, build_name):
tools.write_to_file("{}.qsf".format(build_name), "\n".join(lines))
def _run_quartus(build_name, quartus_path):
def _run_quartus(build_name, quartus_path, create_rbf):
build_script_contents = "# Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\n"
build_script_contents += """
......@@ -119,13 +119,16 @@ set -e
quartus_map --read_settings_files=on --write_settings_files=off {build_name} -c {build_name}
quartus_fit --read_settings_files=off --write_settings_files=off {build_name} -c {build_name}
quartus_asm --read_settings_files=off --write_settings_files=off {build_name} -c {build_name}
quartus_sta {build_name} -c {build_name}
quartus_sta {build_name} -c {build_name}"""
if create_rbf:
build_script_contents +="""
if [ -f "{build_name}.sof" ]
then
quartus_cpf -c {build_name}.sof {build_name}.rbf
fi
""".format(build_name=build_name) # noqa
"""
build_script_contents = build_script_contents.format(build_name=build_name) # noqa
build_script_file = "build_" + build_name + ".sh"
tools.write_to_file(build_script_file,
build_script_contents,
......@@ -166,7 +169,7 @@ class AlteraQuartusToolchain:
_build_sdc(self.clocks, self.false_paths, v_output.ns, build_name)
if run:
_run_quartus(build_name, toolchain_path)
_run_quartus(build_name, toolchain_path, platform.create_rbf)
os.chdir(cwd)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment