z80replacement · a Z80 CPU replacement with an FPGA

The DDR3L controller

HISTORY: the LiteDRAM DDR3L controller that the SRAM replaced on 9 November 2026

Status, 29 November 2026: nobody has built this module yet. The first sample run of 2 boards comes soon. Wait until the project has tested these boards before you send an order or a build request to a factory.

Repository file: docs/ddr3.md

HISTORY: The SRAM replaced the DDR3L on 9 November 2026. See sram.md. The DDR3L part (U5), the 1.35 V buck converter (U20) and the LiteDRAM controller are no longer in the design. This file and gateware/ddr stay in the repository as history. The text below describes the DDR3L design as it was. The DDR3L text that was in memory.md is at the end of this file, in "History: text from memory.md".

Memory mode 2 (memory.md) kept the banked ROM and RAM of a RomWBW system in the DDR3L part. This file describes the controller: LiteDRAM, generated for the ECP5 DDR PHY.

STATUS: SIMULATION AND FIT TEST ONLY. litedram_gen makes the controller, and the controller goes through place and route on the real DDR3L balls. Memory mode 2 uses the controller (memory.md, "Mode 2 in the gateware"). No board test is done yet.

Tools

Tool Version Use
LiteDRAM 2024.12 The controller and the ECP5 DDR PHY
LiteX 2024.12 The generator framework of LiteDRAM
Migen 0.10.0 The HDL of LiteX
LiteEth, LiteScope 2024.12 Only for litedram_gen --sim

The tools are in a Python venv. On the Windows build machine, the venv is C:\temp\tools\litex-venv:

python -m venv C:\temp\tools\litex-venv
C:\temp\tools\litex-venv\Scripts\python -m pip install litex==2024.12 litedram==2024.12 migen==0.10.0 liteeth==2024.12 litescope==2024.12 pyyaml

The configuration

gateware/ddr/litedram_ecp5.yml holds the settings of litedram_gen:

Setting Value
Memory DDR3, 2 bytes (one x16 part), timing of the MT41K128M16 (the class of the IS43TR16128DL)
PHY ECP5DDRPHY, rate 1:2
Clocks 25 MHz oscillator in. The PLL of the core makes the system clock (48 MHz) and twice the system clock for the PHY (96 MHz, the DDR3L clock CK). The PLL gives 575 MHz / 6 = 95.8 MHz, within the 1% of litedram_gen.
CPU none. The control bus (wb_ctrl, Wishbone) is a port of the core.
User port z80, native: 128-bit words, a 24-bit word address (256 MB). The port does not wait for init_done (block_until_ready is False), because the init sequencer uses the port for the read leveling.

mingw32-make core in gateware/ddr writes build/litedram/gateware/litedram_core.v. Then fix_core.py patches the Verilog:

  1. The DQ and DQS ports become inout. The core drives these ports through its own TRELLIS_IO buffers.
  2. The generator writes 26 assign lines two times. The script removes the second copy of each.
  3. The 8 FD1S3BX flip-flops of the reset synchronizers become flip-flops with a synchronous set and a power-up value of 1. With Yosys 0.70+344 and nextpnr-ecp5 0.11.1-88, nextpnr stops in the packer on these flip-flops with an asynchronous set.
  4. Each always @(*) block gets blocking assignments. The generator writes these blocks with nonblocking assignments, for Verilator. Synthesis gives the same logic.

Simulation

litedram_gen --sim writes litedram_sim.v, with a model of the PHY and the DRAM in place of the ECP5 primitives. mingw32-make sim-core makes a copy for iverilog:

  • fix_core.py --sim does items 2 and 4 above. Each always @(*) block also becomes always_comb, which runs once at time 0. An always @(*) block first runs when an input changes. Without the change, the wishbone-to-CSR bridge keeps a wrong start value in its idle state, and takes the address of a write without the data.
  • The model holds all of the 256 MB in 8 arrays of 2M words. The copy keeps 64K words in each array (8 MB in all).

mingw32-make test runs tb_native.sv. The bench sets init_done through the control bus, writes words and one byte through the native port, and reads them back. A read takes 12 to 14 system clocks (250 ns to 290 ns at 48 MHz) from the command to the data.

The init sequencer

With no CPU, gateware/ddr/z80r_dram_init.sv does the work of the LiteX BIOS in sdram_init(). The sequencer operates on the system clock of the core. It is the master of the control bus, and of the native port until the init ends.

make_init.py makes the program of the sequencer from the headers of the core (csr.h and sdram_phy.h):

  1. Each step of init_sequence(): a CSR write, or a delay. A cdelay(n) becomes 4 × n system clocks.
  2. The DFII control register to DFII_CONTROL_SEL. The controller then drives the DRAM.
  3. The read leveling of the ECP5 PHY (only with --level).
  4. init_done to 1.

The program of the hardware core has 34 steps, and the delays take 241600 clocks (5.0 ms at 48 MHz).

