FPGA Prototypes

An FPGA prototype runs the chip's RTL on a real FPGA, fast enough for software and real interfaces. Getting there changes clocks, memories and pads. This page builds ap_soc for an FPGA and reads the report; no board is used.

You Will Be Able To

  • Say what an FPGA prototype is for, and how it differs from an emulator.
  • Name what changes when ASIC RTL goes onto an FPGA: clocks, memories, pads.
  • Read a synthesis and place-and-route report: resources, block RAM, clock estimates.
  • Say what a build report does not prove.
Lesson
V13.7
Time
24 min
Runs on
Your browser
Check
5 questions

The software team wants a board on their desks with the chip on it, long before silicon. The hardware team has RTL and an FPGA. Between them is a build that must fit, close timing and keep the chip's behaviour.

ap_soc as a Report of Cells and a Clock EstimateThe digital chip goes through FPGA synthesis and place and route; what comes out is a list of resources and clock estimates.
  • File
  • Clock / reset
  • Tool
  • Report
  • External
  • Data
  • Clock
ap_soc as a Report of Cells and a Clock EstimateThe digital chip goes through FPGA synthesis and place and route; what comes out is a list of resources and clock estimates. file ap_soc RTL core, fabric,peripherals clock reset analog.sv replaces the analogmodel tool Yosyssynth_ecp5 LUTs, flops, blockRAM tool nextpnr-ecp5 place and route report 10,424 logic cells 3,982 flops, 34 blockRAMs report 28.37 MHz lowest target 25 MHz external Board none: nothing wasloaded one board clocknetlistresourcestiming
  1. file ap_soc RTLcore, fabric, peripherals
    • Yosys synth_ecp5
  2. clock reset analog.svreplaces the analog model
    • one board clock → Yosys synth_ecp5
  3. tool Yosys synth_ecp5LUTs, flops, block RAM
    • netlist → nextpnr-ecp5
  4. tool nextpnr-ecp5place and route
    • resources → 10,424 logic cells
    • timing → 28.37 MHz lowest
  5. report 10,424 logic cells3,982 flops, 34 block RAMs
  6. report 28.37 MHz lowesttarget 25 MHz
  7. external Boardnone: nothing was loaded
  1. Swap what an FPGA cannot be

    The oscillators, PLL and power-on cell become a small digital model driven by one board clock.

  2. Synthesize and place

    Yosys maps the chip onto LUTs, flops and block RAM; nextpnr places and routes it.

  3. Read the report

    Resources used, and an estimate of the fastest clock for each clock net.

  4. Stop there

    No pin constraints, no bitstream on a board. This is where our prototype ends.

Read the diagram as text
  • ap_soc RTL: core, fabric, peripherals
  • analog.sv: replaces the analog model
  • Yosys synth_ecp5: LUTs, flops, block RAM
  • nextpnr-ecp5: place and route
  • 10,424 logic cells: 3,982 flops, 34 block RAMs
  • 28.37 MHz lowest: target 25 MHz
  • Board: none: nothing was loaded
  • ap_soc RTL → Yosys synth_ecp5
  • analog.sv → Yosys synth_ecp5: one board clock
  • Yosys synth_ecp5 → nextpnr-ecp5: netlist
  • nextpnr-ecp5 → 10,424 logic cells: resources
  • nextpnr-ecp5 → 28.37 MHz lowest: timing

Yosys 0.70+290, nextpnr nextpnr-0.11.1-85-ga2c64799; LFE5U-85F, CABGA381, speed 6, seed 1. Rebuilt in 133 s by npm run build:fast-fpga.

Before You Start

Read Emulation, Honestly first. Synthesis reports are read in the RTL track; this page reads one for a whole chip.

Five questions this page answers
Question
1What is an FPGA prototype for, and how is it unlike an emulator?
2What must change in ASIC RTL to build it for an FPGA?
3What does ap_soc use on an ECP5 FPGA?
4How fast might it run, and what does that estimate rest on?
5What does a build report not prove?

The Idea: The Same RTL on Hardware You Can Buy

An FPGA is a chip of programmable logic. Build the RTL for it and the design runs as real hardware on a board with real connectors. It runs far faster than any simulation. Software can run on it for hours, and real cables can plug in.

Unlike an emulator, a prototype is built for speed and copies, not for debug. Seeing inside it is hard. It is used once the design works, so that software teams and system tests get a fast, cheap stand-in for the chip.

ASIC RTL does not go onto an FPGA unchanged. Its clocks come from analog parts the FPGA lacks; its memories must fit the FPGA's block RAM; its pads become FPGA pins.

New Words

New words on this page
WordMeaning
FPGAA chip of programmable logic: look-up tables, flip-flops, block RAM and IO cells.
LUTLook-up table: a small programmable logic cell, here with four inputs (LUT4).
Block RAMA fixed memory block of the FPGA; on ECP5, DP16KD holds 16 Kbit of data (18 with parity).
Place and routeChoosing where each cell goes on the FPGA and how they are wired.
Clock estimateThe fastest clock at which the router's delays still meet timing, for one clock net.
Derived clockA clock made by logic inside the design, not by a clock pin or a PLL.
PrototypeThe chip's RTL running on FPGAs, for software and system tests before silicon.

