Module 8: Protocol Projects | Intermediate UVM

UART Verification Project

Build a focused UVM environment that verifies UART framing, configuration, data transfer, and error handling.

Learning objectives

  • Identify the protocol rules that must be verified in a UART interface.
  • Build and adapt UVM sequences, agents, monitors, and a scoreboard for UART traffic.
  • Verify transmitted and received bytes against protocol expectations.
  • Use assertions, functional coverage, and reports to produce measurable verification evidence.
  • Debug a UART failure by connecting a transaction-level mismatch to the corresponding waveform activity.

Step 1: Understand the protocol

UART is simple at the pin level, but a useful verification environment must check more than whether a byte eventually appears at the receiver. A UART frame normally contains a start bit, a configurable number of data bits, an optional parity bit, and one or more stop bits.

Before writing the testbench, turn the UART specification into explicit verification rules:

  • Frame format: verify start, data, parity, and stop-bit ordering.
  • Data configuration: exercise supported data widths, commonly 7 or 8 bits.
  • Parity: verify none, even, and odd parity when supported.
  • Stop bits: check the configured number of stop bits.
  • Baud timing: verify that bit timing stays within the design's allowed tolerance.
  • TX/RX behavior: confirm that transmitted data is reconstructed correctly by the receiver.
  • Error handling: deliberately create parity, framing, or timing errors and verify the documented response.

The important UVM boundary is the transaction. The sequence should describe what byte and configuration to transmit; the driver converts that transaction into UART pin activity; the monitor reconstructs the observed frame; and the scoreboard compares the observed result with the expected behavior.

Design principle: Keep serial timing details inside the driver and monitor. Keep protocol intent and expected data at the transaction level so the environment remains reusable.

Step 2: Define the UART transaction

A useful transaction should contain enough information to describe a UART transfer without exposing low-level pin toggling to the test.

class uart_item extends uvm_sequence_item;


rand bit [7:0] data;
rand bit       parity_enable;
rand bit       parity_odd;

`uvm_object_utils(uart_item)

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

The exact fields should follow the DUT specification. If the UART configuration is fixed, configuration can instead be stored in the environment or a configuration object. The key idea is to separate transfer intent from wire-level representation.

For example, a sequence should be able to say data = 8'hA5 without manually generating a start bit, eight data-bit periods, parity, and stop bit. That responsibility belongs to the driver.

Step 3: Build the driver and monitor

The UART driver translates a transaction into serial activity. The monitor performs the inverse operation: it observes the serial line, detects the start bit, samples the frame, reconstructs the byte, and publishes an observed transaction.

class uart_driver extends uvm_driver #(uart_item);


virtual uart_if vif;

`uvm_component_utils(uart_driver)

function new(string name = "uart_driver", uvm_component parent = null);
super.new(name, parent);
endfunction

task run_phase(uvm_phase phase);
uart_item req;


forever begin
  seq_item_port.get_next_item(req);

  // Convert transaction fields into UART frame activity.
  drive_start_bit();
  drive_data_bits(req.data);

  if (req.parity_enable)
    drive_parity(req.data, req.parity_odd);

  drive_stop_bit();

  seq_item_port.item_done();
end


endtask
endclass

This example intentionally leaves the timing helpers abstract. In a real environment, those helpers would implement the configured baud period and frame format.

The monitor should publish what it actually observed, not what the driver intended to send. This distinction is critical: a scoreboard cannot detect a DUT or timing problem if both sides use the same unverified source of truth.

Common mistake: making the monitor reuse the driver's expected byte instead of decoding the UART line. A monitor must be an independent observer of DUT behavior.

Step 4: Add the scoreboard

The scoreboard turns observed UART traffic into a functional check. For a basic loopback or TX verification scenario, it can compare the expected byte with the byte reconstructed by the monitor.

function void write_actual(uart_item actual);


uart_item expected;

if (expected_fifo.size() == 0) begin
`uvm_error("UART_SB",
"Received UART transaction with no expected transaction")
return;
end

expected = expected_fifo.pop_front();

if (actual.data !== expected.data) begin
`uvm_error("UART_SB",
      $sformatf("Data mismatch: expected=0x%02h actual=0x%02h",
                expected.data, actual.data))
  end
  else begin
    `uvm_info("UART_SB",
$sformatf("UART byte matched: 0x%02h", actual.data),
UVM_MEDIUM)
end
endfunction

For a production-quality environment, extend the comparison beyond data. Check the relevant frame configuration, parity status, framing-error indication, and other DUT-visible status fields.

Step 5: Verify normal and abnormal frames

Start with legal frames before introducing protocol errors. A useful progression is:

  1. Transmit a single known byte such as 8'h55.
  2. Transmit boundary values such as 8'h00 and 8'hFF.
  3. Transmit several bytes back-to-back.
  4. Exercise different supported parity configurations.
  5. Exercise the supported stop-bit configurations.
  6. Vary baud-rate settings within the supported range.
  7. Inject an incorrect parity bit and verify the error response.
  8. Inject an invalid stop bit or altered frame timing and verify framing-error behavior.

Do not treat error injection as simply “making the test fail.” The expected result of an error scenario should be explicitly defined. For example, the DUT may raise a parity-error flag, discard the received byte, preserve the byte with an error indication, or generate an interrupt.

Step 6: Build the test sequence

Use a deterministic smoke test first. Once the basic path works, add constrained-random traffic and configuration combinations.

class uart_smoke_seq extends uvm_sequence #(uart_item);


`uvm_object_utils(uart_smoke_seq)

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

