AMBA Protocol

APB — Advanced Peripheral Bus

APB is the simplest and most power-efficient bus in the AMBA family. Designed for low-bandwidth peripheral access — UART, SPI, GPIO, timers — it forms the last mile of most ARM SoC designs.

AMBA 2 / AMBA 3 / AMBA 5 2-cycle minimum transfer Non-pipelined

1. Where APB Fits in AMBA

AMBA (Advanced Microcontroller Bus Architecture) is ARM's open on-chip bus specification. It defines a hierarchy of protocols suited to different bandwidth and latency requirements:

ProtocolUse CaseKey FeatureBandwidth
AXI4CPU, DDR, DMA, GPUSeparate R/W channels, out-of-orderVery High
AHBOn-chip SRAM, FlashPipelined, burst, multi-masterHigh
APBUART, SPI, GPIO, TimerSimple, low power, no pipelineLow

APB is always a slave-only bus — it hangs off an AHB-to-APB or AXI-to-APB bridge. The bridge converts high-speed bus accesses into APB transactions.

Key fact: APB is intentionally simple. It has no burst mode, no pipelining, and no out-of-order transactions. This makes it easy to implement compliant peripherals.

2. APB Signal Definition

All signals are driven by the master (bridge) except PRDATA, PREADY, and PSLVERR which are driven by the slave.

SignalDriverWidthDescription
PCLKSystem1Bus clock — all transfers are synchronous to the rising edge
PRESETnSystem1Active-LOW reset — resets both master and slave
PADDRMaster32Address bus — selects register within slave
PSELxMaster1Slave select — one per slave in the system
PENABLEMaster1Enable signal — HIGH on 2nd cycle of transfer
PWRITEMaster1Direction: HIGH = write, LOW = read
PWDATAMaster32Write data bus
PSTRBMaster4Write strobes (APB4) — byte enables for PWDATA
PRDATASlave32Read data bus
PREADYSlave1Transfer complete — slave inserts wait states when LOW
PSLVERRSlave1Error response (APB3+) — HIGH indicates failed transfer
PREADY note: Tie PREADY = 1'b1 if your slave never needs wait states. Leaving it undriven can cause the bus to stall indefinitely.

3. APB State Machine

The APB master operates a simple 3-state FSM. Every transfer takes a minimum of 2 clock cycles.

IDLE PSEL=0 SETUP PSEL=1, PENABLE=0 ACCESS PSEL=1, PENABLE=1 PSEL=1 always PREADY=1, no next transfer PREADY=1, next transfer PREADY=0

4. Write Transfer

No Wait States (minimum 2 cycles)

SETUP ACCESS PCLK PADDR ADDR PWRITE HIGH (write) PSEL PENABLE PWDATA WRITE DATA PREADY T1 T2 T3 ✓ T4

5. Read Transfer

SETUP ACCESS PCLK PADDR ADDR PWRITE LOW (read) PSEL PENABLE PRDATA READ DATA PREADY T1 T2 T3 ✓

6. Wait States — PREADY

A slow slave drives PREADY=0 in the ACCESS phase to insert wait states. The bus master holds all signals stable until the slave is ready.

SETUP ACCESS (3 cycles) PCLK PSEL PENABLE PREADY WAIT DONE T1 T2 T3(wait) T4 ✓
Important: During wait states the master must hold PADDR, PWRITE, PWDATA, PSEL, and PENABLE stable. Changing any of these while PREADY=0 violates the APB spec.

7. Error Response — PSLVERR

Introduced in APB3. Slave asserts PSLVERR=1 in the same cycle as PREADY=1 to signal a failed transfer (e.g., invalid address, write to read-only register).

PREADYPSLVERRResult
10Transfer OK
11Transfer ERROR — master logs fault
00Wait state — transfer ongoing
01Reserved — do not use
Tip: For peripherals with no error conditions, tie PSLVERR = 1'b0 permanently.

8. Verilog RTL Implementation

APB Slave — Register File (4 × 32-bit registers)

APB Slave Verilog
module apb_slave #(
  parameter DATA_W = 32,
  parameter ADDR_W = 32
)(
  input  wire              PCLK,
  input  wire              PRESETn,
  input  wire [ADDR_W-1:0] PADDR,
  input  wire              PSEL,
  input  wire              PENABLE,
  input  wire              PWRITE,
  input  wire [DATA_W-1:0] PWDATA,
  output reg  [DATA_W-1:0] PRDATA,
  output wire              PREADY,
  output wire              PSLVERR
);
  // 4 internal 32-bit registers at offsets 0x00, 0x04, 0x08, 0x0C
  reg [DATA_W-1:0] regs[0:3];

  // No wait states, no errors
  assign PREADY  = 1'b1;
  assign PSLVERR = 1'b0;

  // Write — sample on ACCESS phase
  always @(posedge PCLK or negedge PRESETn) begin
    if (!PRESETn) begin
      regs[0] <= 0; regs[1] <= 0;
      regs[2] <= 0; regs[3] <= 0;
    end else if (PSEL && PENABLE && PWRITE && PREADY) begin
      regs[PADDR[3:2]] <= PWDATA;
    end
  end

  // Read — combinational in SETUP / ACCESS
  always @(*) begin
    if (PSEL && !PWRITE)
      PRDATA = regs[PADDR[3:2]];
    else
      PRDATA = 32'h0;
  end

endmodule

APB Master (Simple — for testbench)

