Part of Curriculum: Protocol RTL Design (Module 3: APB Slave Controller & Phase FSM)
View Full Roadmap →
Level 6 Advanced ★ Advanced #41 50 pts ✓ Solved

AMBA APB Slave Controller with Wait States & Error Response

Advanced RTL & Protocol Design · advanced-rtl, apb-protocol, systemverilog, asic, fpga

Design a compliant AMBA 3/4 APB slave supporting IDLE, SETUP, and ACCESS phases with dynamic wait states and slave error signaling.

Write a synthesizable Verilog module named top_module matching the ports below exactly.
📐 Circuit Schematic Diagram
PSELPENABLEPWRITEPADDR[7:0]PRDATA[31:0]PREADYPSLVERR>clkrst_nAMBA APB SLAVE CONTRPROTOCOL INTERFACE
⚡ Timing & Synthesizability Constraints

Timing Contract: Clocked on rising edge of PCLK with active-low synchronous reset PRESETn. PREADY must assert during ACCESS phase; PSLVERR is valid only when PSEL && PENABLE && PREADY.

RTL Constraints: Fully synthesizable Verilog-2001. No # delays. Registered read data and PREADY control.

Objective: Implement a 3-state APB slave FSM (IDLE, SETUP, ACCESS) adhering to Arm AMBA protocol specifications. Handle zero-wait and wait-state transfers, register writes/reads, and PSLVERR generation for unmapped address spaces.

