Debugging_Controller_stucking
Debugging_Controller_stucking
1. **Problem Identification**:
- You initially reported that your STM32 controller was stuck inside a routine, and the UART
- Debugging in Keil resulted in different execution behavior, making it harder to trace the problem
directly.
- **PC Register**: Program Counter (`0x080002C8`) was inspected and traced to corresponding
- **Call Stack**: Registers and the memory pointed to by the Stack Pointer (SP) and Link Register
- **Disassembly Analysis**:
- **Fault Registers**: Fault-related registers like HFSR, CFSR, MMFAR, and BFAR were manually
- CFSR (`0xE000ED28`) pointed to a stacking error (`STKERR`), likely caused by invalid stack
pointer usage.
pointer corruption.
4. **Memory Inspections**:
- **Function Pointers**:
- `r0` was traced to `0x080002F4`, and the address (`0x080001AD`) was inspected.
- **Invalid Branch**:
- Memory at `0x080001AC` contained a valid `BL.W` instruction, but subsequent code execution
- At `0xF8ED00E0`, data was observed instead of valid code, confirming a corrupted memory
pointer.
branch.
- **Invalid Memory Access**: Misaligned or invalid memory being accessed during function calls or
interrupt handling.
6. **Fix Recommendations**:
```c
SCB_SHCSR_USGFAULTENA_Msk;
```
- Add a custom Hard Fault handler to capture faulting addresses and stack states:
```c
void HardFault_Handler(void) {
```
7. **Testing Recommendations**:
- Use hardware breakpoints and stack monitoring to catch stack overflows early.
- Validate all pointer arithmetic and ensure memory addresses are within valid ranges.
8. **Final Notes**:
- The steps provided aim to systematically identify and resolve the issue, ensuring a robust and
fault-free program.
This detailed document includes all interactions and insights shared during the debugging process.