Definition
A power-on reset is a reset that a circuit on the chip applies while the supply voltage rises from zero: it holds the chip in reset until the voltage is high enough, so that the chip starts from a known state. A brownout reset is a reset that a voltage monitor applies when the supply voltage of a running chip falls below a threshold, because below its minimum operating voltage the chip may misbehave. Power-on reset handles power arriving; brownout reset handles power sagging.
The idea
A battery-powered sensor is writing a record to flash memory §6.6 when its battery contact shakes loose for a moment. The supply voltage sags from 3.0 V to 1.4 V for 20 ms and then recovers. A brownout is exactly this: a drop in supply voltage that is not, or not yet, a complete loss of power. Without a brownout reset, the processor keeps executing at a voltage at which its logic may produce wrong results and flash programming may store wrong bits, and the device may carry on with corrupted state. With a brownout reset, the chip stops as soon as the voltage crosses the threshold and starts again cleanly once the voltage recovers.
The core idea is that a reset prevents work at a bad voltage; it does not finish the work in flight. The record that was being written when the voltage crossed the threshold is cut off, and after the restart, flash memory holds whatever the interrupted operation left behind. A referee who stops a match when the floodlights fail is a fair picture: no play happens in the dark, and the rally in progress is simply not completed. The picture stops being accurate in one respect: a match restarts from the scoreboard, which is always correct, while the device restarts from its storage, which may hold a half-written record.
How it works
Power-related resets work as follows.
Power-on. The supply voltage ramps up from zero. The power-on reset circuit holds the chip in reset until the voltage has passed its threshold, then releases it. The processor starts at its reset handler, every register holds its documented reset value, and the content of RAM is undefined.
Running. A brownout detector, a comparator that continuously watches the supply voltage, triggers a reset as soon as the voltage falls below its threshold, and holds the chip in reset until the voltage has recovered. The release level is usually slightly above the trigger level, a gap called hysteresis, so that a voltage hovering near the threshold does not cause a burst of resets.
Early warning. Many chips also have a power-fail comparator with a higher, programmable threshold, which raises an interrupt §6.11 instead of a reset. On Nordic Semiconductor’s nRF52840 §6.4 microcontroller §6.1 this is the power-failure comparator, configured through the
POFCONregister (power-failure comparator configuration), which signals aPOFWARNevent (power-failure warning). Software uses the warning to stop starting new flash memory operations.Restart. When the reset ends, the chip boots as after any reset, and start-up code can read a reset-reason register to learn what caused the reset.
Flash memory operations are slow compared with instructions. On typical microcontroller flash memory, programming one 32-bit word takes tens of microseconds, and erasing one page, the smallest unit that can be erased, takes tens of milliseconds. An operation that is in progress when the voltage falls below the flash memory’s minimum operating voltage is cut off. The bits it was changing are then undefined: each may hold the old value, the new value, or a weak level that reads differently from one read to the next.
Worked example
A hypothetical board runs at 3.0 V. Its flash memory is specified down to 1.7 V, and the brownout threshold is set to 1.7 V. The board’s supply capacitors total microfarads, and while the flash memory is busy, the board draws a current of mA. At time 0 the supply is cut, and the capacitors alone feed the board.
With a constant current, the capacitor voltage falls at the rate . Since 5 mA is 0.005 A and 10 microfarads is 0.00001 F, the rate is V/s. The voltage must fall by V to reach the threshold, which takes s, that is, 2.6 ms.
Say that writing one 32-bit word takes at most 41 s and erasing one page takes at most 85 ms on this flash memory.
A word write that started just before the cut has 2.6 ms of valid voltage, far more than its 41 s, so it completes.
A page erase that started 1 ms before the cut is cut off when the voltage reaches the threshold, ms after it began, which is , about 4% of its 85 ms. The page is now partly erased, and no read can tell which of its bits are trustworthy.
The brownout reset did not help the erase. It only made sure that no instruction ran, and no new operation began, below 1.7 V.
A second example shows why the reset source matters to recovery logic. An update procedure on an nRF52840 stores a “trial in progress” flag in a GPREGRET register and then requests a soft reset; the boot code sees the flag and treats the new firmware as on trial. Tested with soft resets, this works every time, because GPREGRET survives a soft reset. After a power cut, a brownout or a pin reset, the register reads 0, the boot code sees no flag, and the device takes a different path, which a test with soft resets alone never exercises. Recovery logic that must work after every kind of reset should decide from flash memory, which survives every kind of reset, and should write it so that an interruption leaves it valid.
Stated precisely
Let be the supply voltage at time , let be the brownout threshold, with BOR standing for brownout reset, and let be the lowest voltage at which the flash memory’s operations are specified. The brownout reset guarantees one thing: whenever , the chip is held in reset, so no instruction executes and no new flash memory operation starts. This protects flash memory operations only if . The brownout reset guarantees nothing about an operation already in progress.
Let a flash memory operation start at time and need until time to finish at a valid voltage, and let be the first time after at which . The operation’s result is defined only if . If , every bit the operation was changing is undefined. A storage format has the property called crash consistency §8.4 when, for every such , the recovery code at the next boot reaches a valid state.
The hold-up time, the time for which the supply capacitors keep the voltage above a level after the supply is cut, is where is the capacitance, the voltage at the cut, the level of interest and the current drawn. The formula assumes that the current stays constant and that the capacitors are the only source of energy after the cut. With , an operation that is in progress at the cut completes only if its remaining time is at most .
Reset sources and what survives them
A chip can be reset for several reasons, called reset sources, and each one leaves behind a different amount of state:
power-on reset and brownout reset: the supply was absent or too low, so nothing survives except non-volatile storage, such as flash memory, which keeps its content without power;
pin reset: something, such as a button or a debugger, pulled the chip’s reset pin low while power stayed on;
watchdog §6.16 reset: a watchdog timer, a hardware timer that resets the device unless software restarts it in time, expired;
soft reset: software asked for a reset. On Cortex-M processors software does this by setting the reset-request bit in the AIRCR (Application Interrupt and Reset Control Register), a write that must also carry the key value
0x05FAin the register’s upper 16 bits. An operating system’s reboot call typically ends with this write;lockup reset: on chips that have it, the processor stopped after a fault it could not handle, and the chip reset itself;
wake from deep sleep: on some chips the deepest sleep state ends with a reset, so waking up looks like a restart.
A restart after a power-on or a brownout is called a cold boot; a restart after a reset during which power stayed on is called a warm boot. After a warm boot some state may remain. SRAM §6.7 (static random-access memory, the chip’s working memory) often still holds its old content, although the chip does not guarantee it, and some registers are deliberately kept.
The nRF52840 makes this concrete. Its RESETREAS register (reset reason) has one bit per reset source: RESETPIN for a pin reset, DOG for a watchdog reset, SREQ for a soft reset, LOCKUP for a lockup reset, and further bits for the ways of waking from System OFF, the chip’s deepest sleep state. The bits accumulate across resets until software clears them by writing 1 to them. Only a power-on or a brownout reset clears the whole register, so a value of zero means that the last reset was a power-on or a brownout, and the register cannot tell those two apart. The general-purpose retention registers, named GPREGRET, survive a soft reset, a lockup reset and a wake from System OFF, and are cleared by a pin reset, a watchdog reset, a brownout and a power-on. A running watchdog survives a soft reset.
Limits and common mistakes
A reset threshold is not a promise to finish writes. The brownout reset stops the chip; it completes nothing, and an interrupted write or erase leaves undefined bits.
A pin reset or a soft reset is not a power cut. Power stays on, so no operation runs at a falling voltage, and SRAM, retention registers and, on some chips, a running watchdog survive. Tests that use only such resets miss the states a power loss creates; the Reset injection §8.37 and Power-loss injection §8.38 entries treat the two kinds of test.
A pin reset is a fair test of logic that decides from flash memory alone, such as a boot step that discards an update that was never confirmed, provided that the reset lands at a moment when no flash memory operation is in progress and that the logic reads nothing that a pin reset keeps but a power loss destroys. It is not a test of a power loss during a flash memory write.
A brownout threshold set below the flash memory’s minimum voltage, or a brownout detector switched off to save power, lets the chip run and write at a voltage at which neither is specified.
A nearly empty battery can cause a reset loop. In reset the chip draws little current, and the voltage recovers above the threshold; the chip starts, draws more current, and the voltage sags below the threshold again.
A reset-reason register has to be read early in every boot, and cleared if its bits accumulate. On the nRF52840 a reading of zero cannot distinguish a power-on from a brownout.
Hold-up capacitance helps only for operations shorter than the hold-up time, and only if software stops starting new operations when the early warning arrives.
Questions answered
Which storage writes are guaranteed complete at the reset threshold?
Only the writes that had already finished, as reported by the flash memory controller, while the supply voltage was still within the flash memory’s specified operating range. The reset threshold is the supply voltage below which a brownout reset holds the chip in reset. Crossing it stops the chip: no instruction runs and no new operation starts below it. It completes nothing.
A write or an erase that is in progress when the voltage falls below the flash memory’s minimum operating voltage is cut off, and every bit it was changing is undefined: the old value, the new value, or a weak level that reads inconsistently. Data that software still held in RAM, such as a buffer waiting to be written, is lost. Which operations in flight do finish depends on how long each needs, how long the board’s capacitors keep the voltage up after the supply fails, and whether software reacted to an early power-fail warning; only the chip’s datasheet and the board’s measured hold-up time can establish that.
The safe design therefore assumes that any operation in progress can be interrupted. It writes the data first and a small commit record §8.21, which marks the data as complete, last, checks each record with a checksum §4.32 at boot, keeps the previous valid copy until the new one is committed, and stops starting flash memory operations when the power-fail warning arrives. Test it with real power cuts, not only with software or pin resets, which leave the power on.
Related entries: Torn write (§8.19), Reset injection (§8.37), Power-loss injection (§8.38), Crash consistency (§8.4), Flash memory (§6.6), Watchdog timer (§6.16).