Embedded – how to debug unexpected resets in STM32 devices?

I'm doing some development in C using stm32f107 chip, and sometimes when I call a specific function, the device starts to reset I don't have a debugger. My debugging is just plain text of a serial port

I used some other microcontrollers where I could access a register to see the reason for the reset, but I couldn't seem to find the equivalent of this device I know the hardware exception of Cortex-M3, but I don't know whether one of them is triggered, because when I am in these handlers, it seems that I can't send text (perhaps because my TX function is interrupted?)

So I decided to ask someone who has more experience than this device: what do you usually do when debugging these situations?

edit

One of the developers activated the wwdg watchdog and is resetting the hardware before getting my information from the fault handler This is a hard failure because the function is called with a pointer to the wrong location However, I will keep this problem and hope that someone will provide more details (or materials) to indicate the C code from the saved register, that is, hard fault (@dwelch idea)

Solution

Cortex m3 has excellent fault handling function, which can make your life easier In case of fault, it will automatically stack multiple registers, such as PC and LR, and the fault status register will tell you the address of bus fault, etc

You should implement a good fault handler (for example, hard fault handler, here: http://blog.frankvh.com/2011/12/07/cortex-m3-m4-hard-fault-handler/ )Print stack register and debug fault status register

You should use UART to print, just write your own simple custom version of printf for your fault handler to use, without relying on interrupts Write Bytes directly into UART TX data register and poll bytes

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>