1 # This file is Copyright (c) 2020 LambdaConcept <contact@lambdaconcept.com>
4 from nmigen
.lib
.cdc
import ResetSynchronizer
5 from nmigen_soc
import wishbone
, memory
7 from lambdasoc
.periph
.intc
import GenericInterruptController
8 from lambdasoc
.periph
.serial
import AsyncSerialPeripheral
9 from lambdasoc
.periph
.sram
import SRAMPeripheral
10 from lambdasoc
.periph
.timer
import TimerPeripheral
11 from lambdasoc
.periph
import Peripheral
12 from lambdasoc
.soc
.base
import SoC
14 from gram
.core
import gramCore
15 from gram
.phy
.ecp5ddrphy
import ECP5DDRPHY
16 from gram
.modules
import MT41K256M16
17 from gram
.frontend
.wishbone
import gramWishbone
19 from nmigen_boards
.ecpix5
import *
20 from uartbridge
import UARTBridge
23 class DDR3SoC(SoC
, Elaboratable
):
25 ddrphy_addr
, dramcore_addr
,
27 self
._decoder
= wishbone
.Decoder(addr_width
=30, data_width
=32, granularity
=8,
28 features
={"cti", "bte"})
30 self
.crg
= ECPIX5CRG()
32 self
.ub
= UARTBridge(divisor
=868, pins
=platform
.request("uart", 0))
34 ddr_pins
= platform
.request("ddr3", 0, dir={"dq":"-", "dqs":"-"},
35 xdr
={"clk":4, "a":4, "ba":4, "clk_en":4, "odt":4, "ras":4, "cas":4, "we":4})
36 self
.ddrphy
= DomainRenamer("dramsync")(ECP5DDRPHY(ddr_pins
))
37 self
._decoder
.add(self
.ddrphy
.bus
, addr
=ddrphy_addr
)
39 ddrmodule
= MT41K256M16(platform
.default_clk_frequency
, "1:2")
41 self
.dramcore
= DomainRenamer("dramsync")(gramCore(
43 geom_settings
=ddrmodule
.geom_settings
,
44 timing_settings
=ddrmodule
.timing_settings
,
45 clk_freq
=platform
.default_clk_frequency
))
46 self
._decoder
.add(self
.dramcore
.bus
, addr
=dramcore_addr
)
48 self
.drambone
= DomainRenamer("dramsync")(gramWishbone(self
.dramcore
))
49 self
._decoder
.add(self
.drambone
.bus
, addr
=ddr_addr
)
51 self
.memory_map
= self
._decoder
.bus
.memory_map
53 self
.clk_freq
= platform
.default_clk_frequency
55 def elaborate(self
, platform
):
58 m
.submodules
.sysclk
= self
.crg
60 m
.submodules
.ub
= self
.ub
62 m
.submodules
.decoder
= self
._decoder
63 m
.submodules
.ddrphy
= self
.ddrphy
64 m
.submodules
.dramcore
= self
.dramcore
65 m
.submodules
.drambone
= self
.drambone
68 self
.ub
.bus
.connect(self
._decoder
.bus
),
74 if __name__
== "__main__":
75 platform
= ECPIX585Platform()
77 soc
= DDR3SoC(ddrphy_addr
=0x00008000, dramcore_addr
=0x00009000,
80 soc
.build(do_build
=True)
81 platform
.build(soc
, do_program
=True)