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

APB Slave — APB Transactions

On-Chip Protocols · memory, fifo, protocols, apb, uart, hard, amba-apb

Implement an AMBA APB (Advanced Peripheral Bus) slave containing two 32-bit read/write registers at byte offsets 0x00 and 0x04. (Simplified educational implementation).

Write a synthesizable Verilog module named top_module matching the ports below exactly.
📐 Circuit Schematic Diagram
paddr[3:0]pselpenablepwriteprdata[31:0]pready>clkrst_nAPB SLAVEPROTOCOL INTERFACE
⚡ Timing & Synthesizability Constraints

Timing Contract: Writes commit on `posedge pclk` when `psel && penable && pwrite && pready`. Read data is valid during the ACCESS phase.

RTL Constraints: Zero wait-state implementation: `pready` is permanently 1'b1. Word-aligned addresses: 0x00 and 0x04.

Objective: Understand the 2-phase APB protocol: SETUP phase (PSEL=1, PENABLE=0) and ACCESS phase (PSEL=1, PENABLE=1), read/write data steering, and PREADY response.

Prerequisites: AMBA bus specifications, memory-mapped I/O, synchronous register maps.
NameDirWidthDescription
pclkinput1APB bus clock
preset_ninput1Active-low APB reset
paddrinput4APB address bus
pselinput1APB slave select
penableinput1APB enable (strobe)
pwriteinput11 = Write transfer, 0 = Read transfer
pwdatainput32APB write data bus
prdataoutput32APB read data bus
preadyoutput1Slave ready signal
Expected Waveform (Golden Timing Contract)
💡 Need Guidance? Progressive Hints (3 Levels)
Hint 1: Conceptual Direction & Hardware Primitives
In APB, a write transfer is committed when `psel && penable && pwrite` at `posedge pclk`.
Hint 2: Implementation Architecture & Approach
Read data `prdata` is driven when `psel && !pwrite`.
Hint 3: Edge Cases, Timing & Verilog Syntax
Drive `pready = 1'b1` for zero wait-state response.
🔒 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         pclk,
  input         preset_n,
  input  [3:0]  paddr,
  input         psel,
  input         penable,
  input         pwrite,
  input  [31:0] pwdata,
  output reg [31:0] prdata,
  output        pready
);
  reg [31:0] reg0;
  reg [31:0] reg1;

  assign pready = 1'b1; // zero wait-state response

  // Write phase
  always @(posedge pclk or negedge preset_n) begin
    if (!preset_n) begin
      reg0 <= 32'h0;
      reg1 <= 32'h0;
    end else if (psel && penable && pwrite) begin
      case (paddr[3:0])
        4'h0: reg0 <= pwdata;
        4'h4: reg1 <= pwdata;
      endcase
    end
  end

  // Read phase
  always @(*) begin
    if (psel && !pwrite) begin
      case (paddr[3:0])
        4'h0: prdata = reg0;
        4'h4: prdata = reg1;
        default: prdata = 32'h0;
      endcase
    end else begin
      prdata = 32'h0;
    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 3 · On-Chip Protocols

What You Will Learn

By solving APB Slave — APB Transactions, 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

Implement an AMBA APB (Advanced Peripheral Bus) slave containing two 32-bit read/write registers at byte offsets 0x00 and 0x04. (Simplified educational implementation).

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: Understand the 2-phase APB protocol: SETUP phase (PSEL=1, PENABLE=0) and ACCESS phase (PSEL=1, PENABLE=1), read/write data steering, and PREADY response.

Prerequisites: AMBA bus specifications, memory-mapped I/O, synchronous register maps.

Port List & Interface Timing

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

NameDirWidthDescription
pclkinput1APB bus clock
preset_ninput1Active-low APB reset
paddrinput4APB address bus
pselinput1APB slave select
penableinput1APB enable (strobe)
pwriteinput11 = Write transfer, 0 = Read transfer
pwdatainput32APB write data bus
prdataoutput32APB read data bus
preadyoutput1Slave ready signal

Timing Constraints & Synthesizable RTL Rules

⚡ Synthesizable Implementation Guidelines

Timing Contract: Writes commit on `posedge pclk` when `psel && penable && pwrite && pready`. Read data is valid during the ACCESS phase.

Synthesis Constraints: Zero wait-state implementation: `pready` is permanently 1'b1. Word-aligned addresses: 0x00 and 0x04.

Architectural Deep Dive & Implementation Walkthrough

AMBA APB is an unpipelined, low-power control bus designed by ARM for peripheral register access (UART, Timers, GPIO). Each transaction consists of two cycles: 1) SETUP cycle (`psel=1, penable=0`), where address and write data are driven; 2) ACCESS cycle (`penable=1`), where data is sampled or driven.

Common RTL Designer Pitfalls

⚠️ Common Mistakes to Avoid

['Committing writes during the SETUP phase (`penable=0`), which violates the AMBA APB protocol specification.', 'Omitting the active-low reset check, causing registers to power up in unknown (`X`) states.']

Silicon & Hardware Engineering Notes

🛠️ ASIC vs FPGA Hardware Considerations

This is a simplified educational APB implementation (no PSTRB byte enables or PSLVERR errors). Real SoC peripherals include byte strobes to support 8-bit and 16-bit register writes.

Starter RTL Code

module top_module(
  input         pclk,
  input         preset_n,
  input  [3:0]  paddr,
  input         psel,
  input         penable,
  input         pwrite,
  input  [31:0] pwdata,
  output reg [31:0] prdata,
  output        pready
);

  // APB Slave containing Reg0 (offset 0x0) and Reg1 (offset 0x4)

endmodule

Verified Reference Solution

🔒 Reveal Verified Reference RTL Solution
module top_module(
  input         pclk,
  input         preset_n,
  input  [3:0]  paddr,
  input         psel,
  input         penable,
  input         pwrite,
  input  [31:0] pwdata,
  output reg [31:0] prdata,
  output        pready
);
  reg [31:0] reg0;
  reg [31:0] reg1;

  assign pready = 1'b1; // zero wait-state response

  // Write phase
  always @(posedge pclk or negedge preset_n) begin
    if (!preset_n) begin
      reg0 <= 32'h0;
      reg1 <= 32'h0;
    end else if (psel && penable && pwrite) begin
      case (paddr[3:0])
        4'h0: reg0 <= pwdata;
        4'h4: reg1 <= pwdata;
      endcase
    end
  end

  // Read phase
  always @(*) begin
    if (psel && !pwrite) begin
      case (paddr[3:0])
        4'h0: prdata = reg0;
        4'h4: prdata = reg1;
        default: prdata = 32'h0;
      endcase
    end else begin
      prdata = 32'h0;
    end
  end
endmodule

Related RTL Problems in Level 3

Frequently Asked Questions

What does APB Slave — APB Transactions require?

Implement an AMBA APB (Advanced Peripheral Bus) slave containing two 32-bit read/write registers at byte offsets 0x00 and 0x04. (Simplified educational implementation). Implement it as Verilog module top_module matching the listed ports.

Is this design combinational or sequential?

Tags: memory, fifo, protocols, apb, uart, hard, amba-apb. 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 APB Slave — APB Transactions to assess real-world synthesizability and race-condition awareness.