When using Keil to simulate an STM32 program, the program sometimes runs away. When the simulation is stopped, the program stops in the infinite while(1) loop in the HardFault_Handler function. This indicates that a hardware error has occurred in the STM32.
STM32 hardware errors may occur due to the following reasons:
(1) Array out-of-bounds operation;
(2) Memory overflow, out-of-bounds access;
(3) The stack overflows and the program runs away;
(4) Interrupt processing error;
In this case, you can locate the error code segment in the following two ways.
method 1:
1.1 Set a debugging breakpoint at while(1) in the hardware interrupt function HardFault_Handler. When the program reaches the breakpoint, click "STOP" to stop the simulation.
1.2 Click "View" - "Registers Window" in the Keil menu bar, and find the value of R14(LR) in the register view window. If R14(LR) = 0xFFFFFFE9, continue to check the value of MSP (main stack pointer). If R14(LR) = 0xFFFFFFFD, continue to check the value of PSP (process stack pointer). My program R14(LR) = 0xFFFFFF9, and I will take this as an example.
1.3 In the Keil menu bar, click "View" - "Memory Windows" - "Memory1", enter the value of MSP in the "Address" address column: 0x20001288, and then find the address in the corresponding line. The address is usually a 32-bit number starting with 0x08. In this example, the address is 0x08003CB9.
1.4 Click "View" - "Disassembly Window" in the Keil menu bar, right-click in the "Disassembly" window, and select "Show Disassembly at Address..." in the drop-down menu. Enter the address 0x08003CB9 in the address box of the pop-up box "Show Code at Adress" to search, and then the corresponding code will be found. The code here is the situation before entering the loop interrupt. Carefully check the relevant code in the nearby area to find out the specific cause of the error.
Method 2:
2.1 Set a debugging breakpoint at while(1) in the hardware interrupt function HardFault_Handler. When the program reaches the breakpoint, click "STOP" to stop the simulation.
2.2 In the Keil menu bar, click "View" - "Call Stack Window" to pop up the "Call Stack + Locals" dialog box. Then right-click in the dialog box and select "Show Caller Code", which will jump to the function before the error. Carefully check the function calls or array memory usage.
Previous article:ARM compiler extended keywords
Next article:STM32F407 study notes - Systick interrupt
- Popular Resources
- Popular amplifiers
- Learn ARM development(14)
- Learn ARM development(15)
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Using Ginkgo USB-ADC and heart rate sensor to implement a heart rate tester with Android APP source code
- EMI noise suppression in harsh environments
- Jump-start your new design with the TI motor control software development kit!
- PlanAhead14.7
- Is this a capacitor explosion or something else? It's out of warranty.
- Analog electronics elective test + DC and AC parameters
- Introduction to TI_DSP link command file (*.cmd)
- TI CC1310 sub1G SDK development unique identification number MAC address reading
- FPGA Implementation of ECT Image Reconstruction Algorithm
- Why does the AD21 shortcut key not work after modification?