The read leveling writes a test word through the native port. Then, for each byte lane, for each bitslip (0 to 3) and each read delay (0 to 7), the sequencer clears the burst detector and reads the test word. A setting passes if the bytes of the lane are correct and the burst detector saw the read. The sequencer keeps the bitslip with the most passing delays, and the middle of the longest run of passing delays. Then the sequencer syncs the DQSBUFM, as the BIOS does (DLY_SEL to 0, FFH, 0). A lane with no passing setting sets error.

The sequencer uses 623 LUT4 and 175 flip-flops (mingw32-make synth-init).

mingw32-make test runs tb_dram_init.sv against the simulation core three times:

Run Test
0 No leveling. init_done goes to 1, and the native port then works.
1 The leveling. The bench models the PHY registers at an address that the simulation core does not use, and corrupts the read data of a lane outside a good window. The sequencer must find bitslip 2, delay 3 for lane 0, and bitslip 1, delay 5 for lane 1. One setting has correct data but no burst detect, and the sequencer must not count it.
2 Lane 1 has no good setting. The sequencer must set error.

Each of 5 deliberately broken versions of the sequencer fails run 1.

The fit test

gateware/ddr/ddr_fit.sv puts the core on the DDR3L balls of gateware/top/z80r_mg285.lpf, with a traffic source on the user port and on the control bus. mingw32-make fit runs place and route on the LFE5U-85F (8 November 2026, seeds 1 and 2):

Item Result
LUT4 2279
Flip-flops 1121
Block RAM 0
PLL 1 of 4
DQSBUFM 2 of 14
System clock 69.7 MHz to 73.3 MHz (48 MHz is necessary)

nextpnr placed each DQ, DM and DQS ball of the LPF, and placed the two DQSBUFM in the DQS groups of F2 and K2. Thus the bank split and the DQS groups of fpga_pinout.md agree with the ECP5 DDR PHY. The full design with mode 1 uses 7605 LUT4. Thus the full design with the controller uses about 10000 of the 83640 LUT4 of the 85F.

Open items

  • The leveling on a board. The bench tests the leveling only against a model of the PHY registers. Compare the result on the first board with the result of the LiteX BIOS (sdram_leveling) on the same board.
  • The DDR3L clock. CK is 96 MHz. The JEDEC limit for the DLL-on mode of DDR3 is 300 MHz minimum. LiteDRAM on ECP5 boards (for example the OrangeCrab, with a 48 MHz system clock) operates DDR3L at about 100 MHz, below this limit. Read the data sheet of the selected part, and test the board.
  • The reset synchronizers. The synchronous set of item 3 above needs a clock while the PLL locks. Check this on the board, or find a yosys and nextpnr version that accept the asynchronous set.
  • Simulation of the PHY. The simulation core has no ECP5 PHY. Thus no bench tests the read leveling or the init sequence of the real core.
  • Timing margin. At 50 MHz, the full design with mode 2 and the boot copy did not meet the timing on one of three seeds (49.8 MHz). The critical path is in LiteDRAM (the ZQ calibration timer and the refresher). Thus the system clock is 48 MHz. The full design then reaches 49.2 MHz to 52.7 MHz on three seeds, a margin of 2.6 % or more (memory.md, "Size and speed").

History: text from memory.md

On 9 November 2026 the SRAM replaced the DDR3L. memory.md now describes the SRAM. This section keeps the DDR3L text that was in memory.md. The text is not changed, and it describes the DDR3L design.

Amount of RAM (DDR3L design)

The full version has 256 MB (2 Gbit) of RAM, if the parts fit on the board (R10). The fallback is 32 MB (256 Mbit) of SDR SDRAM.

The Z80 addresses 64 KB. A RomWBW system uses 512 KB of ROM and 512 KB of RAM. The rest of the 256 MB can hold RAM disks and ROM images.

Why DDR3L

The largest SDR SDRAM chip is 512 Mbit (64 MB). Thus 256 MB of SDR SDRAM needs four chips, and four chips do not fit. The ECP5 does not support DDR4. DDR3L is the only memory type that gives 256 MB in one chip on an ECP5.

Item Selection
Type DDR3L, 1.35 V, 16-bit, 2 Gbit (128M × 16)
Candidates ISSI IS43TR16128, Micron MT41K128M16, Nanya, Alliance. Check each for stock and status.
Package 96-ball FBGA, about 8 mm × 14 mm
FPGA pins about 49, in the DDR-capable banks
Controller LiteDRAM (BSD-2-Clause), which runs on the ECP5 with yosys and nextpnr
Precedent The OrangeCrab board has an LFE5U-25F in csfBGA285 with 128 MB of DDR3L and LiteDRAM.

A 4 Gbit (512 MB) part has the same package. The module uses 2 Gbit because the Z80 cannot use more.

