A Test for Every Reset Source
A chip can be reset from five places. Each is its own path from a request to a reset to a record. Test each one: did the reset happen, how far did it reach, and did the chip write down why?
You Will Be Able To
- List the reset sources of a chip and what each one reaches.
- Write a firmware test that survives its own resets and checks the cause after each one.
- Say what a warm reset leaves behind, in the chip and in a C program.
- Raise a reset at a chosen moment from the bench, including in the middle of a line of output.
- Lesson
- V9.1
- Time
- 26 min
- Runs on
- Your browser
- Check
- 5 questions
A product restarts in the field, and RESET_CAUSE says "watchdog". That is true only if someone tested that the watchdog, and nothing else, sets that bit.
- Clock / reset
- Pads
- Peripheral
- Debug
- Processor
- Bus
- Reset
- Five ways in
Power, the pin, the watchdog, software and the debugger can each reset the chip.
- One record
ap_crg sets a bit of RESET_CAUSE for each source. Power-on starts a new record.
- Different reach
Pin, watchdog and software reset the core and the bus. The debug request resets the core alone.
- What only power reaches
ap_pwrctl, the slow bus, the scratch registers, the debug module, its TAP and the sampled BOOT strap are reset by power-on only.
Read the diagram as text
- Power-on cell: supply comes up
- RST_N pin: two samples
- Watchdog: no kick in time
- SOFT_RESET: firmware asks
- Debug request: tied low on v1.5
- ap_crg: RESET_CAUSE, reach
- Core: every source
- Bus, peripherals, watchdog: not the debug request
- Power-on cell → ap_crg: bit 0
- RST_N pin → ap_crg: bit 1
- Watchdog → ap_crg: bit 2
- SOFT_RESET → ap_crg: bit 3
- Debug request → ap_crg: bit 4
- ap_crg → Core: resetn_core
- ap_crg → Bus, peripherals, watchdog: resetn_sys
ap_crg.sv and the lab block reset_sources.sv it uses unchanged (facts 10, 27.3, 27.11). The debug module of v1.5 asks for no reset: its request is tied low, and only the bench can raise it.
Before You Start
Read Clocks, Resets and Straps From the Outside and The Mailbox first. How a reset controller is built is taught in Reset Sources and the Reset Cause Register; this page tests it.
| Question | |
|---|---|
| 1 | Why does each reset source need its own test? |
| 2 | How does a firmware test survive the reset it asks for? |
| 3 | What does RESET_CAUSE read after several resets in a row? |
| 4 | Which parts of the chip does each source reset? |
| 5 | What does a warm reset leave in SRAM and in a C program's variables? |
The Idea: One Path per Source
A reset is not one thing. The power-on cell, the pin, the watchdog, a software request and the debugger each start a reset through their own logic. Each sets its own bit of the record, and each reaches its own set of blocks. A bug can sit in any one of the five paths and leave the other four working.
So a chip-level reset test asks three questions of every source. Did the reset happen at all? Did it reach exactly what the specification says, no less and no more? Did the chip record the right cause? A fourth question is about software: what is left after the reset, for the program that runs next?
The test has a strange shape. It is reset in the middle by its own request, and it must carry on afterwards. The chip gives it a place to keep its step: four scratch registers that only power-on clears.
New Words
| Word | Meaning |
|---|---|
| Reset source | Something that can start a reset: power-on, the RST_N pin, the watchdog, SOFT_RESET, the debug module. |
| Cold reset | The power-on reset: everything starts again, the record of causes too. |
| Warm reset | Any other reset: power stays on, so some state survives it. |
| RESET_CAUSE | The register of ap_sysctl that records which sources have reset the chip since power-on. |
| Sticky | A bit that stays set until something clears it on purpose. Each cause bit is sticky until the next power-on. |
| Reach | The set of blocks a reset source puts into reset. |
| Scratch register | A register with no meaning to the chip. TB_STATUS to TB_ARG are cleared by power-on only, so a test can keep its step there. |
The Smallest Example: A Record That Grows
RESET_CAUSE starts at 0x01 after power-on: bit 0 is set. Then a pin reset sets bit 1, a software reset bit 3, the watchdog bit 2. Work out the word after each step before you read on.
| After | Bits set | RESET_CAUSE |
|---|---|---|
| power-on | 0 | 0x01 |
| a pin reset | 0, 1 | 0x03 |
| a software reset | 0, 1, 3 | 0x0B |
| a watchdog reset | 0, 1, 2, 3 | 0x0F |
| power-on again | 0 | 0x01 |
The word only grows, until power-on starts it again. A test that compares the whole word with a single bit fails on the second reset. A test that ignores the word misses a source that records nothing.
The Rules
Rule 1: Raise every source at least once.
Each source is its own logic from request to reset. A test of the pin says nothing about the watchdog.
Rule 2: Keep the step where only power-on clears it.
A scratch register survives a warm reset. A C variable in .bss does not: start-up code clears it on every boot.
Rule 3: Check the record after every reset.
Compare the bits you are sure of exactly. Accept a bit another agent may add, such as a debug reset, and print the word.
Rule 4: Check the reach, not only the restart.
A pin reset must reset UART0's registers; a debug reset must not. Read a block that should and one that should not have been reset.
Rule 5: Give every wait for a reset a limit.
A source that never resets the chip leaves the test waiting for ever. A limit turns that into a fail code.
Rule 6: Raise sources at awkward moments too.
The bench can reset the chip at any cycle: in the middle of a line, a bus transfer or a DMA copy. The next lesson does that on purpose.
Sources for These Rules
The sources, the record and the reach: reset_sources.sv (content/modules/v3/soc/ap_soc). ap_crg.sv uses it unchanged (facts 10 and 27.11).
The scratch registers and their reset: facts 27.3 ("cleared by the power-on reset only").
The bench's knobs: tools/soc/ap_soc/bench/soc_tb/README.md, "Interconnect and boot experiments (E19)": +reset_<source>=<cycle>, +count_resets. The debug request is tied low at the chip boundary, so the bench drives ap_crg's synchronizer input.
Start-up code clears .bss and copies .data only when the two addresses differ: tools/soc/fwkit/crt0.S and the kit README.
Debug resets: RV-DBG 3.2 (reset control) and 3.14.2 (dmcontrol fields hartreset and ndmreset). mcause after reset: RV-PRIV 3.4; ap_rv32_csr.sv resets it to 0.
The Lab: Five Sources on the Chip
One image, built with the firmware kit, runs on the site's chip bench. At each boot it prints its step (kept in TB_ARG), RESET_CAUSE, a variable with a first value (.data) and one without (.bss). Then it asks for the next reset. The pin comes by TB_EVENT 2, software by SOFT_RESET bit 1. The watchdog is armed and never kicked.
CONSOLE 982: step 00000000 cause 00000001 data 00000100 bss 00000000
EVENT 1009: 00000002
CONSOLE 1999: step 00000001 cause 00000003 data 00000101 bss 00000000
CONSOLE 3013: step 00000002 cause 0000000b data 00000102 bss 00000000
CONSOLE 4400: step 00000003 cause 0000000f data 00000103 bss 00000000Rules 1 and 3 at work: four boots, and the record grows 0x01, 0x03, 0x0B, 0x0F. The bench counted one reset of each kind: pin 1, software 1, watchdog 1, and the power-on of the start, 1.
Rule 2 at work: the step in TB_ARG went 0, 1, 2, 3 through three warm resets. The .data variable went 0x100, 0x101, 0x102, 0x103: SRAM kept its words. In this layout .data already sits where the program runs, so start-up code copies nothing over it. The .bss variable read 0 at every boot, although the program wrote 7 each time.
Now the bench raises the two sources firmware cannot. Be clear about the first one. On ap_soc v1.5 the debug module never asks for a reset. Its request is tied low, so no program and no debugger can raise it. The bench forces the input of ap_crg's synchronizer instead. That tests the path a later chip would use, not anything v1.5 can do in the field. Here it comes 200 cycles after the core first left reset:
CONSOLE 1215: step 00000000 cause 00000011 data 00000100 bss 00000000
CONSOLE 2233: step 00000001 cause 00000013 data 00000101 bss 00000000
CONSOLE 3247: step 00000002 cause 0000001b data 00000102 bss 00000000
CONSOLE 4635: step 00000003 cause 0000001f data 00000103 bss 00000000It struck before the first line was printed, so the core simply started main again. RESET_CAUSE read 0x11 at that boot and kept bit 4 for good: 0x1F at the end. The bench counted reset_debug = 1. By the RTL the bus was not reset: a debug reset reaches the core alone. Problem V9.2.2 shows a DMA job running straight through one.
Then a power failure 300 cycles in, in the middle of the first line of output:
CONSOLE 1284: step step 00000000 cause 00000001 data 00000100 bss 00000000
CONSOLE 2302: step 00000001 cause 00000003 data 00000101 bss 00000000The first line was cut after "step " and the program started again from power-on. RESET_CAUSE read 0x01 again: power-on starts a new record. A half line in a log is the mark of a reset that struck while firmware was talking.
Why It Is Built This Way
Why is the record sticky? Because the program that reads it runs after the reset, sometimes after several. A record that held only the last cause would lose the first one when a second reset followed. Power-on clears it, because a new supply is a new story.
Why do the scratch registers survive warm resets? So a test, or a product's boot code, can carry a note across them: a step number, a crash address. Real chips have such registers for exactly that reason.
Why does the debug request reach only the core? A debugger restarts the program but keeps its own session and the chip's state for inspection. So the debug module and the TAP are reset by power-on only, and the bus keeps running. The RISC-V debug specification names two such resets: one of the selected cores alone, and one of everything except the debug logic. ap_soc's request is the first kind. V9.6 shows what it costs.
Why a register outside the core at all? RISC-V lets a core report a reset's cause in mcause, but only as a value the chip defines. The core of ap_soc always resets mcause to 0, the value for a core that does not tell causes apart. So on this chip only RESET_CAUSE says why.
Traps
The first trap is the test that checks only the restart. It asks for a software reset, sees main again, and passes. A chip whose software reset records the debug bit instead passes it too. The field engineer who reads that register later is told the wrong story.
The second is a step kept in a C variable. A variable with no first value, or a first value of 0, lives in .bss. Start-up code clears it at every boot. The test starts again from step 0 after every reset and never ends.
The third is a simulation artifact. ap_sram.sv has no reset input, so in simulation SRAM keeps its words even through a power-on reset. A real SRAM loses them when the supply goes. A test must not lean on SRAM after power-on, even though the bench lets it.
At Scale
This section looks ahead. ap_soc has five sources and one record.
More sources
Large chips add brown-out detectors, clock monitors, thermal limits, lockstep compare errors and security alarms. Each is one more path to test.
A reach matrix
The plan lists every source against every reset domain, with the expected effect in each cell. Each cell is a check.
Reset in every state
Each source is raised in each power mode and during boot, not only while main runs.
Try It
Run it: the record after each source, and which resets each source raised.
Find the line where "bus and I/O" is 0. Which source is that, and why?
Change the list to put "por" in the middle. What happens to the bits before it?
power-on cause=00001 reached: core 1, bus and I/O 1, debug 1 pin cause=00011 reached: core 1, bus and I/O 1, debug 0 software cause=01011 reached: core 1, bus and I/O 1, debug 0 watchdog cause=01111 reached: core 1, bus and I/O 1, debug 0 debug cause=11111 reached: core 1, bus and I/O 0, debug 0Check Yourself
Common Mistakes
Wrong Pass a reset test once main runs again.
The reset happened, but its record and its reach are untested.
Fix Check RESET_CAUSE and one block inside and one outside the reach after every reset.
Wrong Keep the test's step in a C variable.
A .bss variable is cleared by start-up code at every boot, so the test loops for ever.
Fix Keep it in a scratch register that only power-on clears.
Wrong Compare RESET_CAUSE with the bit of the newest source.
The record is sticky: earlier bits are still set.
Fix Compare with the bits of every source so far, and accept bits another agent may add.
Remember
- Each reset source is its own path: request, reset, reach and record. Test all five.
- RESET_CAUSE is sticky: bits gather until power-on starts a new record.
- A debug reset reaches the core only; pin, watchdog and software reach the bus too; power-on reaches everything.
- A test survives its own resets by keeping its step in a register only power-on clears.