Prerequisites: AMBA APB specification, synchronous FSM design, bus handshaking, address decoding.
PortDirWidthDescription
PCLKinput1APB clock
PRESETninput1Active-low reset
PSELinput1Slave select
PENABLEinput1Enable strobe (asserted in ACCESS phase)
PWRITEinput11 = Write transfer, 0 = Read transfer
PADDR[7:0]input88-bit memory address
PWDATA[31:0]input32Incoming 32-bit write data
PRDATA[31:0]output32Outgoing 32-bit read data
PREADYoutput11 when transfer complete; 0 extends wait state
PSLVERRoutput11 on address out of bounds (PADDR > 8'h0C) during completed access
Expected Waveform (Golden Timing Contract)
💡 Need Guidance? Progressive Hints (3 Levels)
Hint 1: Conceptual Direction & Hardware Primitives
Recall that in APB, a transfer spans at least two clock cycles: Cycle 1 is SETUP (PSEL=1, PENABLE=0) and Cycle 2 is ACCESS (PSEL=1, PENABLE=1).
Hint 2: Implementation Architecture & Approach
Data sampling and writing happen on posedge PCLK when PSEL && PENABLE && PREADY are all asserted.
Hint 3: Edge Cases, Timing & Verilog Syntax
Check for valid address bounds (PADDR <= 8'h0C). If unmapped, assert PSLVERR = 1 during the ACCESS cycle and drive a benign default value (e.g., 32'hDEADBEEF) onto PRDATA.
🔒 Reveal Verified Reference RTL Solution (Click to expand)
⚠️ Self-Discovery Warning: Try solving and simulating first! Viewing the verified reference implementation will bypass the real debugging experience.
Verified Synthesizable RTL
module top_module (
  input  wire        PCLK,
  input  wire        PRESETn,
  input  wire        PSEL,
  input  wire        PENABLE,
  input  wire        PWRITE,
  input  wire [7:0]  PADDR,
  input  wire [31:0] PWDATA,
  output wire [31:0] PRDATA,
  output wire        PREADY,
  output wire        PSLVERR
);

  reg [31:0] mem [0:3];
  wire addr_valid = (PADDR <= 8'h0C) && (PADDR[1:0] == 2'b00);
  wire [1:0] reg_idx = PADDR[3:2];

  assign PREADY = 1'b1;
  assign PSLVERR = (PSEL && PENABLE && !addr_valid);
  assign PRDATA = (PSEL && !PWRITE) ? (addr_valid ? mem[reg_idx] : 32'hDEADBEEF) : 32'h0;

  always @(posedge PCLK or negedge PRESETn) begin
    if (!PRESETn) begin
      mem[0] <= 32'h0;
      mem[1] <= 32'h0;
      mem[2] <= 32'h0;
      mem[3] <= 32'h0;
    end else begin
      if (PSEL && PENABLE && PWRITE && addr_valid) begin
        mem[reg_idx] <= PWDATA;
      end
    end
  end

endmodule
Verilog-2001 / SV Saved
Font: |
// Click Run Tests (or press Ctrl+Enter) to compile your RTL and simulate against hidden testbenches.
Simulation Timing Diagram (VCD Waveform)
100%
No simulation waveform yet. Run tests to simulate and generate VCD traces.
No compilation run yet. Syntax warnings and elaboration messages will appear here.
No simulation output yet. Raw stdout from vvp will appear here.

RTL Problems / Level 6 · Advanced RTL & Protocol Design

What You Will Learn

By solving AMBA APB Slave Controller with Wait States & Error Response, you will acquire core industry skills:

  • Synthesizable hardware modeling in standard Verilog-2001 / SystemVerilog.
  • Correct handling of interface port contracts, edge-triggered clocks, and active-low/high resets.
  • Simulation waveform interpretation and debugging using timing diagrams (VCD traces).
  • Architectural avoidance of timing violations, glitching hazards, and synthesis warnings.

Problem Statement & Requirements

Design a compliant AMBA 3/4 APB slave supporting IDLE, SETUP, and ACCESS phases with dynamic wait states and slave error signaling.

Hardware design teams at leading semiconductor firms evaluate these exact port contracts, race-condition assertions, and corner cases during technical design reviews and ASIC engineer interviews.

Objective: Implement a 3-state APB slave FSM (IDLE, SETUP, ACCESS) adhering to Arm AMBA protocol specifications. Handle zero-wait and wait-state transfers, register writes/reads, and PSLVERR generation for unmapped address spaces.

Prerequisites: AMBA APB specification, synchronous FSM design, bus handshaking, address decoding.

Port List & Interface Timing

The hidden testbench instantiates top_module. Module port names and bit-widths must match the interface contract exactly:

PortDirWidthDescription
PCLKinput1APB clock
PRESETninput1Active-low reset
PSELinput1Slave select
PENABLEinput1Enable strobe (asserted in ACCESS phase)
PWRITEinput11 = Write transfer, 0 = Read transfer
PADDR[7:0]input88-bit memory address
PWDATA[31:0]input32Incoming 32-bit write data
PRDATA[31:0]output32Outgoing 32-bit read data
PREADYoutput11 when transfer complete; 0 extends wait state
PSLVERRoutput11 on address out of bounds (PADDR > 8'h0C) during completed access

Timing Constraints & Synthesizable RTL Rules

⚡ Synthesizable Implementation Guidelines

Timing Contract: Clocked on rising edge of PCLK with active-low synchronous reset PRESETn. PREADY must assert during ACCESS phase; PSLVERR is valid only when PSEL && PENABLE && PREADY.

Synthesis Constraints: Fully synthesizable Verilog-2001. No # delays. Registered read data and PREADY control.

Architectural Deep Dive & Implementation Walkthrough

AMBA APB Protocol Fundamentals

The Advanced Peripheral Bus (APB) is part of the Arm AMBA protocol family optimized for minimal power and reduced interface complexity. Unlike high-performance burst protocols (such as AXI), APB is designed for non-pipelined, register-mapped control transfers.

The APB Transfer Cycle

  • IDLE State: Normal default state. PSEL and PENABLE are deasserted.
  • SETUP Phase: When a transfer is requested, the bus master drives PADDR, PWRITE, and PWDATA (if writing), and asserts PSEL = 1 while keeping PENABLE = 0.
  • ACCESS Phase: On the next clock edge, the master asserts PENABLE = 1. The slave asserts PREADY = 1 to complete the transaction, or holds PREADY = 0 to insert wait states.

If an invalid address is targeted, the slave asserts PSLVERR = 1 during the completed ACCESS phase to report a transfer error to the master.

Common RTL Designer Pitfalls

⚠️ Common Mistakes to Avoid

Updating internal registers during the SETUP phase (when PENABLE=0) instead of the ACCESS phase (when PSEL && PENABLE && PREADY). Inverting PENABLE or letting PREADY float.

Silicon & Hardware Engineering Notes

🛠️ ASIC vs FPGA Hardware Considerations

In high-frequency SoC architectures, PREADY and PRDATA paths should be registered to avoid combinational feedback loops across chip partition boundaries.

Starter RTL Code

module top_module (
  input  wire        PCLK,
  input  wire        PRESETn,
  input  wire        PSEL,
  input  wire        PENABLE,
  input  wire        PWRITE,
  input  wire [7:0]  PADDR,
  input  wire [31:0] PWDATA,
  output wire [31:0] PRDATA,
  output wire        PREADY,
  output wire        PSLVERR
);

  // Implement 4 internal 32-bit registers at addresses 8'h00, 8'h04, 8'h08, 8'h0C.
  // Addresses > 8'h0C should assert PSLVERR = 1 when transfer completes.
  // PREADY = 1 completes the transfer.

endmodule

Verified Reference Solution

🔒 Reveal Verified Reference RTL Solution
module top_module (
  input  wire        PCLK,
  input  wire        PRESETn,
  input  wire        PSEL,
  input  wire        PENABLE,
  input  wire        PWRITE,
  input  wire [7:0]  PADDR,
  input  wire [31:0] PWDATA,
  output wire [31:0] PRDATA,
  output wire        PREADY,
  output wire        PSLVERR
);

  reg [31:0] mem [0:3];
  wire addr_valid = (PADDR <= 8'h0C) && (PADDR[1:0] == 2'b00);
  wire [1:0] reg_idx = PADDR[3:2];

  assign PREADY = 1'b1;
  assign PSLVERR = (PSEL && PENABLE && !addr_valid);
  assign PRDATA = (PSEL && !PWRITE) ? (addr_valid ? mem[reg_idx] : 32'hDEADBEEF) : 32'h0;

  always @(posedge PCLK or negedge PRESETn) begin
    if (!PRESETn) begin
      mem[0] <= 32'h0;
      mem[1] <= 32'h0;
      mem[2] <= 32'h0;
      mem[3] <= 32'h0;
    end else begin
      if (PSEL && PENABLE && PWRITE && addr_valid) begin
        mem[reg_idx] <= PWDATA;
      end
    end
  end

endmodule

Related RTL Problems in Level 6

  • Manchester Encoder — Combine a data bit with the clock to produce a Manchester-encoded line signal — the self-clocking encoding used in classic Ethernet and RFID.
  • Manchester Decoder — Recover the original data bit from a Manchester-encoded line signal — the exact inverse of the Manchester Encoder problem.
  • Quadrature Rotary Encoder Decoder — Decode the two-phase A/B signal from a real rotary knob or mouse wheel into a direction and position count — sample B on every rising edge of A.

Frequently Asked Questions

What does AMBA APB Slave Controller with Wait States & Error Response require?

Design a compliant AMBA 3/4 APB slave supporting IDLE, SETUP, and ACCESS phases with dynamic wait states and slave error signaling. Implement it as Verilog module top_module matching the listed ports.

Is this design combinational or sequential?

Tags: advanced-rtl, apb-protocol, systemverilog, asic, fpga. If a clock signal is present in the port table, implement it as sequential logic; otherwise, use continuous assignments or combinational blocks.

How is my solution graded?

A hidden SystemVerilog testbench simulates your module in the cloud judge. You pass when all directed corner cases match the golden model and the VCD timing waveform matches the contract.

How does this challenge help with semiconductor interviews?

Technical interviewers at NVIDIA, Qualcomm, Apple, and Intel routinely ask candidates to code, debug, and explain the timing waveforms of AMBA APB Slave Controller with Wait States & Error Response to assess real-world synthesizability and race-condition awareness.