Not all data has an address. Video pixels, network packets, audio samples and DSP data simply flow from one block to the next. AXI4-Stream is the AMBA protocol for that: a single channel from a transmitter to a receiver, with the same VALID/READY handshake as AXI, data, byte qualifiers, and a TLAST signal to mark the end of a packet. This article explains the AXI4-Stream signals and builds a block that consumes one stream and produces another.
8 min read | Intermediate
What You'll Learn
- Name the AXI4-Stream signals and what each one is for
- Use TLAST to mark packet boundaries
- Use TKEEP for packets that are not a whole number of words
- Build a stream block that applies and respects backpressure
One Channel, No Addresses
| Signal | Driven by | Meaning |
|---|---|---|
| TVALID | Transmitter | A transfer is on the channel |
| TREADY | Receiver | The receiver can accept a transfer |
| TDATA | Transmitter | The data, a whole number of bytes wide |
| TKEEP | Transmitter | One bit per byte: the byte is part of the stream. Bytes with TKEEP low are null bytes that can be removed |
| TSTRB | Transmitter | One bit per byte: the byte is data rather than a position byte |
| TLAST | Transmitter | The last transfer of a packet |
| TID, TDEST | Transmitter | Which stream the data belongs to, and where it should go |
| TUSER | Transmitter | User-defined side information, such as start of frame |
Only TVALID is strictly required; most interfaces use TVALID, TREADY, TDATA and TLAST, and add TKEEP when packets can end in the middle of a word. A transfer happens at every rising edge where TVALID and TREADY are both high, with the same rules as AXI: the transmitter must not wait for TREADY before raising TVALID, and once TVALID is high the transfer must stay unchanged until it is accepted.
Packets and TLAST
A stream is a sequence of transfers. TLAST groups them into packets: the transfer with TLAST high ends one packet, and the next transfer starts a new one. A 14-byte packet on a 32-bit stream takes four transfers: three full words and a fourth with only two bytes kept, marked with TKEEP = 0011.
Quick Check
Q: A 32-bit stream carries a 9-byte packet. How many transfers does it take, and what are TKEEP and TLAST on the last one?
Show Answer
Three transfers: two full words and a last transfer with one byte, TKEEP = 0001 and TLAST = 1.
A Packet Byte Counter
This block reads packets from its input stream and, at the end of each one, sends the packet's length in bytes on its output stream. It counts only the bytes whose TKEEP bit is set:
module axis_pkt_count (
input aclk,
input aresetn,
input [31:0] s_tdata,
input [3:0] s_tkeep,
input s_tlast,
input s_tvalid,
output s_tready,
output reg [15:0] m_tdata,
output reg m_tvalid,
input m_tready
);
reg [15:0] bytes;
wire [2:0] kept = s_tkeep[0] + s_tkeep[1] + s_tkeep[2] + s_tkeep[3];
// Stall the input while a count is waiting to be taken on the output
assign s_tready = !m_tvalid || m_tready;
always @(posedge aclk) begin
if (!aresetn) begin
bytes <= 16'd0;
m_tvalid <= 1'b0;
end
else begin
if (m_tvalid && m_tready)
m_tvalid <= 1'b0;
if (s_tvalid && s_tready) begin
if (s_tlast) begin
m_tdata <= bytes + kept;
m_tvalid <= 1'b1;
bytes <= 16'd0;
end
else begin
bytes <= bytes + kept;
end
end
end
end
endmodule
The s_ ports are the receiver side and the m_ ports the transmitter side, a naming convention used by most stream IP. The interesting line is s_tready: the block accepts input only when it can also deliver its output. If a count is waiting and the next block is not ready, the counter stops taking input. That is backpressure: a slow block at the end of a chain slows down everything before it, and no data is lost.
The Simulation
The testbench sends three packets: 14 bytes in four transfers, a single byte, and two full words with a gap between them. The receiver of the counts is busy for four cycles in the middle:
35 in data=0x03020100 keep=1111 45 in data=0x07060504 keep=1111 55 in data=0x0b0a0908 keep=1111 65 in data=0x00000d0c keep=0011 last 75 in data=0x000000ee keep=0001 last 75 out packet length = 14 bytes 125 in data=0x13121110 keep=1111 125 out packet length = 1 bytes 155 in data=0x17161514 keep=1111 last 165 out packet length = 8 bytes
The count of packet 2 is ready at 85 ns, but the receiver is busy until 120 ns. During that time s_tready is low and the first word of packet 3 waits on the input with TVALID high. As soon as the count is taken, the waiting word is accepted in the same cycle.
Quick Check
Q: In this block, s_tready is a combinational function of m_tready. What happens to timing if ten such blocks are chained?
Show Answer
The TREADY of the last block ripples back through all ten blocks in one clock cycle, which makes a long combinational path. Real designs break the chain with a register slice or skid buffer, the subject of Designing a Stream FIFO and Skid Buffer.
Where AXI4-Stream Is Used
- Video: one pixel or a few pixels per transfer,
TUSERmarking the start of a frame andTLASTthe end of each line. - Networking: one packet per
TLAST,TKEEPfor the last partial word. - DMA: a DMA engine reads memory over AXI4 and pushes the data out as a stream, or the reverse.
- DSP chains: filters and FFT blocks that each take a stream and produce one.
Running It in ChipVerify Lab
The example contains the byte counter and the packet testbench. Change the TKEEP values and the packet lengths, and check the counts.
Common Mistakes
Mistake #1: Dropping TVALID while waiting
A transmitter must keep a transfer on the channel until TREADY accepts it. A transmitter that gives up and moves on loses data.
Mistake #2: Forgetting TLAST on single-transfer packets
A one-transfer packet has TLAST high on its only transfer. Without it, the receiver merges it with the next packet.
Mistake #3: Counting null bytes
Bytes with TKEEP low are not part of the stream. A receiver that counts every byte of the last word gets the packet length wrong.
Practice Exercise
Challenge: Null Bytes in the Middle
Replace packet 2 with three transfers: a full word, a word with TKEEP = 0101, and a full last word. Predict the length the counter reports, then run it.
Hint
TKEEP may be low in the middle of a packet too. Count the set bits.
Solution
beat(32'h33221100, 4'b1111, 0);
beat(32'h00550044, 4'b0101, 0);
beat(32'h99887766, 4'b1111, 1);
75 in data=0x33221100 keep=1111 85 in data=0x00550044 keep=0101 95 in data=0x99887766 keep=1111 last 125 out packet length = 10 bytes
4 + 2 + 4 = 10 bytes. The two bytes with TKEEP low in the middle transfer are null bytes and are not counted.
Open the ready-made example in the lab and run the simulation.
Summary
- AXI4-Stream is a single channel with no addresses: TVALID, TREADY and TDATA, plus optional qualifiers.
- TLAST ends a packet; TKEEP marks which bytes belong to the stream.
- TID, TDEST and TUSER carry stream identity, routing and side information.
- The VALID/READY rules are the same as in AXI: TVALID never waits for TREADY and holds until accepted.
- Backpressure through TREADY lets a slow block throttle the whole chain without losing data.