Module 4: Stimulus and Drivers | Lesson 31

Sequences

Learn how UVM sequences generate transaction-level stimulus, organize verification scenarios, and send sequence items to a driver through a sequencer.

Learning objectives

  • Explain what a UVM sequence is and why sequences are useful.
  • Understand the relationship between a sequence, sequence item, sequencer, and driver.
  • Create a basic uvm_sequence.
  • Generate and randomize sequence items inside a sequence.
  • Start a sequence on a sequencer.
  • Understand the basic sequence-driver handshake.
  • Separate scenario intent from protocol-specific signal driving.
  • Debug common sequence problems systematically.

Step 1: What is a sequence?

A sequence is a UVM object that generates and organizes transaction-level stimulus.

Instead of directly manipulating DUT signals, a sequence creates sequence items that describe what the test wants to happen. The driver later converts those items into actual interface activity.

For example, a sequence might generate:

WRITE address=0x10 data=0x55


WRITE address=0x20 data=0xAA
READ  address=0x10

The sequence does not need to know exactly which clock edge, handshake signal, or bus timing is required. That responsibility belongs to the driver.

Core idea: A sequence describes what stimulus should happen. A driver describes how that stimulus happens on the pins.

Step 2: Why use sequences?

Without sequences, a test could become tightly coupled to the implementation details of the driver and DUT interface.

Sequences provide a reusable layer for expressing verification scenarios.

For example, the same driver might support:

  • a reset sequence,
  • a single-write sequence,
  • a burst sequence,
  • a random traffic sequence,
  • a corner-case sequence,
  • an error-injection sequence.

The driver can remain unchanged while different sequences generate different scenarios.

Verification mindset: Put scenario intent in sequences. Put protocol mechanics in drivers.

Step 3: Understand the four important pieces

Sequences become much easier to understand when you separate the four UVM concepts involved in stimulus generation.

  1. Sequence item — represents one transaction.
  2. Sequence — creates and organizes one or more sequence items.
  3. Sequencer — manages the flow of sequence items toward the driver.
  4. Driver — receives sequence items and converts them into DUT signal activity.

The basic flow is:

Sequence
|
| creates
v


Sequence Item
|
| sent through
v
Sequencer
|
| consumed by
v
Driver
|
| converts transaction to signals
v
DUT

Keep this flow in mind throughout the rest of the module.

Step 4: A sequence item is one transaction

From Lesson 28, a sequence item is the object that represents one meaningful protocol operation.

class bus_transaction extends uvm_sequence_item;

rand bit        write;
rand bit [7:0]  addr;
rand bit [31:0] data;

`uvm_object_utils(bus_transaction)

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


endclass

One instance of bus_transaction might represent one write operation.

A sequence can create many such objects to construct a larger scenario.

Step 5: Create a basic sequence

A sequence normally extends uvm_sequence and specifies the type of sequence item it produces.

class write_sequence extends uvm_sequence #(bus_transaction);

`uvm_object_utils(write_sequence)

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


endclass

The parameter uvm_sequence #(bus_transaction) tells UVM that this sequence produces bus_transaction sequence items.

The sequence itself is a UVM object, not a UVM component. It therefore does not have a parent component like an environment, agent, or driver.

Step 6: Put stimulus in body()

The main work of a sequence is normally placed in its body() task.

class write_sequence extends uvm_sequence #(bus_transaction);

