Memory Self-Test and the Handoff of the Port

A scan chain cannot reach the cells of a memory. So a small controller on the chip writes every word, reads it back and reports two bits. While it works, it owns the memory.

You Will Be Able To

  • Explain why a memory gets a test controller of its own, and what the controller reports.
  • Show why a pattern must be followed by its opposite.
  • Describe the handoff of the memory port, and what the test does to the content.
Lesson
S8.11
Time
25 min
Runs on
Your browser
Check
5 questions

A scan test passed, and the chip still lost data in the field. The fault sat in one cell of the memory, a cell that always read 1. No scan flip-flop had ever stored a bit in it.

Before You Start

You need Test Hooks at Chip Level: the tester, and why a chip carries routes for test alone.

You need Memory and Caches in One Picture: a memory is words at addresses, reached by a read or a write.

Five questions this page answers
Question
1Why does a memory need a test of its own?
2What does the test controller report, and through how many bits?
3Why is one pattern not enough?
4Who may use the memory while the test runs?
5A memory, two patterns and one faulty cell: which read goes wrong?

The Idea: The Chip Tests Its Own Memory

A memory holds most of the transistors of many chips. Its cells are not flip-flops, and no scan chain runs through them. The only way to a cell is the port: give an address, then write or read.

A tester could do that through the pins, word by word. It would take far too long. So the chip does the work itself. A small state machine sits next to the memory. It writes a known pattern to every word, reads every word back, and compares. This is a built-in self-test, and for a memory it is called MBIST.

The tester only says start, and waits. The answer is two bits. The done bit says that the test has finished. The fail bit says that at least one read came back wrong.

Two things follow. One pattern cannot find every bad cell, so the controller writes a second one. And the memory has one port, so the test and the function cannot both use it. The port is handed over, and handed back.

New Words

New words on this page
WordMeaning
Built-in self-testA test that the chip runs on itself, with logic added for that purpose.
MBISTMemory built-in self-test: a controller that writes a memory, reads it back and compares.
Test controllerThe state machine that runs a self-test. Here it makes the addresses, the data and the comparison.
CheckerboardA pattern of 0s and 1s in turn, such as 0101 in one word and 1010 in the next.
Stuck cellA faulty memory cell that reads the same value whatever is written to it.
Done bit and fail bitThe two result bits of a self-test: it has finished, and it found a wrong read. This page calls them done and fail.
Handoff of the portThe moment at which the right to use the memory port passes to the test, or back to the function side.

One Picture: Two Users, One Port

A Memory with Two Users and One PortStep through the picture. The memory at work comes first, then the test controller, then the handoff between the two.
  • Processor
  • Debug
  • Control / FSM
  • Memory
A Memory With Two Users and One PortStep through the picture. The memory at work comes first, then the test controller, then the handoff between the two. component Function side the logic that usesthe memory in normalwork component Test controller a small state machine:it writes, reads backand compares component Port mux one owner at a time:function or test component Memory words of cells,reached only throughits port component Result two bits: done and fail address, data, writethe portaddress, data, writeread datadone, fail
  1. component Function sidethe logic that uses the memory in normal work
    • address, data, write → Port mux
  2. component Port muxone owner at a time: function or test
    • the port → Memory
  3. component Memorywords of cells, reached only through its port
    • read data → Test controller
  4. component Test controllera small state machine: it writes, reads back and compares
    • address, data, write → Port mux
    • done, fail → Result
  5. component Resulttwo bits: done and fail
  1. At work

    The function side reads and writes the memory through its one port. No scan chain runs through the cells.

  2. A controller on the chip

    A small state machine next to the memory can write every word and read it back. It needs no tester for that, only a start.

  3. One owner

    A mux at the port chooses the owner. While the test owns the port, the function side is shut out.

  4. Two bits

    The whole answer is two bits. Done says that the test has finished. Fail says that some read came back wrong.

