How to handle STM32 hardware error HardFault_Handler

Publisher:SparklingEyesLatest update time:2018-12-01 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

       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.


Keywords:STM32 Reference address:How to handle STM32 hardware error HardFault_Handler

Previous article:ARM compiler extended keywords
Next article:STM32F407 study notes - Systick interrupt

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号