Module 8: Protocol Projects | Intermediate UVM

APB Verification Project

Build a reusable UVM environment that verifies APB transfers, protocol timing, reset behavior, wait states, and error responses.

Learning objectives

  • Translate APB protocol requirements into executable UVM scenarios.
  • Build an APB agent with a sequencer, driver, and monitor.
  • Verify read and write transfers across setup and access phases.
  • Check transfer completion, wait states, and error responses.
  • Use a scoreboard, assertions, and functional coverage as independent verification evidence.
  • Debug and reproduce an APB failure using transaction context and a known random seed.

Step 1: Understand the APB transfer contract

APB is designed for simple, low-bandwidth register and peripheral accesses. Its verification challenge is not high throughput; it is making sure that every transfer follows the required control and timing sequence.

An APB transfer is organized around two fundamental phases:

  • Setup: the master selects the peripheral and presents the address, direction, and write data when applicable.
  • Access: the transfer remains selected while the peripheral completes the operation. PREADY determines when the transfer can complete.

For a write, the testbench should verify that the address and write data remain stable for the required transfer. For a read, the monitor should capture the returned PRDATA when the transfer completes.

Also treat PSLVERR as part of the protocol contract. An error response is not automatically a testbench failure; it may be the expected result of a negative test.

Verification mindset: Separate “the DUT correctly returned an APB error” from “the APB protocol itself was violated.” The expected response belongs to the test scenario; protocol legality belongs to the checker.

Step 2: Define the APB transaction

A useful sequence item captures the information needed to describe an APB operation without tying the test to individual interface signals.

class apb_transaction extends uvm_sequence_item;


rand bit [31:0] addr;
rand bit        write;
rand bit [31:0] wdata;


   bit [31:0] rdata;
   bit        ready;
   bit        error;


`uvm_object_utils(apb_transaction)

function new(string name = "apb_transaction");
super.new(name);
endfunction
endclass

The sequence item represents intent. The driver is responsible for translating that intent into APB pin activity, while the monitor reconstructs the actual transfer from the interface.

This distinction becomes important when debugging. If the sequence requested a write but the monitor observed a read, the problem may be in the driver or interface timing rather than in the sequence.

Step 3: Build the APB agent

The APB agent should encapsulate protocol-specific mechanics so that tests can focus on scenarios rather than signal-level timing.

class apb_agent extends uvm_agent;


apb_sequencer sequencer;
apb_driver    driver;
apb_monitor   monitor;

function void build_phase(uvm_phase phase);
super.build_phase(phase);


monitor = apb_monitor::type_id::create("monitor", this);

if (get_is_active() == UVM_ACTIVE) begin
  sequencer = apb_sequencer::type_id::create("sequencer", this);
  driver    = apb_driver::type_id::create("driver", this);
end


endfunction
endclass

Notice that the monitor exists for both active and passive configurations, while the sequencer and driver are only needed when the agent actively drives APB traffic. This makes the agent reusable in environments where the DUT is observed rather than controlled by the testbench.

Step 4: Drive a legal APB transfer

The driver should make the APB phase transition explicit. A simplified transfer sequence is:

  1. Drive the transfer fields during the setup phase.
  2. Assert the appropriate select signal.
  3. Move into the access phase.
  4. Keep required signals stable while waiting for PREADY.
  5. Complete the transfer when PREADY is asserted.
  6. Capture the response and return the transaction result.
task drive_transfer(apb_transaction tr);


// Setup phase
vif.psel    <= 1'b1;
vif.penable <= 1'b0;
vif.paddr   <= tr.addr;
vif.pwrite  <= tr.write;
vif.pwdata  <= tr.wdata;

@(posedge vif.pclk);

// Access phase
vif.penable <= 1'b1;

do begin
@(posedge vif.pclk);
end while (!vif.pready);

tr.rdata = vif.prdata;
tr.error = vif.pslverr;

// Return to idle
vif.psel    <= 1'b0;
vif.penable <= 1'b0;
endtask

This example is intentionally simplified. A production driver should also account for reset synchronization, interface-specific timing requirements, multiple APB selections where applicable, and clean handling of invalid or unsupported requests.

Step 5: Observe and check the protocol

The monitor should publish transactions based on what actually occurred on the interface, not what the sequence intended to happen.

A monitor can capture an APB transfer when the access phase completes:

if (vif.psel && vif.penable && vif.pready) begin


apb_transaction tr;

tr = apb_transaction::type_id::create("tr");
tr.addr  = vif.paddr;
tr.write = vif.pwrite;
tr.wdata = vif.pwdata;
tr.rdata = vif.prdata;
tr.error = vif.pslverr;

analysis_port.write(tr);
end

Protocol assertions can independently check rules such as legal phase sequencing and signal stability during wait states. This gives the environment two complementary forms of evidence:

  • Transaction-level checking: did the observed operation produce the expected result?
  • Protocol-level checking: did the interface obey APB timing and control rules?

Step 6: Add a reference model and scoreboard

For a register-oriented APB slave, the scoreboard can maintain a simple reference model of expected register contents. A successful write updates the model; a successful read is compared against the modeled value.

function void check_transfer(apb_transaction tr);


if (tr.write && !tr.error) begin
model[tr.addr] = tr.wdata;
end
else if (!tr.write && !tr.error) begin
if (tr.rdata !== model[tr.addr]) begin
`uvm_error("APB_SB",
$sformatf("Read mismatch addr=%0h expected=%0h actual=%0h",
tr.addr, model[tr.addr], tr.rdata))
end
end
endfunction

