Skip to content

Commit 8378945

Browse files
authored
Merge pull request #244 from miek/hyperram_dqs
Add HyperRAM implementation using ECP5 DQS logic
2 parents 3cce743 + af5acbd commit 8378945

File tree

2 files changed

+549
-21
lines changed

2 files changed

+549
-21
lines changed

applets/hyperram_diagnostic.py

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@
1818
from luna import top_level_cli
1919
from apollo_fpga import ApolloDebugger
2020
from luna.gateware.interface.jtag import JTAGRegisterInterface
21-
from luna.gateware.architecture.car import LunaECP5DomainGenerator
22-
from luna.gateware.interface.psram import HyperRAMPHY, HyperRAMInterface
21+
from luna.gateware.interface.psram import HyperRAMPHY, HyperRAMInterface, HyperRAMDQSInterface, HyperRAMDQSPHY
2322

2423
REGISTER_RAM_REGISTER_SPACE = 1
2524
REGISTER_RAM_ADDR = 2
2625
REGISTER_RAM_READ_LENGTH = 3
2726
REGISTER_RAM_FIFO = 4
2827
REGISTER_RAM_START = 5
2928

29+
DQS = False
30+
REG_WIDTH = 32 if DQS else 16
31+
REG_SHIFT = 16 if DQS else 0
3032

3133
class HyperRAMDiagnostic(Elaboratable):
3234
"""
@@ -37,27 +39,40 @@ class HyperRAMDiagnostic(Elaboratable):
3739
def elaborate(self, platform):
3840
m = Module()
3941

42+
clock_frequencies = platform.DEFAULT_CLOCK_FREQUENCIES_MHZ
43+
44+
#
45+
# HyperRAM test connections.
46+
#
47+
if DQS:
48+
clock_frequencies = {
49+
"fast": 120,
50+
"sync": 60,
51+
"usb": 60,
52+
}
53+
ram_bus = platform.request('ram', dir={'rwds':'-', 'dq':'-', 'cs':'-'})
54+
psram_phy = HyperRAMDQSPHY(bus=ram_bus)
55+
psram = HyperRAMDQSInterface(phy=psram_phy.phy)
56+
else:
57+
ram_bus = platform.request('ram')
58+
psram_phy = HyperRAMPHY(bus=ram_bus)
59+
psram = HyperRAMInterface(phy=psram_phy.phy)
60+
61+
m.submodules += [psram_phy, psram]
62+
4063
# Generate our clock domains.
41-
clocking = LunaECP5DomainGenerator()
64+
clocking = platform.clock_domain_generator(clock_frequencies=clock_frequencies)
4265
m.submodules.clocking = clocking
4366

4467
# Create a set of registers...
4568
registers = JTAGRegisterInterface(address_size=7, default_read_value=0xDEADBEEF)
4669
m.submodules.registers = registers
4770

48-
#
49-
# HyperRAM test connections.
50-
#
51-
ram_bus = platform.request('ram')
52-
psram_phy = HyperRAMPHY(bus=ram_bus)
53-
psram = HyperRAMInterface(phy=psram_phy.phy)
54-
m.submodules += [psram_phy, psram]
55-
5671
psram_address = registers.add_register(REGISTER_RAM_ADDR)
5772
read_length = registers.add_register(REGISTER_RAM_READ_LENGTH, reset=1)
5873

59-
m.submodules.read_fifo = read_fifo = SyncFIFO(width=16, depth=32)
60-
m.submodules.write_fifo = write_fifo = SyncFIFO(width=16, depth=32)
74+
m.submodules.read_fifo = read_fifo = SyncFIFO(width=REG_WIDTH, depth=32)
75+
m.submodules.write_fifo = write_fifo = SyncFIFO(width=REG_WIDTH, depth=32)
6176
registers.add_sfr(REGISTER_RAM_FIFO,
6277
read=read_fifo.r_data,
6378
read_strobe=read_fifo.r_en,
@@ -123,7 +138,10 @@ def elaborate(self, platform):
123138
dut = ApolloDebugger()
124139
logging.info(f"Connected to onboard dut; hardware revision r{dut.major}.{dut.minor} (s/n: {dut.serial_number}).")
125140

126-
logging.info("Running basic HyperRAM diagnostics.")
141+
if DQS:
142+
logging.info("Running basic HyperRAM diagnostics, using DQS implementation.")
143+
else:
144+
logging.info("Running basic HyperRAM diagnostics.")
127145

128146
iterations = 1
129147

@@ -136,7 +154,7 @@ def read_hyperram_register(addr):
136154
dut.registers.register_write(REGISTER_RAM_ADDR, addr)
137155
dut.registers.register_read(REGISTER_RAM_START)
138156
time.sleep(0.1)
139-
return dut.registers.register_read(REGISTER_RAM_FIFO)
157+
return dut.registers.register_read(REGISTER_RAM_FIFO) >> REG_SHIFT
140158

141159
def test_id_read():
142160
return read_hyperram_register(0x0) in (0x0c81, 0x0c86)
@@ -147,7 +165,7 @@ def test_config_read():
147165
def test_mem_readback():
148166
dut.registers.register_write(REGISTER_RAM_REGISTER_SPACE, 0)
149167

150-
data = [random.randint(0, int(2**16)) for _ in range(10)]
168+
data = [random.randint(0, int(2**REG_WIDTH)) for _ in range(10)]
151169

152170
# Fill write FIFO.
153171
for d in data:

0 commit comments

Comments
 (0)