`uvm_object_utils(write_sequence)

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

task body();

    bus_transaction req;

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

    start_item(req);

    req.write = 1;
    req.addr  = 8'h10;
    req.data  = 32'h0000_0055;

    finish_item(req);

endtask


endclass

This sequence generates one transaction.

The important sequence operations are:

  • create() creates the sequence item.
  • start_item() begins the sequence-item handshake.
  • The sequence fills in the transaction fields.
  • finish_item() completes the item and makes it available to the driver.
Important: start_item() and finish_item() are not merely formatting conventions. They participate in the UVM sequence/sequencer mechanism that controls when an item is transferred to the driver.

Step 7: Generate multiple transactions

A sequence becomes especially useful when it generates a series of related transactions.

task body();

bus_transaction req;

repeat (4) begin

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

    start_item(req);

    req.write = 1;
    req.addr  = $urandom_range(0, 255);
    req.data  = $urandom();

    finish_item(req);

end


endtask

This sequence produces four write transactions.

Notice that a new sequence item is created for each transaction. This keeps each operation independent and makes transaction debugging much easier.

Step 8: Let constraints control random stimulus

Sequence items can contain constraints, allowing the sequence to generate legal constrained-random stimulus.

class bus_transaction extends uvm_sequence_item;

rand bit        write;
rand bit [7:0]  addr;
rand bit [31:0] data;

constraint addr_range {
    addr inside {[8'h10:8'h7F]};
}

`uvm_object_utils(bus_transaction)

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


endclass

The sequence can then randomize the item:

start_item(req);


if (!req.randomize()) begin
`uvm_fatal("RANDFAIL", "Transaction randomization failed")
end

finish_item(req);

The sequence controls when and how many transactions are generated. The transaction constraints control which values are legal.

Remember: Randomization chooses values. Constraints define the allowed values. The sequence defines the scenario.

Step 9: Start a sequence

Creating a sequence does not automatically execute it. A test must start the sequence on a sequencer.

task run_phase(uvm_phase phase);

write_sequence seq;

phase.raise_objection(this);

seq = write_sequence::type_id::create("seq");

seq.start(env.agent.sequencer);

phase.drop_objection(this);


endtask

The important line is:

seq.start(env.agent.sequencer);

This tells UVM to execute the sequence using that sequencer.

The sequence then generates items, and the sequencer coordinates their delivery to the appropriate driver.

Step 10: Understand the sequence-driver relationship

The sequence does not directly call the driver's get_next_item(). The sequencer and driver participate in the transaction handshake.

A simplified driver looks like this:

task run_phase(uvm_phase phase);

forever begin

    seq_item_port.get_next_item(req);

    drive_transaction(req);

    seq_item_port.item_done();

end


endtask

The overall flow is:

sequence
|
| start_item / finish_item
v


sequencer
|
| sequence item
v
driver
|
| signal-level activity
v
DUT

This separation is one of the most important architectural ideas in UVM.

Step 11: Sequence versus driver responsibilities

A common beginner mistake is putting protocol behavior into the sequence.

For example, avoid making a sequence responsible for:

vif.valid = 1;


vif.data  = req.data;
@(posedge vif.clk);
vif.valid = 0;

That is driver responsibility.

A better separation is:

Sequence Driver
Generate a write Drive write signals
Choose address/data Apply timing
Generate a read Perform bus handshake
Create scenarios Follow protocol rules
Control stimulus patterns Communicate with the DUT interface
Design rule: If you change the bus timing but do not want to rewrite your verification scenarios, that timing logic belongs in the driver.

Step 12: A complete small example

Here is a compact example showing a transaction, sequence, and the sequence being started by a test.

class bus_transaction extends uvm_sequence_item;

rand bit        write;
rand bit [7:0]  addr;
rand bit [31:0] data;

`uvm_object_utils(bus_transaction)

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


endclass

class basic_write_sequence extends uvm_sequence #(bus_transaction);