The Smallest Example: Where 64 KiB of SRAM Goes

One DP16KD block holds 16 Kbit of data: 2 KiB. ap_soc has 64 KiB of SRAM and a 4 KiB ROM. Work out how many blocks they need before you look at the report.

Memories into block RAM
MemorySizeBlocks of 2 KiB
SRAM64 KiB32
ROM4 KiB2
Total34

The report shows 34 DP16KD blocks. The memories went into block RAM, as they should; nothing was built from flip-flops.

That only works if each memory is written in the shape a block RAM has. Rule 2 below says what that shape is.

The Rules

  1. Rule 1: Replace what an FPGA cannot be.

    Oscillators, PLLs, power-on cells and power switches become simple digital models, or FPGA clock resources.

  2. Rule 2: Write memories in the FPGA's shape.

    A block RAM has a write port and a read port registered on the clock, and nothing more. Code that asks for anything else is built from logic cells or flip-flops.

  3. Rule 3: Keep one RTL with a switch.

    The ASIC and FPGA builds differ in IO, clocks and memories. Select those few parts; keep the core logic one code.

  4. Rule 4: Read the report per clock.

    Each clock net has its own estimate. The lowest may be on a clock made by logic, and the tool's net names do not say which.

  5. Rule 5: A report is not a board.

    Without pin constraints, board timing and a run on hardware, the report proves fit and an estimate, nothing more.

Sources for These Rules

Emulation and prototyping; how an emulator differs from an FPGA prototype: MEHTA-DV 12.2.1, 12.2.3.

ASIC and FPGA builds differ in IO, clocks (PLL against DLL) and memories, selected at integration: MEHTA-DV 15.4.4. Timing closure after place and route: 15.4.3.

This build: tools/soc/fast-platforms/README.md, "ECP5 implementation report", and facts 27.14. They say what analog.sv replaces and what is not checked.

The Lab: The Build Report of ap_soc

The command npm run build:fast-fpga synthesized the whole digital chip, with the RTL core, for an ECP5 LFE5U-85F. Then it placed and routed it. The analog model was replaced by this file:

