Question
Stm32 Hard Fault - PC Address *.map matching
- March 25, 2025
- 2 replies
- 797 views
Hello,
Hard Fault Handler Code:
To capture the details of the Hard Fault, I’m using the following handler:
To capture the details of the Hard Fault, I’m using the following handler:
void HardFault_Handler(void)
{
__asm volatile
(
"TST lr, #4 \n"
"ITE EQ \n"
"MRSEQ r0, MSP \n"
"MRSNE r0, PSP \n"
"B hard_fault_handler_c \n"
);
}
void hard_fault_handler_c(unsigned int *hardfault_args)
{
unsigned int stacked_r0 = hardfault_args[0];
unsigned int stacked_r1 = hardfault_args[1];
unsigned int stacked_r2 = hardfault_args[2];
unsigned int stacked_r3 = hardfault_args[3];
unsigned int stacked_r12 = hardfault_args[4];
unsigned int stacked_lr = hardfault_args[5];
unsigned int stacked_pc = hardfault_args[6];
unsigned int stacked_psr = hardfault_args[7];
printf("\n[HardFault] Hata!\n");
printf("R0 = 0x%08X\n", stacked_r0);
printf("R1 = 0x%08X\n", stacked_r1);
printf("R2 = 0x%08X\n", stacked_r2);
printf("R3 = 0x%08X\n", stacked_r3);
printf("R12 = 0x%08X\n", stacked_r12);
printf("LR = 0x%08X\n", stacked_lr);
printf("PC = 0x%08X\n", stacked_pc);
printf("PSR = 0x%08X\n", stacked_psr);
while (1);
}
I'm getting hard fault in my STM32L4XX project. The output is:
[HardFault]!
R0 = 0x2000FFE8
R1 = 0x0000000A
R2 = 0x00000040
R3 = 0x00000002
R12 = 0x00000000
LR = 0x00000000
PC = 0x0800656F
PSR = 0x08000EEC
Problem: The PC address 0x0800656F shows where the error occurs. I checked the *.map file but couldn’t figure out which function it corresponds to. Where might I be going wrong? How can I match this address with the *.map file?
The *.map file is inside the zip