Read the diagram as text
  • Function side: the logic that uses the memory in normal work
  • Test controller: a small state machine: it writes, reads back and compares
  • Port mux: one owner at a time: function or test
  • Memory: words of cells, reached only through its port
  • Result: two bits: done and fail
  • Function side → Port mux: address, data, write
  • Port mux → Memory: the port
  • Test controller → Port mux: address, data, write
  • Memory → Test controller: read data
  • Test controller → Result: done, fail

Memory self-test. The pins of the chip carry a start and two result bits, not the data of the memory.

The Smallest Example, Worked by Hand

Take a memory of two words, four bits each. One cell is faulty: bit 0 of word 0 always reads 1. No simulator yet. The controller writes 0101 to even words and 1010 to odd words. Then it writes the opposite.

Two passes over a memory with one stuck cell
PassWordWrittenRead backVerdict
1001010101Good. The pattern wants a 1 in bit 0, and the stuck cell gives a 1.
1110101010Good.
2010101011Bad. The pattern wants a 0 in bit 0, and the cell still gives a 1.
2101010101Good.

Read the first row. The fault is there, and the read is right. A stuck cell agrees with any pattern that happens to want its value.

Read the third row. The opposite pattern asks the same cell for a 0. Now the read is wrong, and fail becomes 1. After both passes every cell has been asked for a 0 and for a 1.

The Rules

  1. Rule 1: A memory is tested through its port, by a controller on the chip.

    The tester gives a start and reads two bits.

  2. Rule 2: Every cell must be asked for a 0 and for a 1.

    So a pattern is followed by its opposite. One pattern leaves half the stuck cells unseen.

  3. Rule 3: Fail means something only when done is 1.

    Fail at 0 with done at 0 is a test that has not finished, or never started.

  4. Rule 4: The port has one owner at a time.

    A mux at the address, the data and the write input gives it to the function side or to the test.

  5. Rule 5: The test destroys the content.

    After it, every word holds the last pattern. Whatever the function had stored is gone.

  6. Rule 6: The handoff is planned in the function, not added after it.

    The function must finish its last write and stop asking before the test takes the port.

Sources for These Rules

Memory self-test with a mux on the address, data and control inputs, a state machine, a checkerboard and then its opposite: Weste and Harris, CMOS VLSI Design, fourth edition, section 15.6.3.2.

Built-in self-test in general: the same book, section 15.6.3.

Rules 3, 5 and 6 are common practice. Our reference library holds no standard for memory self-test, and no source that states them.

The two words, the four bits and the edges of the controller are choices of our lab.

Now Run It

The lab at the end of this page has a memory of two words, the port mux and a test controller. Test code plays both the function side and the tester. This memory is healthy.

Printed by the lab on Icarus. A word is written from bit 3 down to bit 0.
e2 function writes word 0: 1001
the test controller owns the port
e4 start
e5 test writes word 0: 0101
e6 function write refused: the test owns the port
e6 test writes word 1: 1010
e7 test reads word 0: wants 0101, gets 0101
e8 test reads word 1: wants 1010, gets 1010
e9 test writes word 0: 1010
e10 test writes word 1: 0101
e11 test reads word 0: wants 1010, gets 1010
e12 test reads word 1: wants 0101, gets 0101
e12 done=1 fail=0 bad reads=0
the function side owns the port
e14 function reads word 0: 1010

Rule 4 at work, in the row at e6 that says "refused". The function side tried to write while the test owned the port. Its write did not reach the memory.

Rule 2, in the rows from e5 to e12. Pass 1 writes 0101 and 1010 and reads them back. Pass 2 writes the opposite and reads again. Every cell held a 0 once and a 1 once.

Rule 3, in the row "done=1 fail=0". Both bits are needed to say that this memory passed.

Rule 5, in the last row. Before the test, word 0 held 1001. After the handoff back, the function side reads 1010: the pattern of pass 2.

