返回提示词目录第 1307 页

微控制器硬故障解析与定位

结合故障寄存器和代码定位异常原因,给出验证步骤、修复方案及现场信息采集代码。

完整提示词

<context>
The user's firmware hit a fault. On ARMv7-M and ARMv8-M, the Configurable Fault Status Register (CFSR at 0xE000ED28) packs three registers: MMFSR (bits 0-7: IACCVIOL, DACCVIOL, MUNSTKERR, MSTKERR, MLSPERR, MMARVALID), BFSR (bits 8-15: IBUSERR, PRECISERR, IMPRECISERR, UNSTKERR, STKERR, LSPERR, BFARVALID) and UFSR (bits 16-31: UNDEFINSTR, INVSTATE, INVPC, NOCP, STKOF on v8-M, UNALIGNED, DIVBYZERO). HFSR FORCED means a configurable fault escalated; VECTTBL means a bad vector fetch. MMFAR and BFAR are valid only when their VALID bits are set. Imprecise bus faults report a PC after the real culprit (often a buffered write), so disabling write buffering (DISDEFWBUF in ACTLR on M3/M4) makes them precise for debugging. EXC_RETURN tells which stack (MSP or PSP) holds the frame and whether an FPU frame was stacked. Cortex-M0/M0+ have no CFSR: only the stacked frame and context are available. INVSTATE usually means a branch to an address with bit 0 clear (a corrupted function pointer or vector), NOCP an FPU instruction with the FPU disabled, and stacking errors (MSTKERR, STKERR) a stack overflow.
</context>

<task>
<fault_registers>
{{fault_registers}}
</fault_registers>

<map_or_code>
{{map_or_code}}
</map_or_code>

1. If CFSR and HFSR or the stacked PC and LR are missing, say so, give a minimal fault handler that captures them (naked assembly that picks MSP or PSP from EXC_RETURN bit 2 and passes the frame to a C function), and stop after a short list of what the partial data already suggests.
2. Decode every set bit of CFSR and HFSR in a table, and say whether MMFAR or BFAR are valid.
3. Locate the fault: map the stacked PC (and LR for the caller) to function and line with the map file, `arm-none-eabi-addr2line -e app.elf -f -C <pc>` or `objdump -d`, noting that LR has bit 0 set for Thumb and may be an EXC_RETURN value if the fault happened in an interrupt.
4. Rank likely causes using all clues: null or wild pointer (fault address near 0 or in unmapped space), stack overflow (stacking errors, SP near the stack limit, PSP of a task below its stack bottom), unaligned access to a packed struct or casted buffer, divide by zero with DIV_0_TRP enabled, bad function pointer or vector, FPU disabled, use of a peripheral whose clock is off (bus error at a peripheral address), DMA or cache coherency.
5. Give confirmation steps: stack watermarks (`uxTaskGetStackHighWaterMark`), MPU guard regions, a data watchpoint on the address, making imprecise faults precise, and breaking in the debugger at the fault handler.
6. Give the fix for the leading cause and the general hardening it suggests.
7. Provide a production fault handler that saves registers and a backtrace hint to no-init RAM, resets cleanly, and reports them on the next boot.
</task>

<constraints>
- Call the cause the leading hypothesis until a watchpoint, watermark or reproduction confirms it.
- Say which architecture version the decode assumes; ask for the core if it changes the meaning of the bits.
- Do not invent symbol names or addresses not in the input.
{{> guardrails/investigate-before-answering}}
{{> output/uncertainty}}
</constraints>

<output_format>
## Register decode
Table: Register | Value | Bits set | Meaning.
## Faulting location
PC and LR mapped to function and line, or the command to do it.
## Likely cause
Ranked list, each with evidence for and against.
## Confirm it
Numbered steps with what result confirms or rules out each cause.
## Fix
Code or diff for the leading cause.
## Add a fault handler
Code for capturing faults in the field.
</output_format>

可替换内容

  • {{fault_registers}}
  • {{map_or_code}}
  • {{> guardrails/investigate-before-answering}}
  • {{> output/uncertainty}}

分类与标签

编程开发、嵌入式调试、故障寄存器、异常定位、故障现场采集

前往 AI 图片创作