Definition
Power-loss injection is a test technique that removes a device’s supply voltage while the device is working, for example while it writes to flash memory §6.6, then restores power and checks that the device recovers to a valid state. Unlike a reset, which leaves the processor chip powered, a loss of power can stop a flash write or erase part way and leave partly written data. The instant that matters is when the chip actually stops operating correctly, which can come many milliseconds after the command that switched the power off.
The idea
A test host tells a power switch to cut a device’s supply at the moment the device starts writing a commit record §8.21. The switch takes a few milliseconds to open. After it opens, the capacitors on the device’s board, components that store electric charge, keep supplying current, and the voltage at the chip falls gradually. The chip keeps running until the voltage drops below the minimum at which it is specified to work, or until its brownout detector, a circuit that resets the chip when the voltage gets too low, stops it. By then the commit record may be complete, and the operation that is actually cut may be a later one. The test log says “cut during the commit record”; the device experienced something else.
So the command and the cut are different events. The command is when the host asked; the cut is when the chip stopped. Power-loss injection is only as good as its measurement of the second.
Switching off a lamp whose light fades slowly is a fair picture: the room does not go dark at the moment of the switch. The picture stops at one point. A falling voltage does not make a chip slowly dimmer. Below its minimum operating voltage, and until the brownout detector acts, the chip may keep running with no guarantee of correct behavior, and a flash write in that range has no guaranteed result.
How it works
Switch the supply. Put a controllable switch, such as a transistor switch, a relay or a programmable power supply, between the supply and the device. Measure its switching delay instead of trusting a nominal figure.
Find every other source of power. A debug probe (the adapter used to program and debug the chip), a serial adapter or any other connected signal line can feed the chip through its input and output pins and keep it running after the main supply is off. Disconnect these, or measure that they supply nothing.
Measure the supply and the program on one instrument. Record the supply voltage at the chip’s supply pin with an oscilloscope, an instrument that records voltages against time. On other channels of the same instrument, record marker pins that the firmware sets at the start of each flash write or erase and clears at its end. One instrument means one clock, so the voltage and the markers can be compared directly. With two instruments, their clocks must be matched against a shared event, and the remaining error added to the measurement uncertainty §11.33.
Define the cut point before measuring. The usual criterion is the first instant the voltage at the chip falls below the minimum operating voltage in the chip’s datasheet, the manufacturer’s specification, or the instant the brownout reset §6.17 takes effect. The cut point is that instant, not the command time.
Classify the cut. Find the operation whose marker interval contains the cut point. The uncertainty is the instrument’s sampling interval plus the error in the voltage threshold. A cut within that uncertainty of an operation’s start or end is labeled ambiguous.
Aim the cut, if a particular operation must be hit. Let the marker itself trigger the switch, and shorten the time the board keeps running by reducing its capacitance or discharging it actively, so that the cut follows the marker by a short, known delay.
Restore power and check. Restoring power has its own hazards: a slow rise, or a switch whose contacts bounce, can cause several short power cycles. Then let the device recover, check the invariants, and read out the storage contents to record the state that the cut left.
Worked example
Estimate how long a board keeps running after the switch opens, in a simplified model. The board’s capacitance is microfarads, which is 0.0001 farad. The device draws a constant current of milliamperes, which is 0.005 ampere. The chip works from 3.3 volts down to a minimum of 1.8 volts, a permitted drop of volts.
The charge that the capacitance gives up over that drop is coulomb. At 0.005 ampere, that charge lasts second, which is 30 ms. If one 4-byte flash write takes 50 microseconds, the chip can complete such writes after the switch opens.
A trace shows why the command time misleads. The host commands the cut at ms, and the switch opens at 2 ms. The markers show the commit-record write from 10 ms to 12 ms, and an erase that starts at 20 ms and would take 85 ms. The voltage at the chip crosses 1.8 volts at ms. The cut point is 32 ms, inside the erase, ms after it began. The test meant to cut , but had finished ms before the cut. The result belongs in the coverage map as “erase torn”, not “commit record torn”.
Stated precisely
The hold-up estimate follows from two definitions. A capacitance , in farads, at voltage , in volts, holds charge , in coulombs. A current , in amperes, removes coulombs per second. If is constant and positive and nothing else supplies the chip, the time for the voltage to fall by volts is seconds. With the values above, s. Real boards break these assumptions: a voltage regulator between the capacitors and the chip changes how the chip’s voltage falls, and a load whose current drops as the voltage drops discharges more slowly toward the end. The formula gives a first estimate, not a bound for a particular board; only a measured trace gives the real time.
The cut point is , the first time at which the measured voltage at the chip is below , the minimum operating voltage. Let operation start at the time of its start marker and end at the time of its end marker, with if no end marker was recorded, and let be the uncertainty in time. The cut tore operation if ; it fell cleanly between operations if it lies more than from every operation’s interval; otherwise it is ambiguous. In the trace, with ms, ms, no end marker for , and ms: , so the cut tore .
Limits and common mistakes
Below the minimum operating voltage and before the brownout reset, the chip runs without guarantees. A flash cell programmed or erased in that range can read back as either value, and the value read can change on later reads. Recovery must apply to such data the same checks as to any torn write §8.19.
Results from resets do not carry over to power loss, nor the reverse. A reset leaves the chip powered, and a power loss does not, so the two can stop different mechanisms.
Power fed back through signal lines can keep the chip running and make a cut look cleaner than it was.
Successful recovery from a few dozen cuts does not show that every cut is safe. The coverage map of the reset injection §8.37 entry applies here, with the measured cut point as the landing point.
Restoring power is part of the test: brief dips, bouncing contacts and slow rises are failure modes of their own.
The voltage at the board’s input is not the voltage at the chip. Measure at the chip’s supply pin.
Questions answered
How is the actual cut point measured independently of the command to cut power?
The actual cut point is measured on the device itself, not taken from the host’s command. Record the voltage at the chip’s supply pin together with marker pins that the firmware sets at the start and clears at the end of each flash write or erase, on one instrument with one clock, such as an oscilloscope with enough channels for both. Fix the criterion in advance: the cut point is the first instant the voltage falls below the chip’s minimum operating voltage, or the instant the brownout reset takes effect. The operation whose marker interval contains that instant is the one the cut hit. Report the uncertainty, which comes from the sampling interval and the error in the voltage threshold, and label cuts within that uncertainty of an operation’s start or end as ambiguous. The command time cannot stand in for the cut point: the switch adds its own delay, and the board’s capacitors keep the chip running for milliseconds after the switch opens, so the real cut can fall several operations later.
Related entries: Reset injection (§8.37), Crash consistency (§8.4), Counter quantization (§11.35), Wall clock and clock synchronization (§9.36), Brownout and power-on reset (§6.17), Torn write (§8.19), Measurement uncertainty (§11.33).