The reference model should reflect the documented register behavior. Not every address necessarily behaves like ordinary storage: read-only registers, write-one-to-clear fields, volatile status bits, and reserved locations require explicit modeling.

Common mistake: assuming every APB address is a simple read/write register. The APB protocol describes the transfer; the peripheral specification determines what each address means.

Step 7: Verify the important scenarios

Start with directed scenarios that establish the protocol contract before introducing constrained-random traffic.

  1. Reset: verify the interface returns to its defined idle state and registers reach their reset values.
  2. Basic write: write a known value to a writable register and verify the update.
  3. Basic read: read a known register and compare the returned value with the reference model.
  4. Back-to-back transfers: perform consecutive legal accesses and verify that each transfer is observed independently.
  5. Wait states: hold the access phase for multiple cycles and verify that the transfer does not complete prematurely.
  6. Error response: access an address or condition that should produce PSLVERR and verify the expected response.
  7. Read-only/write-only behavior: verify access restrictions defined by the register specification.
  8. Boundary addresses: exercise the first, last, and reserved regions of the mapped address space.

Step 8: Add coverage that reflects requirements

Coverage should demonstrate that meaningful APB situations have been exercised rather than merely counting transactions.

  • read versus write transfers
  • different address regions
  • zero, one, and multiple wait-state transfers
  • successful versus error responses
  • reset followed by the first APB access
  • back-to-back reads and writes
  • important register categories such as read-only and writable registers

Cross coverage can be useful when combinations matter. For example, cross read/write with response type to ensure both successful and erroneous reads and writes have been exercised where the specification permits them.

Step 9: Debug failures systematically

When an APB test fails, start with the first incorrect phase or transaction. A later scoreboard mismatch may simply be a consequence of an earlier protocol error.

`uvm_info("APB_TEST",


$sformatf("addr=%0h write=%0b wdata=%0h seed=%0d",
tr.addr, tr.write, tr.wdata,
$get_initial_random_seed()),
UVM_MEDIUM)

`uvm_error("APB_SB",
$sformatf("addr=%0h expected=%0h actual=%0h error=%0b",
tr.addr, expected, tr.rdata, tr.error))

When a failure is intermittent, preserve the random seed and test configuration. Reproduce the failure first; then reduce the transaction sequence until the smallest scenario that still fails is identified.

Debug rule: distinguish a protocol failure, a DUT functional failure, and a testbench modeling failure. The same symptom can originate in any of the three.

Step 10: Make the project reusable

A completed APB project should provide reusable infrastructure rather than a collection of one-off tests.

  • Keep APB signal-level behavior inside the driver and monitor.
  • Keep transaction intent inside sequence items and sequences.
  • Keep register prediction and expected results inside the scoreboard or reference model.
  • Keep protocol rules in assertions and protocol checkers.
  • Keep scenario-specific behavior in tests and virtual sequences.
  • Use configuration objects for reusable parameters such as address width, data width, and timing options where appropriate.

This separation allows the same APB agent to be reused across different peripherals while only the register model, sequences, and expected behavior change.

Try it yourself

Build a small APB verification environment with the following acceptance criteria:

  1. Create an APB sequence item containing address, read/write direction, write data, and response information.
  2. Implement an active APB agent with sequencer, driver, and monitor.
  3. Write directed tests for reset, register write, register read, and an error response.
  4. Add a test in which the slave inserts multiple wait states.
  5. Implement a scoreboard that predicts at least one writable register.
  6. Add protocol assertions for the APB phase relationship and a relevant stability rule.
  7. Add functional coverage for read/write direction, response type, and wait-state behavior.
  8. Run both directed and constrained-random traffic.
  9. Record the test name, seed, first failure, scoreboard result, and coverage result.

Success criteria: the environment can demonstrate legal APB transfers, detect an incorrect read value, distinguish an expected error response from a protocol violation, and reproduce a seeded failure.

Key takeaways

  • APB verification is fundamentally about checking legal transfer phases, stable control information, and correct completion behavior.
  • The sequence item expresses transaction intent; the monitor reports what actually happened.
  • A scoreboard should model peripheral behavior independently rather than duplicate the DUT implementation.
  • Wait states, error responses, reset, and register access permissions deserve explicit tests.
  • Assertions and transaction-level scoreboards provide complementary verification evidence.
  • Functional coverage should measure meaningful protocol and functional scenarios, not just raw transaction count.
  • A reusable APB agent separates protocol mechanics from peripheral-specific verification requirements.