如果TOOL运行期间出错了异常复位,可以方便的锁定问题,方便下次版本迭代更新bug。
[C] 纯文本查看 复制代码 local t = stm32_debug("fault")
if t == nil then
print("本次上电未发生 HardFault")
else
print(string.format("FAULT x%d PC=%08X LR=%08X", t.cnt, t.pc, t.lr))
print(string.format("CFSR=%08X HFSR=%08X BFAR=%08X xPSR=%08X", t.cfsr, t.hfsr, t.bfar, t.xpsr))
print(string.format("SP=%08X MSP=%08X PSP=%08X IPSR=%d", t.sp, t.msp, t.psp, t.ipsr))
-- 常见 CFSR 位判定
if t.cfsr & 0x00000001 ~= 0 then print(" IACCVIOL 取指访问违规") end
if t.cfsr & 0x00000002 ~= 0 then print(" DACCVIOL 数据访问违规") end
if t.cfsr & 0x00000100 ~= 0 then print(" IBUSERR 取指总线错误") end
if t.cfsr & 0x00000200 ~= 0 then print(" PRECISERR 精确总线错误(看 BFAR)") end
if t.cfsr & 0x00000400 ~= 0 then print(" IMPRECISERR 不精确总线错误(PC 是近似)") end
if t.cfsr & 0x00000800 ~= 0 then print(" STKERR 异常入栈出错") end
if t.cfsr & 0x00001000 ~= 0 then print(" UNSTKERR 异常出栈出错") end
if t.cfsr & 0x01000000 ~= 0 then print(" UNDEFINSTR 未定义指令") end
if t.cfsr & 0x02000000 ~= 0 then print(" INVSTATE 非法状态(LSB=0 的跳转)") end
if t.cfsr & 0x04000000 ~= 0 then print(" INVPC 非法 PC 装载") end
for i = 1, 24 do
print(string.format(" [SP+%02X] %08X", (i-1)*4, t.stack[i]))
end
end
|