tools/soc/fast-platforms/fpga/analog.sv
// Single external FPGA clock. The digital boot controller still sequences its grants.
module ap_analog_model(input wire clk_ref, osc_start, pll_start, per_power_on,
  output wire clk_rc, clk_aon, clk_pll, osc_ready, pll_locked, por_n, per_pwr_good);
  reg [3:0] startup = 0;
  always @(posedge clk_ref) startup <= {startup[2:0], 1'b1};
  assign por_n = startup[3];
  assign clk_rc = clk_ref, clk_aon = clk_ref, clk_pll = clk_ref;
  assign osc_ready = osc_start, pll_locked = pll_start, per_pwr_good = per_power_on;
endmodule
Resources (from report.json)
ResourceUsedAvailablePer cent
Logic cells10,42483,64012
Flip-flops3,98283,6404
Block RAM (DP16KD)3420816
IO cells233656

Rule 2 at work: 34 block RAMs, the 32 plus 2 of the worked example. Rule 1: one board clock feeds every clock the chip expected from its analog parts.

The three lowest clock estimates of 9, target 25 MHz.
  28.37 MHz  $glbnet$u_watchdog.supervisor.first_key_LUT4_D_Z_LUT4_D_Z_LUT4_Z_D_LUT
  45.72 MHz  $glbnet$TDO_$_TBUF__Y_A_TRELLIS_FF_Q_DI_LUT4_Z_B_LUT4_D_Z_TRELLIS_FF_D
  84.07 MHz  $glbnet$u_uart.fifo_q.0.0_DO_LUT4_D_Z_LUT4_Z_D_LUT4_Z_D_PFUMX_Z_ALUT_L

Rule 4 at work. The lowest estimate, 28.37 MHz, carries a long name that starts in the watchdog. That name is made up by the synthesis tool from nearby connections, so do not read it as a place. So we followed the net in the synthesized netlist. A look-up table drives it, fed by the board clock pad and the two grant flip-flops of the clock mux, ap_clk_mux. It is clk_sys, the system clock, and it clocks 976 flip-flops.

So the slowest paths are the chip's own, on its main clock, and the estimate still beats the 25 MHz target. The board clock's net itself clocks 183 flip-flops and reached 90.61 MHz. On this build clk_sys is made by logic from the board clock: a derived clock. The tool times paths inside each clock net only. Paths between the two nets, and the delay through the mux, need their own timing analysis, as the kit manual says.

Rule 5: there was no pin constraint file, the pins were placed automatically, and nothing was loaded onto a board.

Why It Is Built This Way

Why replace the analog parts with a model of a few lines? Because the FPGA has no RC oscillator or the chip's PLL. What matters for the digital logic is that clocks arrive and reset is released in order; analog.sv keeps that and nothing more.

Why place and route at all, with no board? Because synthesis alone says nothing about wires. Only after routing are the delays known, and with them a clock estimate.

Why so few IO cells? The chip has few pads: a clock, reset, a strap, JTAG and sixteen IO pads. A prototype of a phone chip would need hundreds.

Traps

The first trap is an ASIC memory model written for simulation comfort. It simulates neatly, but asks for something a block RAM cannot do, and on the FPGA it becomes thousands of cells.

The second is reading the clock pin's estimate and stopping. Here the pin's net looked fast. The real system clock came out of the clock mux, under a generated name, and was the slowest.

The third is calling a routed report a working prototype. Real pins, real board delays and real devices on the board are a separate job, and none was done here.

At Scale

ap_soc~12 blocks
Phone-class SoChundreds of blocks

This section looks ahead. ap_soc fits one mid-size FPGA.

  1. Many FPGAs

    A large chip is split across several FPGAs; the signals between them pass through pins and slow the clock.

  2. Visibility added

    Teams add trace buffers in block RAM to see inside, at a cost in resources.

  3. Copies

    Once it works, the prototype is copied for many software engineers.

Try It

Run it: the FPGA's replacement for the chip's analog block, edge by edge.

On which edge is power-on reset released? Why that edge?

Start the PLL later. What does pll_locked do?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: edge 1: por_n 0 pll_locked 0 clk_pll follows clk_ref: 1 edge 2: por_n 0 pll_locked 1 clk_pll follows clk_ref: 1 edge 3: por_n 0 pll_locked 1 clk_pll follows clk_ref: 1 edge 4: por_n 1 pll_locked 1 clk_pll follows clk_ref: 1 edge 5: por_n 1 pll_locked 1 clk_pll follows clk_ref: 1 edge 6: por_n 1 pll_locked 1 clk_pll follows clk_ref: 1 edge 7: por_n 1 pll_locked 1 clk_pll follows clk_ref: 1

Check Yourself

Predict the outputThe PLL is now started on edge 5. What is the last line printed?
// The chip's analog block, as the FPGA build replaces it: every clock is the board clock, and power-on reset is
// released by a four-flop shift register.
// Single external FPGA clock. The digital boot controller still sequences its grants.
module ap_analog_model(input wire clk_ref, osc_start, pll_start, per_power_on,
  output wire clk_rc, clk_aon, clk_pll, osc_ready, pll_locked, por_n, per_pwr_good);
  reg [3:0] startup = 0;
  always @(posedge clk_ref) startup <= {startup[2:0], 1'b1};
  assign por_n = startup[3];
  assign clk_rc = clk_ref, clk_aon = clk_ref, clk_pll = clk_ref;
  assign osc_ready = osc_start, pll_locked = pll_start, per_pwr_good = per_power_on;
endmodule

module tb;
  reg clk = 0, osc_start = 0, pll_start = 0, per_power_on = 0;
  wire clk_rc, clk_aon, clk_pll, osc_ready, pll_locked, por_n, per_pwr_good;
  ap_analog_model m(.clk_ref(clk), .osc_start, .pll_start, .per_power_on, .clk_rc, .clk_aon, .clk_pll,
                    .osc_ready, .pll_locked, .por_n, .per_pwr_good);
  always #20 clk = ~clk;                         // the board clock
  integer e;
  initial begin
    for (e = 1; e <= 7; e = e + 1) begin
      @(posedge clk); #1;
      if (e == 5) pll_start = 1;
      $display("edge %0d: por_n %b pll_locked %b clk_pll follows clk_ref: %b", e, por_n, pll_locked, clk_pll === clk);
    end
    $finish;
  end
endmodule
ConceptHow does an FPGA prototype differ from an emulator?
ConceptHow many DP16KD blocks did ap_soc use?
ConceptWhat was the lowest clock estimate on?
ConceptWhat does the report not prove?

Common Mistakes

Wrong Read a memory combinationally in code meant for the FPGA.

Block RAM reads on a clock edge; the tool builds the memory from logic cells.

Fix Register the read on the clock, as the block RAM does.

Wrong Read only the clock pin's estimate, and trust net names.

A derived clock can be the slowest, under a name the tool made up.

Fix Read every clock net, and trace the slowest one in the netlist.

Wrong Call a routed report a prototype.

No pins, no board timing, no run on hardware.

Fix Say what the report proves: fit and an estimate.

Remember

  • A prototype runs the RTL on FPGAs: fast, few signals visible, for software and system tests.
  • Clocks, memories and pads change between the ASIC and the FPGA build; the logic stays one code.
  • ap_soc on an ECP5: 10,424 logic cells, 3,982 flops, 34 block RAMs; lowest estimate 28.37 MHz, on clk_sys.
  • The report proves fit and an estimate; no board was used.

Practice

Report a problem with this page