如何调试 STM32 设备中的意外复位? [英] How do I debug unexpected resets in a STM32 device?

查看:21
本文介绍了如何调试 STM32 设备中的意外复位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 STM32F107 芯片在 C 语言中进行一些开发,并且在某些时候,当我调用特定函数时,设备开始重置.我没有调试器,我的调试只是通过串行端口的纯文本.

I'm doing some development in C with a STM32F107 chip and, at some point, the device began to reset when I call a specific function. I don't have a debugger and my debugging is just plain text over a serial port.

我使用了其他一些微控制器,在这些微控制器中我能够访问寄存器以查看重置的原因,但我似乎找不到该设备的等价物.我知道 Cortex-M3 的硬件异常,但我不知道其中一个是否被触发,因为当我在这些处理程序中时,我似乎无法通过 usart 发送文本(可能是因为我的 TX函数使用中断?).

I've used some other microcontrollers in which I was able to access a register to see the cause of the reset, but I can't seem to find an equivalent for this device. I'm aware of the hardware exceptions of the Cortex-M3, but I don't know if one of them is being triggered since I can't seem to send text over usart when I'm inside those handlers (maybe because my TX functions use interruptions?).

因此,我决定询问在此设备方面比我更有经验的人:通常如何调试此类情况?

So, I decided to ask people with more experience than I in this device: what is usually done to debug situations like these?

编辑

其中一位开发人员激活了 WWDG 看门狗,它正在重置硬件,然后我才能从故障处理程序中获取我的信息.这是一个硬故障,因为通过指向错误位置的指针调用函数.但是,我会保留这个问题,希望有人能提供更多详细信息(或有关它的材料),以便从保存在硬故障(@dwelch 想法)中的寄存器中指向 C 代码.

One of the developers activated the WWDG watchdog and it was reseting the hardware before I could get my info from the fault handlers. It was a Hard Fault due to calling a function by a pointer that was pointing to the wrong place. However, I will keep this question in the hope that someone will give more details (or material about it) for pointing back to C code from the registers saved in, lets say, a Hard Fault (@dwelch idea).

推荐答案

Cortex M3 具有出色的故障处理功能,让您的生活更轻松.遇到故障时,它会自动堆叠多个寄存器,例如 PC 和 LR,故障状态寄存器会告诉您诸如总线故障地址等信息.

The Cortex M3 has excellent fault handling features that will make your life easier. On hitting a fault, it automatically stacks several registers like PC and LR, and fault status registers will tell you things like address of bus fault, etc.

您应该实现一个好的故障处理程序(例如,这里的硬故障处理程序:http://blog.frankvh.com/2011/12/07/cortex-m3-m4-hard-fault-handler/) 打印出堆栈寄存器和调试故障状态寄存器.

You should implement a good fault handler (for example, the hard fault handler here: http://blog.frankvh.com/2011/12/07/cortex-m3-m4-hard-fault-handler/) to print out the stacked registers and debug fault status registers.

您应该使用 UART 进行打印,只需编写您自己的简单自定义版本的 printf,以便在不依赖于中断的故障处理程序中使用.只需将字节直接写入 uart Tx 数据寄存器并轮询字节是否完成.

You should use the UART for printing, just write your own simple custom version of printf for use from your fault handler that doesn't depend on interrupts. Just write bytes directly to uart Tx data register and poll for byte completion.

这篇关于如何调试 STM32 设备中的意外复位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