1 # This file is Copyright (c) 2020 LambdaConcept <contact@lambdaconcept.com>
2 # This file is Copyright (c) 2022 Raptor Engineering, LLC <support@raptorengineering.com>
5 from nmigen
.lib
.cdc
import ResetSynchronizer
6 from nmigen_soc
import wishbone
, memory
8 from lambdasoc
.cpu
.minerva
import MinervaCPU
9 from lambdasoc
.periph
.intc
import GenericInterruptController
10 from lambdasoc
.periph
.serial
import AsyncSerialPeripheral
11 from lambdasoc
.periph
.sram
import SRAMPeripheral
12 from lambdasoc
.periph
.timer
import TimerPeripheral
13 from lambdasoc
.periph
import Peripheral
14 from lambdasoc
.soc
.base
import SoC
16 from gram
.core
import gramCore
17 from gram
.phy
.ecp5ddrphy
import ECP5DDRPHY
18 from gram
.modules
import MT41K64M16
19 from gram
.frontend
.wishbone
import gramWishbone
21 from nmigen_boards
.versa_ecp5
import VersaECP5Platform85
22 #from ecp5_crg import ECP5CRG
23 from crg
import ECPIX5CRG
24 from uartbridge
import UARTBridge
27 class DDR3SoC(SoC
, Elaboratable
):
29 ddrphy_addr
, dramcore_addr
,
31 self
._decoder
= wishbone
.Decoder(addr_width
=30, data_width
=32, granularity
=8,
32 features
={"cti", "bte"})
34 self
.crg
= ECPIX5CRG()
37 self
.ub
= UARTBridge(divisor
=868, pins
=platform
.request("uart", 0))
39 ddr_pins
= platform
.request("ddr3", 0, dir={"dq":"-", "dqs":"-"},
40 xdr
={"clk":4, "a":4, "ba":4, "clk_en":4, "odt":4, "ras":4, "cas":4, "we":4, "cs":4, "rst":1})
41 self
.ddrphy
= DomainRenamer("dramsync")(ECP5DDRPHY(ddr_pins
))
42 self
._decoder
.add(self
.ddrphy
.bus
, addr
=ddrphy_addr
)
44 ddrmodule
= MT41K64M16(platform
.default_clk_frequency
, "1:2")
46 self
.dramcore
= DomainRenamer("dramsync")(gramCore(
48 geom_settings
=ddrmodule
.geom_settings
,
49 timing_settings
=ddrmodule
.timing_settings
,
50 clk_freq
=platform
.default_clk_frequency
))
51 self
._decoder
.add(self
.dramcore
.bus
, addr
=dramcore_addr
)
53 self
.drambone
= DomainRenamer("dramsync")(gramWishbone(self
.dramcore
))
54 self
._decoder
.add(self
.drambone
.bus
, addr
=ddr_addr
)
56 self
.memory_map
= self
._decoder
.bus
.memory_map
58 self
.clk_freq
= platform
.default_clk_frequency
60 def elaborate(self
, platform
):
63 m
.submodules
.sysclk
= self
.crg
65 m
.submodules
.ub
= self
.ub
67 m
.submodules
.decoder
= self
._decoder
68 m
.submodules
.ddrphy
= self
.ddrphy
69 m
.submodules
.dramcore
= self
.dramcore
70 m
.submodules
.drambone
= self
.drambone
73 self
.ub
.bus
.connect(self
._decoder
.bus
),
79 if __name__
== "__main__":
80 platform
= VersaECP5Platform85()
82 soc
= DDR3SoC(ddrphy_addr
=0x00008000, dramcore_addr
=0x00009000,
85 soc
.build(do_build
=True)
86 platform
.build(soc
, do_program
=True)