Reset Sources and the Reset Cause Register
The boot banner appears twice. Power stayed on, nobody touched the board, and the second boot looks healthy. One small register can say what happened, if the restart did not erase it.
You Will Be Able To
- Tell a cold reset from a warm reset, and name the five reset sources of ap_soc.
- Say which domains each source resets, and why the debugger resets less.
- Read a reset cause word, and say what it can and cannot tell.
- Lesson
- S5.4
- Time
- 24 min
- Runs on
- Your browser
- Check
- 6 questions
A device in the field restarts once a week. Every restart looks the same: the same banner, the same healthy boot. Somewhere on the chip, one bit knows whether a person pressed a button or the software hung. Where does that bit have to live to still be there?
Before You Start
You need Reset and Interrupts in One Picture: what a reset does to the processor. You need APB, a Few Signals at a Time: a read has a setup cycle and an access cycle.
This page ends at a register that software reads over the bus, like any register of a peripheral. The Anatomy of a Peripheral shows what a register block is. Read it first if a register behind a bus is new to you.
Two sources on this page are devices that later pages build. For now one line each is enough, and both are in the word table.
| Question | |
|---|---|
| 1 | What is a cold reset, and what is a warm reset? |
| 2 | Which domains does a debug request reset? |
| 3 | What does the reset cause register tell boot software? |
| 4 | What can a cause word not tell? |
| 5 | Why must the reset pin be high for two samples? |
The Idea: A Restart Must Leave a Note
A reset puts storage into a known starting state. A chip can be reset for several reasons, and after the reset it looks the same whatever the reason was. That is the point of a reset, and it is also a loss: the reason is gone.
The reason matters. A restart at power-up is normal. A restart by the watchdog means that software hung, and someone should hear of it. So a chip keeps a note. A small register records which source asked for the reset. Boot software reads it first thing.
For the note to survive, the reset must not reach it. Here two words help. A cold reset is the reset at power-up: the supply has just come on, and everything starts fresh, the note included. A warm reset is any reset while the power stays on. It restarts chosen parts of the chip and leaves the rest alone. The note is in the rest.
So each thing that can reset the chip needs two decisions. What does it reset? And is the record outside that reach? A debugger, the tool an engineer uses to stop and inspect a running chip, shows why the first answer varies. It wants to restart the processor and stay attached. So its reset must not touch the debug logic.
New Words
| Word | Meaning |
|---|---|
| Reset source | Anything that can ask for a reset of the chip. |
| Power-on reset (POR) | A circuit that holds the chip in reset while the supply comes up, and a little longer. |
| Cold reset | The reset at power-up. Everything starts from its reset value, the reset record included. |
| Warm reset | A reset while the power stays on. Chosen parts restart. The reset record, and some other state, is kept. |
| Watchdog | A timer that software must restart again and again. If software stops doing so, the watchdog asks for a reset. |
| Debugger | A tool on a desk computer that controls the chip through a few debug pins. |
| Reset domain | A group of flip-flops that are reset together, by the same reset signal. |
| Reset cause register | A register with one bit for each reset source. A bit that is 1 says: this source has reset the chip. |
| Sticky bit | A bit that stays 1 once it is set. Here neither a read nor a warm reset clears it. |
| Pin filter | Logic that accepts a level on a pin only after it has been seen for several samples in a row. |
| Source | Cold or warm | Core domain | Bus and I/O domain | Debug domain | Its bit in the cause register |
|---|---|---|---|---|---|
| Power-on reset | cold | reset | reset | reset | bit 0 |
| Reset pin, held | warm | reset | reset | runs on | bit 1 |
| Watchdog | warm | reset | reset | runs on | bit 2 |
| Software request | warm | reset | reset | runs on | bit 3 |
| Debug request | warm | reset | runs on | runs on | bit 4 |
The reset cause register is at 0x10004004, in a block called ap_sysctl. Reach and bit numbers are choices of ap_soc.
One Picture: From a Request to the Next Boot
- Power
- Control / FSM
- Clock / reset
- Memory
- Processor
- Peripheral
- Debug
- The cold reset
Power comes up. The power-on reset puts every flip-flop of the chip into its starting state. That includes the record itself: a new history begins.
- Four warm sources
With the supply still on, four things can ask for a reset. They are a person at the reset pin, the watchdog, running software, and a debugger. Each sends a request to the reset controller.
- Each source has a reach
The controller does not reset everything for every request. The pin, the watchdog and software restart the processor and the peripherals. The debugger restarts the processor only, and stays attached.
- The record
As the controller accepts a request, it sets one bit in the reset cause register: the bit of that source. The register sits outside the reach of all four warm sources.
- The next boot
The chip restarts and looks the same as after any reset. Boot software reads the cause register over the bus and learns why it is running again.
Read the diagram as text
- Power-on reset: the supply has just come up
- Four warm sources: reset pin, watchdog, software, debugger
- Reset controller: in the block called ap_crg; it stays on through every warm reset
- Reset cause register: one sticky bit for each source
- Core domain: the processor
- Bus and I/O domain: the bus and the peripherals
- Debug domain: the logic a debugger talks to
- Boot software: reads the cause register after reset
- Power-on reset → Reset controller: cold: everything
- Power-on reset → Reset cause register: starts a new record
- Four warm sources → Reset controller: requests
- Reset controller → Core domain: every source
- Reset controller → Bus and I/O domain: all but the debugger
- Reset controller → Debug domain: power-on only
- Reset controller → Reset cause register: sets one bit
- Reset cause register → Boot software: the cause word
Reset in ap_soc. Which source resets which domain is a choice of our chip.
The Smallest Example, Worked by Hand
Follow one history. The cause word has five bits. Bit 0 is on the right. Each accepted source sets its own bit, and nothing but a cold reset clears one.
| Event | Bit set | Cause word in binary | In hexadecimal |
|---|---|---|---|
| Power comes up | 0 | 0 0001 | 01 |
| The reset pin is held | 1 | 0 0011 | 03 |
| The watchdog fires | 2 | 0 0111 | 07 |
| Software asks for a reset | 3 | 0 1111 | 0f |
| The debugger asks for a reset | 4 | 1 1111 | 1f |
Now read a word the way boot software must. Take 07: binary 0 0111. Bits 0, 1 and 2 are set. So power-on, the pin and the watchdog have each reset the chip since power came up.
That is all the word says. It does not say which came last. It does not say whether the watchdog fired once or ten times. A bit that is already 1 cannot be set again.
The pin needs one more table. A reset pin picks up noise, and a spike must not restart the chip. So the controller looks at the pin on every clock edge, and acts only on two high samples in a row.
| Samples of the pin | High samples in a row | Result |
|---|---|---|
| 1, then 0 | 1 | No reset. The cause word does not change. |
| 1, then 1 | 2 | Warm reset of the core and the bus and I/O domain. Bit 1 is set. |
| 1, 0, 1 | 1, then 1 again | No reset. A low sample starts the count again. |
The Rules
Rule 1: A cold reset starts everything, the record included.
In ap_soc only the power-on reset is cold. After it the cause word reads 01.
Rule 2: A warm reset restarts chosen domains and keeps the power on.
The reach of each source is fixed. The table of sources lists it.
Rule 3: Each accepted source sets its own bit in the reset cause register.
The register is outside the reach of every warm source.
Rule 4: The bits are sticky.
A warm reset does not clear them, and a read does not clear them. Only a cold reset starts a new record.
Rule 5: The word names the sources seen since the last cold reset.
It holds no order and no count.
Rule 6: The reset pin counts only after two high samples in a row.
One high sample resets nothing and records nothing.
Sources for These Rules
Every rule on this page describes ap_soc. The reach of each source, the bit numbers, the sticky bits and the depth of the pin filter are our choices.
Cold reset and warm reset are common words in chip and board documents. No standard in our reference library defines them, so the page defines them itself.
The two rows of the bus read, setup and then access: Arm AMBA APB Protocol Specification, IHI 0024 issue E, sections 3.3 and 4.1. Arm AMBA AHB Protocol Specification, IHI 0033 issue C, sections 3.1, 4.2, 5.1.1 and 7.1.2.
Reset at one flip-flop is in Reset: Assert, Release and What RTL Cannot Show.
Now Run It
The lab at the end of this page has the reset controller and the cause register behind the bridge to APB. Test code, a bus-functional model, stands in for the processor: it drives the bus as boot software would. The four warm requests are inputs that the test code raises.
power sample core=1 io=1 debug=1
read sel=1 enable=0 hready=0
read sel=1 enable=1 hready=1
power read=01
short pin sample core=0 io=0 debug=0
short pin read=01
held pin sample core=0 io=0 debug=0
held pin sample core=1 io=1 debug=0
held pin read=03
watchdog sample core=1 io=1 debug=0
watchdog read=07
software sample core=1 io=1 debug=0
software read=0f
debug sample core=1 io=0 debug=0
debug read=1fRule 1 at work: the first row shows all three domains in reset, and the first read returns 01. That read takes two clock edges, the two "read" rows: setup, then access.
Rule 6 at work: the short pin leaves core=0, and the read after it is still 01. The held pin shows core=0 on its first sample and core=1, io=1 on its second. Then the word is 03.
Rules 2 to 4 at work: the watchdog resets the core and the bus and I/O domain, and debug stays 0. The read returns 07: the bits of power-on and of the pin are still there.
The last source is the debugger. Its row shows core=1 with io=0 and debug=0: the processor restarts, and the peripherals and the debug logic run on.
- Sample 0
Power-on reset: the cold reset. All three domains are in reset.
- Sample 1
The pin is high for one sample only. No domain is reset.
- Sample 2
The pin again. Its first high sample: nothing yet.
- Sample 3
Its second high sample in a row: the core and the bus and I/O domain are reset. The debug domain is not.
- Sample 4
The watchdog: the same two domains.
- Sample 5
A software request: the same two domains again.
- Sample 6
A debug request: the core domain only.
Drawn from the seven "sample" rows of the lab. 1 means that the domain is held in reset.
This lab leaves things out. The pin arrives already sampled into the clock of the controller. There is no real watchdog and no debugger. And the lab does not show how a reset is released: that is the next page.
Why It Is Built This Way
| Design choice | The alternative | What the choice buys, and costs |
|---|---|---|
| A cause register in hardware | Software writes a log before it resets | A hung program cannot write a log. The register costs a few flip-flops that need a reset of their own. |
| Sticky bits, one for each source | One field that holds the last source | Nothing is lost if two resets come before a read. Order and count are not kept. |
| A debug request resets the core only | It resets everything, like the pin | The debugger stays attached and can watch the first instruction. The peripherals keep their old state. |
| Two samples on the pin | Act on the first high sample | A spike of noise does not restart the chip. A real press is seen one sample later. |
The Trap: Reading the Highest Bit as the Latest
A field report says "cause 07, so the last reset was the watchdog". Bit 2 is the highest bit that is set. But a bit position names a source. It carries no time. The watchdog may have fired on the first day, and the pin every day since.
If the question is "which came first", the chip needs a register that keeps only the first event. If the question is "how often", it needs a counter. Decide which question the field will ask before the chip is built.
The worse trap is in the wiring. Someone connects the reset of the cause register to the same signal that resets the peripherals. It looks tidy: one reset for the whole block. Now every watchdog reset clears the bit that it has just set, and boot software reads 01 for ever. The second practice problem is that bug.
At Scale
This section looks ahead. Five sources and three domains become dozens of each, and the field report still holds one word.
A table of reach
A row for each source and a column for each domain. Add the record, its clock and the path that software reads it by. A flag behind a bridge that is still in reset helps nobody.
The first reader
Boot code saves the word before any driver clears it. The plan says what happens when a new event arrives on the same edge as the clear.
Order and count
A register for the first event and a counter for each source are cheap. They must be asked for before the chip is built.
Release
This page is about who asks for a reset. How a reset ends, cleanly and in the right order, is Reset Architecture.
Try It
Run the lab. Each source is tried in turn. After each one, test code reads the reset cause register.
Change the held pin from two clock edges to one. Which of the later reads lose bit 1?
Raise the watchdog and the software request together. Predict the read that follows.
Names Printed by the Lab
| Name | Meaning |
|---|---|
| sample | A look at the three reset outputs, 1 ns after a clock edge. 1 means that the domain is held in reset. |
| core, io, debug | The reset outputs for the core domain, the bus and I/O domain and the debug domain. |
| read sel, enable, hready | One row for each clock edge of the first bus read: select, enable and "the transfer is complete". |
| read= | The reset cause register as the read returned it, in hexadecimal. |
| short pin, held pin | The reset pin high for one sample, and high for two samples in a row. |
power sample core=1 io=1 debug=1 read sel=1 enable=0 hready=0 read sel=1 enable=1 hready=1 power read=01 short pin sample core=0 io=0 debug=0 short pin read=01 held pin sample core=0 io=0 debug=0 held pin sample core=1 io=1 debug=0 held pin read=03 watchdog sample core=1 io=1 debug=0 watchdog read=07 software sample core=1 io=1 debug=0 software read=0f debug sample core=1 io=0 debug=0 debug read=1fRead included file: bridge.sv
`timescale 1ns/1ns
// ahb_apb_bridge.sv: an AHB subordinate that turns each accepted transfer into one APB transfer
// (read-only). The address phase is registered when HSEL, HREADY and a NONSEQ or SEQ transfer are
// all present. During SETUP and unfinished ACCESS the bridge keeps HREADYOUT low. A successful APB
// completion ends the AHB data phase with OKAY and HRDATA = PRDATA. A failed APB completion starts
// the two-cycle ERROR (HREADYOUT low then high, HRESP high in both). HWDATA and HWSTRB are data-phase signals the manager holds
// through the wait states, so PWDATA and PSTRB are driven from them directly; PADDR is the aligned
// word address (IHI 0024E 2.1.1 leaves an unaligned PADDR unpredictable). HPROT maps onto PPROT:
// privileged from HPROT[1], instruction from HPROT[0] = 0, and the access is Secure.
// A write therefore costs one setup and one access cycle: two cycles of data phase with no APB wait.
module ahb_apb_bridge (
input logic hclk,
input logic hresetn,
input logic hsel,
input logic [31:0] haddr,
input logic [1:0] htrans,
input logic hwrite,
input logic [3:0] hprot,
input logic [31:0] hwdata,
input logic [3:0] hwstrb,
input logic hready,
output logic hreadyout,
output logic hresp,
output logic [31:0] hrdata,
output logic psel,
output logic penable,
output logic pwrite,
output logic [31:0] paddr,
output logic [31:0] pwdata,
output logic [3:0] pstrb,
output logic [2:0] pprot,
input logic pready,
input logic [31:0] prdata,
input logic pslverr);
localparam int IDLE = 0, SETUP = 1, ACCESS = 2, ERR1 = 3, ERR2 = 4;
bit trace = 0;
int st = IDLE;
logic wr = 0;
logic [31:0] a = 0;
logic [2:0] prot = 0;
wire take = hsel && hready && htrans[1];
assign psel = (st == SETUP || st == ACCESS);
assign penable = (st == ACCESS);
assign pwrite = wr;
assign paddr = {a[31:2], 2'b00}; // APB leaves an unaligned PADDR unpredictable: the word, and PSTRB picks the bytes
assign pwdata = wr ? hwdata : 32'h0;
assign pstrb = wr ? hwstrb : 4'h0;
assign pprot = prot;
assign hreadyout = (st == IDLE || st == ERR2) ? 1'b1 : (st == ACCESS) ? (pready === 1'b1 && pslverr !== 1'b1) : 1'b0;
assign hresp = (st == ERR1 || st == ERR2);
assign hrdata = (st == ACCESS) ? prdata : 32'h0;
always @(posedge hclk or negedge hresetn) begin
if (!hresetn) st <= IDLE;
else begin
case (st)
SETUP: st <= ACCESS;
ACCESS: if (pready === 1'b1) begin
if (trace) $display("apb e%0d: %0s 0x%03h%0s", ($time - 5) / 10, wr ? "write" : "read", a[11:0], pslverr === 1'b1 ? " PSLVERR" : "");
st <= (pslverr === 1'b1) ? ERR1 : IDLE;
end
ERR1: st <= ERR2;
default: st <= IDLE;
endcase
// A new address phase can be taken whenever HREADY is 1: in IDLE, in the last cycle of ERROR,
// or at the edge an access completes with OKAY.
if (take && (st == IDLE || st == ERR2 || (st == ACCESS && pready === 1'b1 && pslverr !== 1'b1))) begin
wr <= hwrite; a <= haddr; prot <= {~hprot[0], 1'b0, hprot[1]}; st <= SETUP;
end
end
end
endmodule
Read included file: reset_bus.svh
// One aligned word at a time. The manager stands in for the future ap_rv32.
logic clk = 0, bus_reset_n;
always #5 clk = ~clk;
logic [31:0] addr = 0, wdata = 0;
logic write_req = 0, request = 0;
wire sel, enable, writing, ready, error, pready, slave_error;
wire [31:0] paddr, pwdata, prdata, rdata;
ahb_apb_bridge bridge (
.hclk(clk), .hresetn(bus_reset_n), .hsel(addr[31:16] == 16'h1000),
.haddr(addr), .htrans({request,1'b0}), .hwrite(write_req), .hprot(4'b0011),
.hwdata(wdata), .hwstrb(4'hf), .hready(ready), .hreadyout(ready),
.hresp(error), .hrdata(rdata), .psel(sel), .penable(enable), .pwrite(writing),
.paddr(paddr), .pwdata(pwdata), .pstrb(), .pprot(), .pready(pready),
.prdata(prdata), .pslverr(slave_error)
);
task automatic issue(input bit wr, input logic [31:0] address, data);
@(negedge clk);
write_req = wr;
addr = address;
request = 1;
@(negedge clk);
request = 0;
addr = 0;
wdata = data;
endtask
Read included file: ap_sysctl_reset_port.sv
// Reset-service words within the ap_soc laboratory system-control page.
// All manager accesses to this port are aligned, full-word APB transfers.
// The cause storage has a separate reset owner and enters through cause.
module ap_sysctl_reset_port (
input logic clk, bus_reset_n,
input logic sel, enable, writing,
input logic [31:0] paddr, pwdata,
input logic [4:0] cause,
input logic service_slot,
output logic page_selected, access_error, armed,
output logic [31:0] read_data
);
localparam logic [31:0] CAUSE = 32'h1000_4004, COMMAND = 32'h1000_4008;
wire cause_read = !writing && paddr == CAUSE;
wire command_write = writing && paddr == COMMAND;
assign page_selected = sel && paddr[31:12] == CAUSE[31:12];
assign read_data = cause_read ? {27'b0,cause} : 32'b0;
assign access_error = page_selected && enable && !(cause_read || command_write);
always_ff @(posedge clk or negedge bus_reset_n) begin
if (!bus_reset_n)
armed <= 0;
else if (page_selected && enable && command_write)
armed <= pwdata[0];
else if (service_slot)
armed <= 0;
end
endmodule
Read included file: reset_sources.sv
// ap_soc lesson slice. The four warm requests are in the always-on clock domain.
// pin_sample is the pad level AFTER synchronization. POR starts a new log.
module reset_sources (
input logic clk, por, pin_sample, watchdog, software_req, debug_req,
output logic core_reset, io_reset, debug_reset,
output logic [4:0] cause
);
logic previous_pin;
logic pin_qualified;
assign io_reset = por || pin_qualified || watchdog || software_req;
assign core_reset = io_reset || debug_req;
assign debug_reset = por;
always_ff @(posedge clk) begin
if (por) begin
previous_pin <= 0;
pin_qualified <= 0;
cause <= 5'b00001;
end else begin
previous_pin <= pin_sample;
pin_qualified <= previous_pin && pin_sample;
if (previous_pin && pin_sample) cause[1] <= 1;
if (watchdog) cause[2] <= 1;
if (software_req) cause[3] <= 1;
if (debug_req) cause[4] <= 1;
end
end
endmodule
Check Yourself
Common Mistakes
Wrong Reset the cause register with the watchdog reset.
The restart erases the only evidence before boot software runs.
Fix Only the cold reset may clear the record.
Wrong Read the highest set bit as the latest reset.
A bit position names a source. It holds no time.
Fix Report every source that is set, and ask for a first-event register if order matters.
Wrong Count high samples of the pin across a low sample.
A low sample ends the run of high samples.
Fix Start the count again after every low sample.
Remember
- A cold reset comes with power-up and starts everything. A warm reset keeps power on and restarts chosen domains.
- Each reset source has a reach. The debugger resets the processor only.
- The reset cause register sets one sticky bit for each source, outside the reach of every warm reset.
- The cause word names the sources seen since power-up. It holds no order and no count.