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
.cpu
.minerva
import MinervaCPU
8 from lambdasoc
.periph
.intc
import GenericInterruptController
9 from lambdasoc
.periph
.serial
import AsyncSerialPeripheral
10 from lambdasoc
.periph
.sram
import SRAMPeripheral
11 from lambdasoc
.periph
.timer
import TimerPeripheral
12 from lambdasoc
.periph
import Peripheral
13 from lambdasoc
.soc
.base
import SoC
15 from gram
.core
import gramCore
16 from gram
.phy
.ecp5ddrphy
import ECP5DDRPHY
17 from gram
.modules
import MT41K256M16
18 from gram
.frontend
.wishbone
import gramWishbone
20 from nmigen_boards
.ecpix5
import *
21 from uartbridge
import UARTBridge
24 class DDR3SoC(SoC
, Elaboratable
):
26 ddrphy_addr
, dramcore_addr
,
28 self
._decoder
= wishbone
.Decoder(addr_width
=30, data_width
=32, granularity
=8,
29 features
={"cti", "bte"})
31 self
.crg
= ECPIX5CRG()
33 self
.ub
= UARTBridge(divisor
=868, pins
=platform
.request("uart", 0))
35 ddr_pins
= platform
.request("ddr3", 0, dir={"dq":"-", "dqs":"-"},
36 xdr
={"clk":4, "a":4, "ba":4, "clk_en":4, "odt":4, "ras":4, "cas":4, "we":4})
37 self
.ddrphy
= DomainRenamer("dramsync")(ECP5DDRPHY(ddr_pins
))
38 self
._decoder
.add(self
.ddrphy
.bus
, addr
=ddrphy_addr
)
40 ddrmodule
= MT41K256M16(platform
.default_clk_frequency
, "1:2")
42 self
.dramcore
= DomainRenamer("dramsync")(gramCore(
44 geom_settings
=ddrmodule
.geom_settings
,
45 timing_settings
=ddrmodule
.timing_settings
,
46 clk_freq
=platform
.default_clk_frequency
))
47 self
._decoder
.add(self
.dramcore
.bus
, addr
=dramcore_addr
)
49 self
.drambone
= DomainRenamer("dramsync")(gramWishbone(self
.dramcore
))
50 self
._decoder
.add(self
.drambone
.bus
, addr
=ddr_addr
)
52 self
.memory_map
= self
._decoder
.bus
.memory_map
54 self
.clk_freq
= platform
.default_clk_frequency
56 def elaborate(self
, platform
):
59 m
.submodules
.sysclk
= self
.crg
61 m
.submodules
.ub
= self
.ub
63 m
.submodules
.decoder
= self
._decoder
64 m
.submodules
.ddrphy
= self
.ddrphy
65 m
.submodules
.dramcore
= self
.dramcore
66 m
.submodules
.drambone
= self
.drambone
69 self
.ub
.bus
.connect(self
._decoder
.bus
),
75 if __name__
== "__main__":
76 platform
= ECPIX585Platform()
78 soc
= DDR3SoC(ddrphy_addr
=0x00008000, dramcore_addr
=0x00009000,
81 soc
.build(do_build
=True)
82 platform
.build(soc
, do_program
=True)