Problems that DDR3L adds

  • Supply rails. DDR3L needs 1.35 V for VDD and VDDQ, and a VREF of half of VDDQ. The ECP5 banks for DDR3L also operate at 1.35 V. See usb_power.md.
  • Pins. The DDR3L banks operate at 1.35 V, so their unused pins cannot connect to the 3.3 V translators. Count the pins in each csfBGA285 bank. The 3.3 V banks must hold about 55 pins: the bus, the translator controls, the flash and the UART.
  • Layout. DDR3L needs length-matched traces and controlled impedance. The traces are short on a board of this size, which helps.
  • Supply life. Samsung stopped DDR3 production in 2024, and SK hynix stopped at the end of 2023. Micron, Nanya and ISSI continue to make DDR3. Before the schematic, find two sources of the selected part.
  • Area. The 96-ball FBGA is larger than a 54-ball SDRAM. See mechanical.md.

If the placement study or the pin count fails, the full version uses 256 Mbit SDR SDRAM (ISSI IS42S16160J, Winbond W9825G6KH or Alliance AS4C16M16SA) and a 3.3 V bank.

The routing of the DDR3L escape of the FPGA did not succeed (13 to 15 nets stayed open), and this is why the SRAM replaced the DDR3L.

Mode 2 with the DDR3L (gateware)

gateware/ddr/z80r_mem2_dram.sv connected the cache to the DDR3L controller. The z80r_top parameter INIT_PROG (default ../ddr/build/init_hw.memh) was the program of the DRAM init sequencer. Mode 2 was only for the full version (the 85F), because the lite version has no DDR3L part. The DRAM held the ROM at physical address 00000H to 7FFFFH and the RAM at 80000H to FFFFFH. A cache line was one 128-bit word of the DRAM controller. The core stayed in reset until the DRAM init was done. The boot copy of mode 2 waited for the end of the DRAM init. The copy then wrote each byte through a FIFO to the DRAM side.

mingw32-make test in gateware/ddr ran tb_mem2.sv with the core, the cache, the DRAM side and the LiteDRAM simulation core. The bench examined that the core does not start before the DRAM init is done. In the bench of the boot copy, the DRAM init lasted longer than the start wait of the copy. The bench also stopped the DRAM port for 20 µs so that the FIFO filled.

Size and speed (DDR3L design)

The full design had the debug unit, the ACIA, mode 2, the boot copy and the DDR3L controller. Place and route on the 85F, seeds 1 to 3 (8 November 2026): 11407 LUT4, 3286 flip-flops, 18 block RAMs, 1 PLL and 2 DQSBUFM. The highest bus clock was 17.6 MHz to 18.3 MHz.

On 9 November 2026 the same build on the same balls gave a highest bus clock of only 15.8 MHz to 16.6 MHz (seeds 1 to 3). The cause of the difference is not known. The pin swap of the PCB (pcb.md, "Pin swap") then gave 14.1 MHz to 15.2 MHz. The system clock of the controller reached 55.3 MHz, 58.4 MHz and 51.7 MHz on the new balls. The critical path of the bus clock is inside the FPGA (from /WAIT through the debug unit to the address register), not at a pin. The new balls change only the placement of the logic.

The system clock of the controller was 48 MHz (47.92 MHz from the PLL). The clock reached 52.2 MHz, 52.7 MHz and 49.2 MHz on the three seeds. The critical path of that clock is in LiteDRAM. With a system clock of 50 MHz, one of three seeds did not meet the timing (49.8 MHz). Thus the design used 48 MHz: a DDR3L clock of 96 MHz in place of 100 MHz, with no change to LiteDRAM. The smallest margin was 2.6 % (seed 3).

Access time (DDR3L design)

A read of the DRAM through LiteDRAM took 12 to 14 system clocks (250 ns to 290 ns at 48 MHz), plus the clock crossing in each direction. That is longer than an opcode fetch, so mode 2 had a cache.

tb_mem2.sv measured the wait states of a miss (8 November 2026):

Bus clock Wait states for each miss Time Before the two parts
4 MHz 5.1 1.28 µs 6.2
10 MHz 8.8 0.88 µs 10.0
20 MHz 12.3 615 ns 12.5

"The two parts" are the reply crossing into the bus clock with one register on the falling edge and one on the rising edge, and the bypass register on the edge of the fill. The SRAM design keeps both.

At 20 MHz, the DRAM read took most of the time. The speed of a real program depends on the hit rate of the cache. Measure the hit rate with RomWBW.

Tests of mode 2 (DDR3L design, text moved from memory.md)

The bench tb_mem2.sv also had a fifth run. This run loaded the program with the boot copy, from a 4 KB slot in a model of the flash. ROM bank 0 in the DRAM held 76H (HALT) before the copy. The DRAM init lasted longer than the start wait of the copy. The bench also stopped the DRAM port for 20 µs during the copy, so that the FIFO filled. The bench examined that the copy waited for the DRAM init, that the FIFO was full, and that the program ran from the copy.

Each of 8 deliberately broken versions of the mode 2 logic failed the bench.

Source of this page: web/ and docs/ in the z80replacement repository. Hardware: CERN-OHL-S-2.0. Other files: GPL-3.0-or-later.