Now the stuck cell of the hand example. With that fault in the lab, the read at e7 still gets 0101. The read at e11 prints "wants 1010, gets 1011, a bad read", and the result row reads "done=1 fail=1 bad reads=1".

This lab leaves things out. The controller is test code, not a circuit of the chip. Two patterns find a cell that is stuck. They do not find every fault of a real memory, such as one cell that disturbs its neighbour.

Why It Is Built This Way

Design choiceThe alternativeWhat the choice buys, and costs
A controller on the chipThe tester writes and reads each word through the pinsThe test runs at the speed of the chip and needs three pins. The controller and the mux take area.
A mux at the portTest the memory through the function logicThe test reaches every address directly. The mux sits in the fastest path of the memory.
Two result bitsSend every wrong word to the testerA simple answer for the factory. To find which cell failed, more logic is needed.

The Trap: A Test That Never Started

A start-up program ran the memory test on every power-up. It wrote the start bit, read fail, saw 0 and went on. For a year every chip passed. Then someone found that the test had never run.

The handoff was missing. The port mux still pointed at the function side, so the controller ignored the start. Our lab shows it: "start ignored: the function side owns the port", and ten edges later "done=0 fail=0". The program had read only half of the answer. Fail at 0 proves nothing until done is 1.

A second trap is the content. A chip ran its memory test in the field, as a health check, and came back with an empty buffer. The test had done what rule 5 says. Anything the function still needs must be saved before the handoff, or the test must wait.

The third trap is a late write. A DMA job was still running when the test took the port. Its last bytes were refused, as in row e6, and nobody was told.

At Scale

This page1 memory of 2 words
A phone chiphundreds of memories

This section looks ahead. Two words become millions, and one memory becomes hundreds.

  1. Longer sequences

    Real controllers walk through the addresses several times, up and down. That also finds a cell which disturbs its neighbour.

  2. Many memories, few controllers

    One controller can serve several memories in turn. Running them all at once may draw more power than the chip can supply.

  3. Repair

    A large memory carries spare rows. A controller that reports which word failed lets the factory switch a spare in.

  4. A ROM

    A ROM cannot be written. Its content is read out and pressed into one short number, which is compared with the right one.

Try It

Run the lab. Find the four rows that start with "test reads", and check each against the pattern of its pass.

Find the line under the comment "One faulty cell to study", and change its 0 to 1. Bit 0 of word 0 now always reads 1. Which read goes wrong, and in which pass?

Set WORDS to 4. On which edge does done rise now?

Names Printed by the Lab
NameMeaning
e1, e2, ...Rising edges of the clock. A row shows what happened on that edge.
word 0, word 1The two words of the memory. Each has four bits, written from bit 3 down to bit 0.
wants, getsThe pattern that the controller wrote to that word, and what the read returned.
bad readsHow many reads returned something other than the pattern.
RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: e2 function writes word 0: 1001 the test controller owns the port e4 start e5 test writes word 0: 0101 e6 function write refused: the test owns the port e6 test writes word 1: 1010 e7 test reads word 0: wants 0101, gets 0101 e8 test reads word 1: wants 1010, gets 1010 e9 test writes word 0: 1010 e10 test writes word 1: 0101 e11 test reads word 0: wants 1010, gets 1010 e12 test reads word 1: wants 0101, gets 0101 e12 done=1 fail=0 bad reads=0 the function side owns the port e14 function reads word 0: 1010

Check Yourself