APB Master Task Verilog
// APB write task
task apb_write;
  input [31:0] addr, data;
  begin
    @(posedge PCLK);
    // SETUP phase
    PADDR   <= addr;
    PWRITE  <= 1'b1;
    PWDATA  <= data;
    PSEL    <= 1'b1;
    PENABLE <= 1'b0;
    @(posedge PCLK);
    // ACCESS phase
    PENABLE <= 1'b1;
    @(posedge PCLK);
    while (!PREADY) @(posedge PCLK); // wait
    // End transfer
    PSEL    <= 1'b0;
    PENABLE <= 1'b0;
  end
endtask

// APB read task
task apb_read;
  input  [31:0] addr;
  output [31:0] data;
  begin
    @(posedge PCLK);
    PADDR   <= addr;
    PWRITE  <= 1'b0;
    PSEL    <= 1'b1;
    PENABLE <= 1'b0;
    @(posedge PCLK);
    PENABLE <= 1'b1;
    @(posedge PCLK);
    while (!PREADY) @(posedge PCLK);
    data    = PRDATA;
    PSEL    <= 1'b0;
    PENABLE <= 1'b0;
  end
endtask

9. Where APB Is Used

PeripheralWhy APB?
UART / SPI / I2C controllersSlow, register-based config — doesn't need high bandwidth
GPIOSimple read/write to pin registers
Timers / WatchdogInfrequent register access for control/status
Interrupt controller (VIC)Low-frequency enable/status reads
PLL / Clock controlOne-time config via register writes
Power management unitLow-power, infrequent access

10. Interview Questions

Q: What is the minimum number of cycles for an APB transfer?

2 cycles — one SETUP cycle and one ACCESS cycle (assuming PREADY=1 with no wait states).

Q: When is PENABLE asserted?

In the second cycle of the transfer (ACCESS phase). It is LOW during SETUP and HIGH during ACCESS.

Q: Can PADDR or PWDATA change during a transfer?

No. All master-driven signals must remain stable from SETUP through the end of ACCESS (when PREADY=1).

Q: What happens if PREADY stays LOW forever?

The bus stalls indefinitely. In real designs, a watchdog or timeout mechanism at the bridge detects this and generates an error response.

Q: Difference between APB2, APB3, and APB4?

Q: Can APB have multiple masters?

No. APB is a single-master bus. The AHB-to-APB or AXI-to-APB bridge acts as the sole master. Multiple AHB/AXI masters access APB only through the bridge.


11. APB in Real SoC Design — Practical Considerations

APB Register Map Design

In practice, the most important design decision for an APB slave is the register map — how PADDR values map to internal configuration and status registers. A well-designed register map groups related controls together at aligned addresses, separates read-only status from read-write control, and leaves address gaps for future expansion. By convention, each register occupies 4 bytes (word-aligned), so PADDR[1:0] is typically ignored. The APB slave decodes PADDR[N:2] where N is the number of address bits needed to cover all registers.

A common pitfall is designing a register map with write-only registers (registers that can be written but where reading returns 0). While technically valid in the APB spec, write-only registers complicate software driver development because the CPU cannot read-back the current value to perform read-modify-write operations. Prefer registers that return their last written value on reads — this is called "read-back support" and is a strong design recommendation for all control registers.

Timing Constraints for APB

APB operates synchronously to PCLK. Because APB is a low-bandwidth peripheral bus, PCLK is typically derived from a divided-down version of the main system clock. A 1 GHz SoC might run AXI4 at 1 GHz, AHB at 500 MHz, and APB at 100–250 MHz. This means the APB bridge contains a clock domain crossing: the AHB or AXI side runs at high frequency, and the APB side at a lower frequency. The bridge must synchronize control signals across this boundary, adding latency to each APB transfer. This latency is acceptable because APB is only used for peripheral register accesses where timing is not critical.

STA (Static Timing Analysis) for APB slaves is straightforward compared to AXI4: all paths are synchronous to one clock (PCLK), there is no pipelining, and the maximum combinational depth is typically 2–3 gates (address decode + mux). The main timing concern is PREADY — if PREADY is generated combinationally from a memory or state machine, it must meet the setup time requirement of the master's PCLK edge. Most designers register PREADY to avoid this combinational path.

APB in Power-Managed SoCs

APB's simple, synchronous architecture makes it particularly well-suited for power-managed designs. Because APB has no pipeline and no outstanding transactions, the APB slave can be placed in a power island that is fully shut down when unused. The AHB-to-APB bridge simply stalls (holds PREADY low or asserts PSLVERR) if the APB domain is powered off. When the software driver needs to access the peripheral, it wakes the power domain, waits for the wake-up time (typically microseconds), and then proceeds with APB transfers. This coarse-grained power management is used extensively in mobile SoCs for peripherals like Bluetooth controllers, camera interfaces, and audio codecs.

Verifying APB Compliance

A complete APB verification environment checks the following properties: the slave never asserts PSLVERR without PREADY being simultaneously high; PRDATA is stable before PREADY goes high; the slave holds PREADY low for the correct number of wait states; PADDR, PWRITE, and PWDATA are stable throughout the SETUP and ACCESS phases; PSELx is not deasserted before PREADY; and the slave correctly resets all registers to their default values on PRESETn. A UVM-based APB VIP (Verification IP) generates constrained-random traffic and checks these properties using assertions. For most VLSI interview scenarios, demonstrating knowledge of these protocol rules — not just the waveform diagrams — separates candidates who understand the protocol from those who have memorized the timing diagram.