Advanced Hard Fault Debugging Interview
Questions (Embedded C + ARM +
AUTOSAR)
Hard Fault debugging is one of the most important skills in embedded interviews,
especially for:
• Automotive ECU
• AUTOSAR
• STM32
• NXP S32K
• RTOS-based systems
Interviewers check:
➢ Debugging approach
➢ Memory understanding
➢ ARM Cortex-M knowledge
➢ Stack analysis
➢ Real-time thinking
1. What is Hard Fault?
Answer:
Hard Fault is an exception generated when CPU detects a critical error such as:
• Invalid memory access
• Divide by zero
• Undefined instruction
• Stack corruption
2. Common Causes of Hard Fault
Cause Example
NULL pointer *ptr = 10
Stack overflow Large local array
Invalid address Wrong pointer
Divide by zero x/0
Corrupted stack ISR issue
Unaligned Wrong casting
access
3. Interview Scenario – NULL Pointer
Logs
[INFO] ECU Started
[DEBUG] CAN Task Running
[ERROR] Hard Fault Triggered
Code
uint8_t *ptr = NULL;
*ptr = 10;
Interview Question
How do you debug this?
Best Answer
1. Check fault registers
2. Verify PC/LR
3. Analyze call stack
4. Identify invalid pointer access
5. Add pointer validation
4. What registers are checked during Hard
Fault?
Important Registers
• PC → Program Counter
• LR → Link Register
• SP → Stack Pointer
• xPSR → Processor status
5. What is Bus Fault?
Answer:
Occurs when CPU cannot access memory correctly.
Example:
*(volatile uint32_t*)0xFFFFFFFF = 1;
6. What is Usage Fault?
Causes:
• Divide by zero
• Undefined instruction
• Invalid state
7. Divide-by-zero Scenario
int x = 10;
int y = 0;
int z = x / y;
How debug?
• Enable divide-by-zero trap
• Check operands before division
8. Stack Overflow Hard Fault
Code
void func()
{
uint8_t bigArray[10000];
}
Symptoms
• Random reset
• Hard fault
• Watchdog reset
Debug Approach
1. Check stack size
2. Analyze map file
3. Enable stack monitoring
9. Recursive Function Crash
void fun()
{
fun();
}
Root Cause?
Infinite recursion → stack overflow
10. Unaligned Memory Access
uint32_t *ptr = (uint32_t*)0x20000001;
Problem
Address not 4-byte aligned
11. How to capture Hard Fault
information?
Example
void HardFault_Handler(void)
{
while(1);
}
Better Debugging
Store:
• PC
• LR
• Stack frame
• Fault status registers
12. Fault Status Registers
Register Purpose
CFSR Configurable Fault
Status
HFSR Hard Fault Status
MMFAR Memory Fault Address
BFAR Bus Fault Address
13. Real Interview Scenario
Logs
[INFO] Sensor Task Started
[DEBUG] Reading ADC
[ERROR] Hard Fault at 0x08001234
What do you do first?
Best Answer
1. Check PC address
2. Match with map file
3. Identify function
4. Trace pointer usage
14. What is stack corruption?
Answer:
Stack data overwritten accidentally.
Causes
• Buffer overflow
• Wrong pointer access
• ISR misuse
15. Buffer Overflow Scenario
char buf[5];
strcpy(buf, "HELLOWORLD");
Result
Memory corruption → Hard fault later
16. Why hard faults sometimes occur
later?
Answer:
Memory corruption may happen earlier but crash occurs later when corrupted memory is
accessed.
17. How to debug random hard faults?
Best Approach
1. Enable fault handlers
2. Store crash logs
3. Trace last executed task
4. Check stack usage
5. Review pointer operations
18. RTOS Hard Fault Scenario
Problem
Task switching causes crash.
Possible Causes
• Stack overflow
• Invalid task stack
• Context corruption
19. ISR-Related Hard Fault
Example
void ISR()
{
largeFunction();
}
Problem
ISR stack overflow or timing issue
20. Why local large arrays dangerous?
Example
void task()
{
uint8_t temp[5000];
}
Problem
Consumes stack memory rapidly
AUTOSAR Hard Fault Questions
21. Hard fault after RTE call. Why?
Possible Causes
• Invalid pointer
• Uninitialized port
• Wrong configuration
22. Hard fault after CAN interrupt
Causes
• ISR corruption
• Shared buffer issue
• Stack overflow
23. Hard fault during startup
Possible Causes
• Clock issue
• Wrong linker config
• Invalid memory init
24. Hard Fault During Bootloader Jump
Common Issue
Wrong vector table setup
25. How verify stack overflow in RTOS?
Methods
• Watermark checking
• Stack pattern filling
• RTOS APIs
26. What is MPU role in debugging?
✅ Answer
Detects invalid memory access.
27. Why volatile important in debugging?
Example
volatile uint8_t flag;
Without volatile:
• Compiler optimization causes unexpected behavior
28. Interview Trap
Code
char *ptr;
strcpy(ptr, "ABC");
Problem
Uninitialized pointer
29. Hard Fault after memcpy
Causes
• Invalid destination
• Size overflow
• Overlapping memory
30. memcpy vs memmove interview trap
memcpy memmove
No overlap Safe for overlap
handling
31. Scenario – Fault after 5 hours only
Expected Thinking
• Memory leak
• Fragmentation
• Stack growth
• Race condition
32. Race Condition Crash
Example
shared++;
Non-atomic access can corrupt memory.
33. How use map file in debugging?
Purpose
Find:
• Memory usage
• Function address
• Stack size
34. Hard fault due to linker issue
Cause
Sections overlapping in memory.
35. Fault after enabling optimization
Causes
• Missing volatile
• Timing issue
• Undefined behavior
36. Why undefined behavior dangerous?
Because:
Compiler behavior becomes unpredictable.
37. Hard fault in DMA application
Causes
• Invalid buffer
• Alignment issue
• Cache coherency
38. What is precise vs imprecise fault?
Precise Imprecise
Exact instruction Delayed
known detection
39. Fault only in Release build
Causes
• Optimization issue
• Timing issue
• Uninitialized variable
40. BEST HARD FAULT DEBUGGING
STRATEGY
Gold Interview Answer
1. Capture logs/registers
2. Check PC/LR/SP
3. Analyze stack
4. Verify pointers
5. Check memory boundaries
6. Analyze recent code changes
7. Reproduce issue
8. Validate fix