硬汉嵌入式论坛

 找回密码
 立即注册
搜索
查看: 40|回复: 0
收起左侧

[Lua] H7-TOOL的LUA新增了个本体的硬件异常日志记录功能,如果本身出现异常复位会记录现场信息,方便升级修改(2026-11-22)

[复制链接]

1万

主题

7万

回帖

12万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
124619
QQ
发表于 6 小时前 | 显示全部楼层 |阅读模式



如果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




回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2026-11-22 22:24 , Processed in 0.127555 second(s), 24 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表