task body();
uart_item req;


req = uart_item::type_id::create("req");

start_item(req);
req.data = 8'h55;
req.parity_enable = 0;
req.parity_odd = 0;
finish_item(req);

start_item(req);
req.data = 8'hA5;
req.parity_enable = 0;
req.parity_odd = 0;
finish_item(req);


endtask
endclass

Once the deterministic sequence passes, randomize the data and configuration fields within the legal protocol space. Keep illegal configurations in separate negative tests so a failure is immediately understandable.

Step 7: Add protocol assertions and coverage

A scoreboard answers whether a transaction produced the expected result. Assertions can detect protocol violations closer to the signal level.

// Conceptual example: stop bit should be high


property stop_bit_is_high;
@(posedge vif.clk)
stop_bit_sample |-> vif.rx;
endproperty

assert property (stop_bit_is_high)
else `uvm_error("UART_ASSERT", "UART stop bit was not high");

Coverage should measure whether the important combinations were exercised rather than merely counting tests.

covergroup uart_cg;


data_cp: coverpoint data {
bins zero = {8'h00};
bins all_ones = {8'hFF};
bins alternating = {8'h55, 8'hAA};
}

parity_cp: coverpoint parity_mode;
stop_cp:   coverpoint stop_bits;

data_x_parity:
cross data_cp, parity_cp;
endgroup

Use coverage results to identify what still needs testing. High code coverage does not automatically prove that UART protocol behavior has been adequately verified.

Step 8: Assemble the project environment

The final environment should have clear ownership:

  • Sequence: generates UART transfer scenarios.
  • Driver: converts transactions into UART signaling.
  • Monitor: decodes actual UART activity.
  • Scoreboard: compares expected and observed behavior.
  • Assertions: check signal-level protocol rules.
  • Coverage: measures meaningful configuration and traffic combinations.
  • Test: selects the scenario and controls the overall verification flow.
class uart_env extends uvm_env;


uart_agent      agent;
uart_scoreboard scoreboard;

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


agent = uart_agent::type_id::create("agent", this);
scoreboard = uart_scoreboard::type_id::create("scoreboard", this);


endfunction

function void connect_phase(uvm_phase phase);
agent.monitor.ap.connect(scoreboard.actual_export);
endfunction
endclass

The environment becomes valuable when the same UART agent can be reused across multiple tests without rewriting protocol behavior.

Step 9: Debug a failing UART test

When a UART test fails, start with the transaction-level evidence and move toward the waveform only when necessary.

  1. Record the test name and random seed.
  2. Identify the first scoreboard or assertion failure.
  3. Compare expected and observed transaction fields.
  4. Check whether the monitor decoded the frame correctly.
  5. Inspect start-bit detection and bit sampling timing.
  6. Verify the configured baud period and frame format.
  7. Only then inspect deeper DUT implementation details.

If the same seed reproduces the failure, reduce the sequence to the smallest transaction that still demonstrates the problem. A small, repeatable UART failure is far more useful than a large regression log containing hundreds of unrelated transactions.

Try it yourself

Build a UART smoke test that transmits 8'h55, 8'h00, and 8'hFF. Verify each byte through the monitor and scoreboard. Then add one parity configuration and one deliberately corrupted frame.

For each scenario, record:

  • Expected byte and frame configuration
  • Observed byte and status
  • Pass/fail result
  • Relevant assertion result
  • Coverage point reached
  • Seed and test name if randomized

Key takeaways

  • Model UART transfers as transactions and keep serial timing inside the driver and monitor.
  • The monitor should independently decode the DUT's actual serial activity.
  • Verify both legal traffic and deliberately injected protocol errors.
  • Use scoreboards for end-to-end data checking and assertions for signal-level protocol rules.
  • Use functional coverage to demonstrate that important UART configurations and traffic patterns were exercised.
  • A reusable UART agent should support multiple tests without duplicating protocol implementation.
  • Preserve the seed and transaction context so failures can be reproduced and minimized.