HardFault_Handler

This commit is contained in:
2026-07-16 01:12:05 +08:00
parent abe5b0c5b9
commit f4a90b18a5
+9 -6
View File
@@ -157,9 +157,9 @@ void SVC_Handler_C(os_uintptr_t* svc_args){
// - reboot system
#define AUTO_REBOOT_ENABLE /* 允许自动重启 */
#define OUTPUT_FAULT_TO_CONSOLE_ENABLE /* 在调试终端输出运行时信息 */
#define RECOVER_FROM_FAULT_ENABLE /* 尝试从错误中继续运行 */
//#define AUTO_REBOOT_ENABLE /* 允许自动重启 */
//#define OUTPUT_FAULT_TO_CONSOLE_ENABLE /* 在调试终端输出运行时信息 */
//#define RECOVER_FROM_FAULT_ENABLE /* 尝试从错误中继续运行 */
#if defined(RECOVER_FROM_FAULT_ENABLE)
static void recover_from_task_fault(void){
@@ -184,6 +184,9 @@ void HardFault_Handler_C(ContextStateFrame_t* frame, uint32_t lr_value){
uint32_t bus_fault_address = SCB->BFAR;
uint32_t mem_manage_fault_address = SCB->MMFAR;
uint32_t cfsr = SCB->CFSR;
uint32_t hfsr = SCB->HFSR;
uint32_t dfsr = SCB->DFSR;
uint32_t afsr = SCB->AFSR;
#if defined(AUTO_REBOOT_ENABLE)
const uint32_t usage_fault_mask = 0xffff0000;
@@ -215,9 +218,9 @@ void HardFault_Handler_C(ContextStateFrame_t* frame, uint32_t lr_value){
printf(" PSR = %08"OS_PRIx"\n", frame->xpsr);
printf("- FSR/FAR:\n");
printf(" CFSR = %08"OS_PRIx"\n", cfsr);
printf(" HFSR = %08"OS_PRIx"\n", SCB->HFSR);
printf(" DFSR = %08"OS_PRIx"\n", SCB->DFSR);
printf(" AFSR = %08"OS_PRIx"\n", SCB->AFSR);
printf(" HFSR = %08"OS_PRIx"\n", hfsr);
printf(" DFSR = %08"OS_PRIx"\n", dfsr);
printf(" AFSR = %08"OS_PRIx"\n", afsr);
if(cfsr & 0x0080){
printf(" MMFAR = %08"OS_PRIx"\n", mem_manage_fault_address);
}