|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import argparse |
| 4 | + |
| 5 | +from migen import * |
| 6 | +from migen.genlib.resetsync import AsyncResetSynchronizer |
| 7 | +from migen.build.platforms.sinara import kasli |
| 8 | + |
| 9 | +from misoc.cores.sdram_settings import MT41K256M16 |
| 10 | +from misoc.cores.sdram_phy import a7ddrphy |
| 11 | +from misoc.cores import spi_flash |
| 12 | +from misoc.integration.soc_sdram import * |
| 13 | +from misoc.integration.builder import * |
| 14 | + |
| 15 | + |
| 16 | +class _CRG(Module): |
| 17 | + def __init__(self, platform): |
| 18 | + self.clock_domains.cd_sys = ClockDomain() |
| 19 | + self.clock_domains.cd_sys4x = ClockDomain(reset_less=True) |
| 20 | + self.clock_domains.cd_sys4x_dqs = ClockDomain(reset_less=True) |
| 21 | + self.clock_domains.cd_clk200 = ClockDomain() |
| 22 | + |
| 23 | + clk50 = platform.request("clk50") |
| 24 | + |
| 25 | + pll_locked = Signal() |
| 26 | + pll_fb = Signal() |
| 27 | + pll_sys = Signal() |
| 28 | + pll_sys4x = Signal() |
| 29 | + pll_sys4x_dqs = Signal() |
| 30 | + pll_clk200 = Signal() |
| 31 | + self.specials += [ |
| 32 | + Instance("PLLE2_BASE", |
| 33 | + p_STARTUP_WAIT="FALSE", o_LOCKED=pll_locked, |
| 34 | + |
| 35 | + # VCO @ 1GHz |
| 36 | + p_REF_JITTER1=0.01, p_CLKIN1_PERIOD=20.0, |
| 37 | + p_CLKFBOUT_MULT=20, p_DIVCLK_DIVIDE=1, |
| 38 | + i_CLKIN1=clk50, i_CLKFBIN=pll_fb, o_CLKFBOUT=pll_fb, |
| 39 | + |
| 40 | + # 125MHz |
| 41 | + p_CLKOUT0_DIVIDE=8, p_CLKOUT0_PHASE=0.0, o_CLKOUT0=pll_sys, |
| 42 | + |
| 43 | + # 500MHz |
| 44 | + p_CLKOUT1_DIVIDE=2, p_CLKOUT1_PHASE=0.0, o_CLKOUT1=pll_sys4x, |
| 45 | + |
| 46 | + # 200MHz |
| 47 | + p_CLKOUT2_DIVIDE=5, p_CLKOUT2_PHASE=0.0, o_CLKOUT2=pll_clk200, |
| 48 | + |
| 49 | + p_CLKOUT3_DIVIDE=2, p_CLKOUT3_PHASE=90.0, o_CLKOUT3=pll_sys4x_dqs, |
| 50 | + |
| 51 | + p_CLKOUT4_DIVIDE=4, p_CLKOUT4_PHASE=0.0, #o_CLKOUT4= |
| 52 | + ), |
| 53 | + Instance("BUFG", i_I=pll_sys, o_O=self.cd_sys.clk), |
| 54 | + Instance("BUFG", i_I=pll_sys4x, o_O=self.cd_sys4x.clk), |
| 55 | + Instance("BUFG", i_I=pll_sys4x_dqs, o_O=self.cd_sys4x_dqs.clk), |
| 56 | + Instance("BUFG", i_I=pll_clk200, o_O=self.cd_clk200.clk), |
| 57 | + AsyncResetSynchronizer(self.cd_sys, ~pll_locked), |
| 58 | + AsyncResetSynchronizer(self.cd_clk200, ~pll_locked), |
| 59 | + ] |
| 60 | + |
| 61 | + reset_counter = Signal(4, reset=15) |
| 62 | + ic_reset = Signal(reset=1) |
| 63 | + self.sync.clk200 += \ |
| 64 | + If(reset_counter != 0, |
| 65 | + reset_counter.eq(reset_counter - 1) |
| 66 | + ).Else( |
| 67 | + ic_reset.eq(0) |
| 68 | + ) |
| 69 | + self.specials += Instance("IDELAYCTRL", i_REFCLK=ClockSignal("clk200"), i_RST=ic_reset) |
| 70 | + |
| 71 | + |
| 72 | +class BaseSoC(SoCSDRAM): |
| 73 | + def __init__(self, sdram_controller_type="minicon", **kwargs): |
| 74 | + platform = kasli.Platform() |
| 75 | + SoCSDRAM.__init__(self, platform, |
| 76 | + clk_freq=125*1000000, cpu_reset_address=0xaf0000, |
| 77 | + **kwargs) |
| 78 | + |
| 79 | + self.submodules.crg = _CRG(platform) |
| 80 | + |
| 81 | + self.submodules.ddrphy = a7ddrphy.A7DDRPHY(platform.request("ddram")) |
| 82 | + sdram_module = MT41K256M16(self.clk_freq, "1:4") |
| 83 | + self.register_sdram(self.ddrphy, sdram_controller_type, |
| 84 | + sdram_module.geom_settings, sdram_module.timing_settings) |
| 85 | + self.csr_devices.append("ddrphy") |
| 86 | + |
| 87 | + if not self.integrated_rom_size: |
| 88 | + spiflash_pads = platform.request("spiflash") |
| 89 | + spiflash_pads.clk = Signal() |
| 90 | + self.specials += Instance("STARTUPE2", |
| 91 | + i_CLK=0, i_GSR=0, i_GTS=0, i_KEYCLEARB=0, i_PACK=0, |
| 92 | + i_USRCCLKO=spiflash_pads.clk, i_USRCCLKTS=0, i_USRDONEO=1, i_USRDONETS=1) |
| 93 | + self.submodules.spiflash = spi_flash.SpiFlash(spiflash_pads, dummy=11, div=2) |
| 94 | + self.config["SPIFLASH_PAGE_SIZE"] = 256 |
| 95 | + self.config["SPIFLASH_SECTOR_SIZE"] = 0x10000 |
| 96 | + self.flash_boot_address = 0xb00000 |
| 97 | + self.register_rom(self.spiflash.bus, 16*1024*1024) |
| 98 | + self.csr_devices.append("spiflash") |
| 99 | + |
| 100 | + |
| 101 | +def soc_kasli_args(parser): |
| 102 | + soc_sdram_args(parser) |
| 103 | + |
| 104 | + |
| 105 | +def soc_kasli_argdict(args): |
| 106 | + r = soc_sdram_argdict(args) |
| 107 | + return r |
| 108 | + |
| 109 | + |
| 110 | +def main(): |
| 111 | + parser = argparse.ArgumentParser(description="MiSoC port to Kasli") |
| 112 | + builder_args(parser) |
| 113 | + soc_kasli_args(parser) |
| 114 | + args = parser.parse_args() |
| 115 | + |
| 116 | + cls = BaseSoC |
| 117 | + soc = cls(**soc_kasli_argdict(args)) |
| 118 | + builder = Builder(soc, **builder_argdict(args)) |
| 119 | + builder.build() |
| 120 | + |
| 121 | + |
| 122 | +if __name__ == "__main__": |
| 123 | + main() |
0 commit comments