Predict the outputIn this run the memory has four words and is healthy. The start is still at e4. What is the last row? Its form is: e.. function reads word 0: ....
`timescale 1ns/1ns
module tb;
  logic clk = 0;
  always #5 clk = ~clk;                // e1 is the first rising edge

  localparam int WORDS = 4;
  // One faulty cell to study. STUCK = 0 is a healthy memory.
  localparam bit STUCK = 0;
  localparam int STUCK_WORD = 0, STUCK_BIT = 0;
  localparam bit STUCK_AT = 1;

  logic [3:0] ram [0:WORDS-1];
  task automatic store(input int a, input logic [3:0] d);
    ram[a] = d;
    if (STUCK && a == STUCK_WORD) ram[a][STUCK_BIT] = STUCK_AT;
  endtask

  // The mux at the port of the memory. owner = 0: the function side. owner = 1: the test controller.
  bit owner = 0;
  bit f_write = 0, f_read = 0, start = 0;
  int f_word = 0;
  logic [3:0] f_data = 0;

  // The pattern: 0101 in even words and 1010 in odd words. The second pass writes the opposite.
  function automatic logic [3:0] pattern(input int a, input bit second);
    return (a[0] ^ second) ? 4'b1010 : 4'b0101;
  endfunction

  bit running = 0, reading = 0, second = 0, done = 0, fail = 0;
  int word = 0, edges = 0, bad = 0;
  always @(posedge clk) begin
    edges++;
    if (f_write && owner) $display("e%0d function write refused: the test owns the port", edges);
    else if (f_write) begin store(f_word, f_data); $display("e%0d function writes word %0d: %b", edges, f_word, f_data); end
    if (f_read && !owner) $display("e%0d function reads word %0d: %b", edges, f_word, ram[f_word]);
    if (start && !owner) $display("e%0d start ignored: the function side owns the port", edges);
    else if (start) begin
      running = 1; reading = 0; second = 0; word = 0; done = 0; fail = 0; bad = 0;
      $display("e%0d start", edges);
    end else if (running && owner) begin
      if (!reading) begin
        store(word, pattern(word, second));
        $display("e%0d test writes word %0d: %b", edges, word, pattern(word, second));
      end else if (ram[word] === pattern(word, second))
        $display("e%0d test reads word %0d: wants %b, gets %b", edges, word, pattern(word, second), ram[word]);
      else begin
        $display("e%0d test reads word %0d: wants %b, gets %b, a bad read", edges, word, pattern(word, second), ram[word]);
        fail = 1; bad++;
      end
      if (word == WORDS-1) begin
        word = 0;
        if (reading && second) begin
          running = 0; done = 1;
          $display("e%0d done=%b fail=%b bad reads=%0d", edges, done, fail, bad);
        end
        if (reading) second = 1;
        reading = !reading;
      end else word++;
    end
  end

  task automatic function_write(input int a, input logic [3:0] d);
    @(negedge clk); f_write = 1; f_word = a; f_data = d;
    @(negedge clk); f_write = 0;
  endtask
  task automatic function_read(input int a);
    @(negedge clk); f_read = 1; f_word = a;
    @(negedge clk); f_read = 0;
  endtask

  initial begin
    function_write(0, 4'b1001);        // the function side uses the memory
    @(negedge clk);
    owner = 1;                         // the handoff: the test controller takes the port
    $display("the test controller owns the port");
    start = 1;
    @(negedge clk); start = 0;
    function_write(0, 4'b1111);        // the function side tries to write during the test
    wait (done);
    @(negedge clk);
    owner = 0;                         // the port goes back
    $display("the function side owns the port");
    function_read(0);
    $finish;
  end
endmodule
ConceptWhy does a memory need a test of its own?
ConceptWhat does the test controller report?
ConceptWhy is one pattern not enough?
ConceptWho may use the memory while the test runs?

Common Mistakes

Wrong Read fail and ignore done.

A test that never ran also shows fail at 0.

Fix Wait for done at 1, then read fail.

Wrong Write one pattern and call the memory tested.

A stuck cell agrees with a pattern that wants its value.

Fix Follow each pattern with its opposite.

Wrong Expect the content to survive the test.

Every word ends with the last pattern.

Fix Save what the function needs, or run the test before the memory is used.

Remember

  • A controller on the chip writes the memory, reads it back and reports done and fail.
  • A pattern is followed by its opposite, so that every cell holds a 0 and a 1.
  • Fail means something only when done is 1.
  • The port has one owner, and the test destroys the content.

Practice

Report a problem with this page