Follow+Star Public Account, don’t miss the exciting content
Author | strongerHuang
WeChat Public Account | strongerHuang
Many friends encounter the HardFault_Handler situation while learning or developing STM32.
1Cortex-M3 Exceptions
Speaking of Fault, we must mention the exceptions of Cortex-M3.
List of CM3 exceptions:
Vector Table
2Fault Error Exceptions
InCortex-M3, there are several types of Fault error exceptions:
-
BusFault
-
MemManageFault
-
UsageFault
-
HardFault
-
Instruction fetch, commonly referred to as “prefetch abort” -
Data read/write, commonly referred to as “data abort”
-
PUSH action on the stack at the start of interrupt handling, known as “stack entry error” -
POP action on the stack at the end of interrupt handling, known as “stack exit error” -
Reading the vector after the processor starts the interrupt handling sequence. This is a rare special case classified as a hard error.
-
Attempting to access an invalid memory region. Common when accessing an address with no corresponding memory. -
The device is not ready to transfer data. For example, attempting to access SDRAM before initializing the SDRAM controller. -
When attempting to initiate a data transfer, the size of the transfer is not supported by the target device. For example, a device only accepts word-sized data but is attempted to be sent byte-sized data. -
For some reason, the device cannot accept data transfer. For example, some devices only allow access at privileged levels, but the current level is user level.
-
Accessed an address outside the range set by the MPU -
Wrote data to a read-only region -
Accessed an address that is only allowed at privileged levels while in user level
-
Executed an undefined instruction -
Executed co-processor instructions (Cortex-M3 does not support co-processors, but can use the fault exception mechanism to simulate co-processor functionality, making it easier to port between other Cortex processors) -
Attempted to enter ARM state (since CM3 does not support ARM state, usage faults will occur during the switch. Software can use this mechanism to test whether a processor supports ARM state) -
Invalid interrupt return (LR contains an invalid/error value) -
When using multiple load/store instructions, the address is misaligned. Additionally, by setting the corresponding control bits of the NVIC, usage faults can also occur in the following situations: -
Division by zero -
Any unaligned access
Status Register (HFSR):
3How to Respond to Fault Error Exceptions
During software development, we can determine program errors based on the values of various fault status registers and correct them. Below are common causes of various faults and response strategies.
MemManage fault status register provides information:
Bus fault status register provides information:
Usage fault status register provides information:
Hard fault status register provides information:
Reply to the background with 『STM32』『Cortex-M3』 to read more related articles.
Welcome to follow my public account, reply “Join Group” to join the technical exchange group as per the rules, reply “1024” to see more content.
Click “Read Original” to see more shares.