1、测试环境:MDK + STM32F407
2、汇编重写 HardFault_Handler 中断
/* 硬件错误中断的回调 */ void HardFault_CallBack_MSP(void) { unsigned int MSP = __get_MSP(); unsigned int nextPoint1 = *((unsigned int*)MSP + 5); unsigned int nextPoint2 = *((unsigned int*)MSP + 6); unsigned int nextPoint3 = *((unsigned int*)MSP + 7); while (1) { static unsigned int i = 0; printf("<%s>[%d] MSP = 0x%.8X, nextPoint = 0x%.8X / 0x%.8X / 0x%.8X\r\n", __func__, ++i, MSP, nextPoint1, nextPoint2, nextPoint3); for (int j = 0; j < 100000000; j++); } } /* 硬件错误中断的回调 */ void HardFault_CallBack_PSP(void) { unsigned int PSP = __get_PSP(); unsigned int nextPoint1 = *((unsigned int*)PSP + 5); unsigned int nextPoint2 = *((unsigned int*)PSP + 6); unsigned int nextPoint3 = *((unsigned int*)PSP + 7); while (1) { static unsigned int i = 0; printf("<%s>[%d] PSP = 0x%.8X, nextPoint = 0x%.8X / 0x%.8X / 0x%.8X\r\n", __func__, ++i, PSP, nextPoint1, nextPoint2, nextPoint3); for (int j = 0; j < 100000000; j++); } } /** * @brief This function handles Hard fault interrupt. */ __asm void HardFault_Handler(void) { extern HardFault_CallBack_MSP extern HardFault_CallBack_PSP /* lr = 0xFFFFFFF9 跳转 HardFault_CallBack_MSP */ CMP lr, #0xFFFFFFF9 BLEQ HardFault_CallBack_MSP /* lr = 0xFFFFFFFD 跳转 HardFault_CallBack_PSP */ CMP lr, #0xFFFFFFFD BLEQ HardFault_CallBack_PSP }标签:HardFault,int,unsigned,MSP,Handler,STM32F407,PSP,0x% From: https://www.cnblogs.com/yangjinghui/p/17051877.html