The manager port sends transactions; something has to answer them. The first block on the far side of the bus is the system SRAM, 16 KB of memory behind an AXI4-Lite subordinate port. Writing it shows the bus from the other side: when to raise READY, when a write may be accepted, how long a response must stay up, and how a full 32-bit bus address becomes the index of a word. This article explains those rules and the timing they lead to, and in exercise S05 you write the SRAM.

9 min read | Intermediate

What You'll Learn

  • Apply the AXI4-Lite rules from the subordinate's side: READY, accepting a write, holding a response
  • Accept a write only when both its address and its data are present
  • Turn a bus address into a word index with a parameterized memory size
  • Explain the SRAM's share of the four cycles an access takes

Before You Start

This section needs Verilog: see the Verilog Tutorial. An AXI4-Lite Manager Port explains the five channels and the valid/ready rules from the manager's side; this article turns them around. Memories in a System explains what on-chip SRAM is. No earlier exercise is needed, but S03 and S04 make this one easier to picture.

A Subordinate's Job

A subordinate (also called a slave in older documents) does what the manager asks and answers. For the SRAM that means three things: store a word when it is written, return a word when it is read, and send a response for each. On the AXI4-Lite channels its roles are the mirror image of the manager's: it raises AWREADY, WREADY and ARREADY when it accepts, and it drives BVALID with BRESP and RVALID with RDATA and RRESP when it answers. These are its ports:

module cvsoc_axil_sram #(
    parameter int WORDS = 4096                     // 16 KB
) (
    input  logic        clk,
    input  logic        rst_n,
    input  logic [31:0] s_awaddr,
    input  logic        s_awvalid,
    output logic        s_awready,
    input  logic [31:0] s_wdata,
    input  logic [3:0]  s_wstrb,
    input  logic        s_wvalid,
    output logic        s_wready,
    output logic [1:0]  s_bresp,
    output logic        s_bvalid,
    input  logic        s_bready,
    input  logic [31:0] s_araddr,
    input  logic        s_arvalid,
    output logic        s_arready,
    output logic [31:0] s_rdata,
    output logic [1:0]  s_rresp,
    output logic        s_rvalid,
    input  logic        s_rready
);

The s_ prefix marks the ports of a subordinate, as m_ marked the manager's. The SRAM never fails, so its responses are always OKAY (00).

Accepting a Write

A write arrives on two channels, and a manager may offer them in any order: the address and the data together, the address first, or the data first, each VALID staying up until its own handshake. The SRAM cannot store anything until it has both: an address without data says nothing to write, data without an address says nowhere to put it.

The simplest correct rule is to accept a write only in a cycle where both are present: raise AWREADY and WREADY together, when AWVALID and WVALID are both 1. Whichever arrives first waits, with its VALID up, until the other one comes:

Three cases of a write: address and data together accepted in cycle 2; address first, data in cycle 3, accepted in cycle 3; data first, address in cycle 2, accepted in cycle 2. In each case BVALID follows one cycle after acceptance.

At the clock edge of acceptance, the SRAM writes the byte lanes whose s_wstrb bit is 1, exactly as the TCM did with dwstrb. In the next cycle it raises BVALID with OKAY, and keeps it up until the manager's BREADY takes it. While a write response is waiting, it does not accept another write.

Waiting for both is a choice, not the only option: a subordinate may also accept the address and the data in different cycles and keep whichever came first in a register. That costs more logic and buys nothing for a single manager doing one transaction at a time, so the reference design waits.

Answering a Read

A read is simpler: accept the address when ARVALID is 1 and no read response is still waiting; in the next cycle raise RVALID with the word in RDATA and OKAY in RRESP; keep RVALID and RDATA exactly as they are until RREADY is 1.

Both responses come one cycle after acceptance, and that is not a coincidence. A real SRAM macro is synchronous: it takes the address at a clock edge and delivers the data after it. Registering the response models that, and it keeps the outputs clean: BVALID, RVALID and RDATA come straight from flip-flops, which makes the timing of whatever logic reads them easy. The tests check this cycle: each response must be there in the cycle after its request was accepted.

Quick Check