`uvm_object_utils(basic_write_sequence)

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

task body();

    bus_transaction req;

    repeat (4) begin

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

        start_item(req);

        req.write = 1;
        req.addr  = $urandom_range(0, 255);
        req.data  = $urandom();

        finish_item(req);

    end

endtask


endclass

The test can start the sequence:

task run_phase(uvm_phase phase);

basic_write_sequence seq;

phase.raise_objection(this);

seq = basic_write_sequence::type_id::create("seq");
seq.start(env.agent.sequencer);

phase.drop_objection(this);


endtask

The resulting architecture is:

Test


|
+-- Sequence
|
+-- Transaction 1
+-- Transaction 2
+-- Transaction 3
+-- Transaction 4
|
v
Sequencer
|
v
Driver
|
v
DUT

Step 13: Sequences are reusable scenarios

One of the major benefits of sequences is reuse.

Instead of writing all stimulus inside one test, create small reusable sequences that represent meaningful scenarios.

For a FIFO, you might eventually create:

  • fifo_reset_sequence
  • fifo_write_sequence
  • fifo_read_sequence
  • fifo_fill_sequence
  • fifo_empty_sequence
  • fifo_random_sequence

Tests can then combine these building blocks into larger scenarios.

This is much easier to maintain than placing hundreds of individual transaction assignments directly inside a test.

Step 14: Common sequence mistakes

Mistake 1: Creating a sequence but never starting it

seq = basic_write_sequence::type_id::create("seq");


// Nothing happens here.

A sequence must be started on a sequencer.

seq.start(env.agent.sequencer);

Mistake 2: Forgetting start_item() and finish_item()

Sequence items should be transferred using the UVM sequence mechanism rather than bypassing the sequencer.

Mistake 3: Putting pin-level protocol code in the sequence

This couples the scenario to one interface implementation. Keep protocol timing and signal manipulation inside the driver.

Mistake 4: Reusing one item without understanding object lifetime

For beginner code, creating a fresh item for each transaction is usually the clearest approach and avoids confusing transaction traces and accidental data reuse.

Mistake 5: Ignoring randomization failure

if (!req.randomize()) begin
`uvm_error("RANDFAIL", "Could not randomize transaction")


end

A failed randomization should be investigated rather than silently ignored.

Step 15: Debug a sequence that produces no traffic

Suppose the simulation starts successfully, but the DUT receives no transactions.

Do not immediately modify the driver. Trace the stimulus path.

  1. Was the sequence created?
  2. Was the sequence started?
  3. Was it started on the correct sequencer?
  4. Did body() execute?
  5. Was a sequence item created?
  6. Did start_item() and finish_item() execute?
  7. Is the sequencer connected to the correct driver?
  8. Is the driver waiting for items?
  9. Did the driver receive the item?
  10. Did the driver actually drive the DUT?

Temporary messages can make this path visible:

`uvm_info("SEQ", "Sequence body started", UVM_MEDIUM)


`uvm_info("SEQ", "Sending transaction", UVM_MEDIUM)

`uvm_info("DRV", "Driver received transaction", UVM_MEDIUM)

`uvm_info("DRV", "Driver completed transaction", UVM_MEDIUM)
Debugging rule: Find the first stage where the expected behavior disappears. Do not start by changing components that have not yet been proven to be broken.

Step 16: Sequence mental model

Think of the stimulus architecture as a chain of responsibilities:

Scenario


|
v
Sequence
|
| creates
v
Sequence Item
|
| transferred through
v
Sequencer
|
| delivered to
v
Driver
|
| converts to signals
v
DUT
|
v
Monitor
|
v
Scoreboard

Each layer has a different job.

Core UVM rule: The sequence should think in terms of transactions and scenarios. The driver should think in terms of clocks, handshakes, and pins.

Try it yourself

Create a write_sequence for the bus_transaction from this lesson.

  1. Extend uvm_sequence #(bus_transaction).
  2. Register the sequence with uvm_object_utils.
  3. Implement body().
  4. Generate four write transactions.
  5. Use start_item() and finish_item().
  6. Randomize the address and data.
  7. Check the return value of randomize().
  8. Start the sequence on the agent's sequencer.
  9. Confirm that the driver receives all four transactions.
Challenge: Add a constraint so that all generated addresses fall between 8'h20 and 8'h7F. Then print each transaction and verify that every generated address satisfies the constraint.

Key takeaways

  • A sequence generates and organizes transaction-level stimulus.
  • A sequence item represents one transaction.
  • A sequencer manages the flow of sequence items toward a driver.
  • A driver converts sequence items into DUT signal activity.
  • body() contains the main behavior of a sequence.
  • start_item() and finish_item() participate in the sequence-item handshake.
  • Use seq.start(sequencer) to execute a sequence.
  • Keep scenario intent in sequences and protocol mechanics in drivers.
  • Sequences become powerful when they are reusable and composable.
  • When stimulus disappears, debug the sequence → sequencer → driver path in order.