From f773a04522fd463889cb5d8baa7b7ae8fb4f1b8c Mon Sep 17 00:00:00 2001 From: armink Date: Fri, 17 Feb 2017 16:35:23 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E3=80=90=E5=A2=9E=E5=8A=A0=E3=80=91?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E5=99=A8=E7=AE=A1=E7=90=86=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=8F=8A=E6=80=BB=E7=BA=BF=E9=94=99=E8=AF=AF=E5=85=B7=E4=BD=93?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E7=9A=84=E4=BF=A1=E6=81=AF=E8=BE=93=E5=87=BA?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: armink --- LICENSE | 2 +- cm_backtrace/cm_backtrace.c | 18 +++++++++++++++--- cm_backtrace/cmb_def.h | 10 ++++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/LICENSE b/LICENSE index 6b761d3..f956e16 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 Armink (armink.ztl@gmail.com) +Copyright (c) 2016-2017 Armink (armink.ztl@gmail.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/cm_backtrace/cm_backtrace.c b/cm_backtrace/cm_backtrace.c index e94cd06..5e83a76 100644 --- a/cm_backtrace/cm_backtrace.c +++ b/cm_backtrace/cm_backtrace.c @@ -1,7 +1,7 @@ /* * This file is part of the CmBacktrace Library. * - * Copyright (c) 2016, Armink, + * Copyright (c) 2016-2017, Armink, * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -118,6 +118,8 @@ enum { PRINT_DFSR_DWTTRAP, PRINT_DFSR_VCATCH, PRINT_DFSR_EXTERNAL, + PRINT_MMAR, + PRINT_BFAR, }; static const char *print_info[] = { @@ -155,6 +157,8 @@ static const char *print_info[] = { [PRINT_DFSR_DWTTRAP] = "Debug fault is caused by DWT match occurred", [PRINT_DFSR_VCATCH] = "Debug fault is caused by Vector fetch occurred", [PRINT_DFSR_EXTERNAL] = "Debug fault is caused by EDBGRQ signal asserted", + [PRINT_MMAR] = "The memory management fault occurred address is %08x", + [PRINT_BFAR] = "The bus fault occurred address is %08x", #elif (CMB_PRINT_LANGUAGE == CMB_PRINT_LANUUAGE_CHINESE) [PRINT_FIRMWARE_INFO] = "固件名称:%s,硬件版本号:%s,软件版本号:%s", [PRINT_ASSERT_ON_THREAD] = "在线程(%s)中发生断言", @@ -189,6 +193,8 @@ static const char *print_info[] = { [PRINT_DFSR_DWTTRAP] = "发生调试错误,原因:数据监测点匹配", [PRINT_DFSR_VCATCH] = "发生调试错误,原因:发生向量捕获", [PRINT_DFSR_EXTERNAL] = "发生调试错误,原因:外部调试请求", + [PRINT_MMAR] = "发生存储器管理错误的地址:%08x", + [PRINT_BFAR] = "发生总线错误的地址:%08x", #else #error "CMB_PRINT_LANGUAGE defined error in 'cmb_cfg.h'" #endif @@ -497,7 +503,9 @@ static void fault_diagnosis(void) { #endif if (regs.mfsr.bits.MMARVALID) { - //TODO + if (regs.mfsr.bits.IACCVIOL || regs.mfsr.bits.DACCVIOL) { + cmb_println(print_info[PRINT_MMAR], regs.mmar); + } } } /* Bus Fault */ @@ -525,8 +533,11 @@ static void fault_diagnosis(void) { #endif if (regs.bfsr.bits.BFARVALID) { - //TODO + if (regs.bfsr.bits.PRECISERR) { + cmb_println(print_info[PRINT_BFAR], regs.bfar); + } } + } /* Usage Fault */ if (regs.ufsr.value) { @@ -674,6 +685,7 @@ void cm_backtrace_fault(uint32_t fault_handler_lr, uint32_t fault_handler_sp) { #if (CMB_CPU_PLATFORM_TYPE != CMB_CPU_ARM_CORTEX_M0) regs.syshndctrl.value = CMB_SYSHND_CTRL; // System Handler Control and State Register regs.mfsr.value = CMB_NVIC_MFSR; // Memory Fault Status Register + regs.mmar = CMB_NVIC_MMAR; // Memory Management Fault Address Register regs.bfsr.value = CMB_NVIC_BFSR; // Bus Fault Status Register regs.bfar = CMB_NVIC_BFAR; // Bus Fault Manage Address Register regs.ufsr.value = CMB_NVIC_UFSR; // Usage Fault Status Register diff --git a/cm_backtrace/cmb_def.h b/cm_backtrace/cmb_def.h index c74bff8..d06c208 100644 --- a/cm_backtrace/cmb_def.h +++ b/cm_backtrace/cmb_def.h @@ -1,7 +1,7 @@ /* * This file is part of the CmBacktrace Library. * - * Copyright (c) 2016, Armink, + * Copyright (c) 2016-2017, Armink, * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -34,7 +34,7 @@ #include /* library software version number */ -#define CMB_SW_VERSION "0.1.1" +#define CMB_SW_VERSION "0.1.2" #define CMB_CPU_ARM_CORTEX_M0 0 #define CMB_CPU_ARM_CORTEX_M3 1 @@ -134,6 +134,11 @@ #define CMB_NVIC_DFSR (*(volatile unsigned short*)(0xE000ED30u)) #endif +/* memory management fault address register */ +#ifndef CMB_NVIC_MMAR +#define CMB_NVIC_MMAR (*(volatile unsigned int*) (0xE000ED34u)) +#endif + /* bus fault manage address register */ #ifndef CMB_NVIC_BFAR #define CMB_NVIC_BFAR (*(volatile unsigned int*) (0xE000ED38u)) @@ -202,6 +207,7 @@ struct cmb_hard_fault_regs{ unsigned char MMARVALID : 1; // Indicates the MMAR is valid } bits; } mfsr; // Memory Management Fault Status Register (0xE000ED28) + unsigned int mmar; // Memory Management Fault Address Register (0xE000ED34) union { unsigned char value;