Q: A manager offers the write address in cycles 1 to 3 and raises WVALID in cycle 3. In which cycle does the SRAM accept the write, when is BVALID first 1, and when does the data reach the memory array?

Show Answer

It accepts in cycle 3, the first cycle in which both VALIDs are 1, so AWREADY and WREADY are 1 in cycle 3. The array is written at the clock edge at the end of cycle 3, and BVALID is 1 from cycle 4 until the manager accepts it.

From Bus Address to Word Index

The interconnect passes the manager's address unchanged, so the SRAM sees addresses such as 0x2000_0010. It only needs the bits that select a word inside its own 16 KB. Bits [1:0] select a byte within a word and are covered by the byte enables. The next bits select the word: with 4,096 words, 12 bits, [13:2]. Everything above, including the 0x2000 that told the interconnect where to route the access, is ignored here.

The number of words is a parameter, WORDS, so write the index in terms of it: with AW = $clog2(WORDS) address bits for the word number, the index is bits [AW+1:2]. With the default 4,096, AW is 12 and the index is [13:2]. A common mistake is to use bits [AW-1:0], the right number of bits but the byte address: then neighbouring bytes land in different words and every fourth word is never used.

Four Cycles per Access

In An AXI4-Lite Manager Port an SRAM access took 4 cycles. The SRAM's share is the acceptance cycle and the response cycle: it accepts in the same cycle the manager first offers the request, and answers in the next. The other two cycles belong to the manager port, which needs a cycle to see the request and a cycle to hand the result to the core. The interconnect adds none, because it routes in the same cycle. The program copy_sram, which copies 1,024 words into the SRAM and reads them back, makes 2,048 SRAM accesses and waits 3 cycles more for each than it would for the TCM; Your First System: Core, Memory and Bus shows the total.

Where Is This Used?

On-chip SRAM behind a bus port is in almost every SoC: shared buffers between the CPU and a DMA engine, a frame of sensor data, the stack of a second core. Industrial SRAM controllers add ECC, several outstanding reads, bursts and the occasional extra cycle for a slower macro, but their AXI side follows the same rules as this one: accept when you can, answer in order, hold every response until it is taken.

How It Is Tested

The S05 tests act as a manager:

  • writes with address and data together, address first and data first, each read back;
  • byte and halfword writes that change only their lanes;
  • the first and last word of the 16 KB;
  • for every request, a check that the response is there in the next cycle, and that it stays, unchanged, while the manager waits 0 to 3 cycles before accepting it;
  • after acceptance, a check that BVALID or RVALID has dropped;
  • 400 random reads and writes (hidden test).

Common Mistakes

Mistake #1: Accepting the address without the data

Raising AWREADY when only AWVALID is 1 takes the address; if WVALID is still 0, the SRAM writes whatever is on WDATA, and the real data arrives later with nowhere to go.

Mistake #2: Dropping a response before READY

Clearing RVALID one cycle after raising it, instead of when RREADY is 1, works with a manager that always accepts at once and loses the data with one that does not. The tests' manager waits.

Mistake #3: Using the byte address as the word index

Indexing with address bits [AW-1:0] puts the four bytes of a word into four different array entries. Word writes and reads at aligned addresses still seem to work until two addresses share an entry; the random test finds it.

Your Turn in the Lab

Exercise S05: write cvsoc_axil_sram with the parameter and ports above. Save it in your lab project; S08 connects it to your interconnect.

Open exercise S05 in ChipVerify Lab

Summary

  • A subordinate raises READY to accept and drives the response channels; the SRAM always answers OKAY.
  • The SRAM accepts a write in the cycle where both the address and the data are present, writes the enabled byte lanes, and raises BVALID in the next cycle until BREADY.
  • A read is accepted when no read response is waiting; RVALID with the data follows in the next cycle and stays until RREADY.
  • The word index is address bits [AW+1:2] with AW = $clog2(WORDS); the upper bits are the interconnect's business.
  • The SRAM's share of a 4-cycle access is acceptance and response; the manager port supplies the other two.
Did you find what you were looking for?

Quiz

No quiz questions available for this article.