GCC HardFault_Handler 输出栈内所有信息
时间: 2023-12-31 18:22:48 浏览: 221
输出N个元素的所有出栈可能
以下是GCC HardFault_Handler 输出栈内所有信息的示例代码:
```c
void print_stack_frame(unsigned int *stack_frame) {
printf("r0 = 0x%08X\n", stack_frame[0]);
printf("r1 = 0x%08X\n", stack_frame[1]);
printf("r2 = 0x%08X\n", stack_frame[2]);
printf("r3 = 0x%08X\n", stack_frame[3]);
printf("r12 = 0x%08X\n", stack_frame[4]);
printf("lr = 0x%08X\n", stack_frame[5]);
printf("pc = 0x%08X\n", stack_frame[6]);
printf("psr = 0x%08X\n", stack_frame[7]);
}
void HardFault_Handler(void) {
printf("Hard Fault\n");
printf("SCB->HFSR = 0x%08X\n", SCB->HFSR);
printf("SCB->CFSR = 0x%08X\n", SCB->CFSR);
printf("SCB->DFSR = 0x%08X\n", SCB->DFSR);
printf("SCB->AFSR = 0x%08X\n", SCB->AFSR);
printf("SCB->BFAR = 0x%08X\n", SCB->BFAR);
printf("SCB->MMFAR = 0x%08X\n", SCB->MMFAR);
unsigned int *stack_frame = (unsigned int *)__get_MSP();
printf("Stack frame:\n");
print_stack_frame(stack_frame);
while (1);
}
```
该代码中,`HardFault_Handler` 函数是一个中断处理函数,用于处理硬件故障中断。在该函数中,我们首先打印出一些硬件故障的信息,例如 `SCB->HFSR`、`SCB->CFSR` 等。然后,我们通过 `__get_MSP()` 函数获取当前栈指针的地址,并将其转换为 `unsigned int *` 类型的指针。最后,我们调用 `print_stack_frame` 函数,将栈帧中的寄存器值打印出来。
阅读全文