Bladeren bron

【同步】至 1.3.0 最新版。

Signed-off-by: armink <armink.ztl@gmail.com>
armink 6 jaren geleden
bovenliggende
commit
caf235ac47
5 gewijzigde bestanden met toevoegingen van 54 en 8 verwijderingen
  1. 1 1
      LICENSE
  2. 39 1
      README.md
  3. 10 2
      cm_backtrace.c
  4. 1 1
      cmb_cfg.h
  5. 3 3
      cmb_def.h

+ 1 - 1
LICENSE

@@ -1,6 +1,6 @@
 The MIT License (MIT)
 The MIT License (MIT)
 
 
-Copyright (c) 2016-2018 Armink (armink.ztl@gmail.com)
+Copyright (c) 2016-2019 Armink (armink.ztl@gmail.com)
 
 
 Permission is hereby granted, free of charge, to any person obtaining
 Permission is hereby granted, free of charge, to any person obtaining
 a copy of this software and associated documentation files (the
 a copy of this software and associated documentation files (the

+ 39 - 1
README.md

@@ -1,6 +1,6 @@
 # CmBacktrace: ARM Cortex-M 系列 MCU 错误追踪库
 # CmBacktrace: ARM Cortex-M 系列 MCU 错误追踪库
 
 
-[![GitHub release](https://img.shields.io/github/release/armink/CmBacktrace.svg)](https://github.com/armink/CmBacktrace/releases/latest) [![GitHub commits](https://img.shields.io/github/commits-since/armink/CmBacktrace/1.2.0.svg)](https://github.com/armink/CmBacktrace/compare/1.0.0...master) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/armink/CmBacktrace/master/LICENSE)
+[![GitHub release](https://img.shields.io/github/release/armink/CmBacktrace.svg)](https://github.com/armink/CmBacktrace/releases/latest) [![GitHub commits](https://img.shields.io/github/commits-since/armink/CmBacktrace/1.3.0.svg)](https://github.com/armink/CmBacktrace/compare/1.0.0...master) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/armink/CmBacktrace/master/LICENSE)
 
 
 ## 0、CmBacktrace 是什么
 ## 0、CmBacktrace 是什么
 
 
@@ -176,6 +176,44 @@ void cm_backtrace_fault(uint32_t fault_handler_lr, uint32_t fault_handler_sp)
 - 1、注释/删除其他文件中定义的 `HardFault_Handler` 函数,仅保留 cmb_fault.s 中的;
 - 1、注释/删除其他文件中定义的 `HardFault_Handler` 函数,仅保留 cmb_fault.s 中的;
 - 2、将 cmb_fault.s 移除工程,手动添加 `cm_backtrace_fault` 函数至现有的故障处理函数,但需要注意的是,务必 **保证该函数数入参的准备性** ,否则可能会导致故障诊断功能及堆栈打印功能无法正常运行。所以如果是新手,不推荐第二种解决方法。
 - 2、将 cmb_fault.s 移除工程,手动添加 `cm_backtrace_fault` 函数至现有的故障处理函数,但需要注意的是,务必 **保证该函数数入参的准备性** ,否则可能会导致故障诊断功能及堆栈打印功能无法正常运行。所以如果是新手,不推荐第二种解决方法。
 
 
+#### 2.5.4 初始化时提示无法获取主栈(main stack)信息
+
+在 `cmd_def.h` 中有定义默认的主栈配置,大致如下:
+
+```c
+
+#if defined(__CC_ARM)
+    /* C stack block name, default is STACK */
+    #ifndef CMB_CSTACK_BLOCK_NAME
+    #define CMB_CSTACK_BLOCK_NAME          STACK
+    #endif
+    ...
+#elif defined(__ICCARM__)
+    /* C stack block name, default is 'CSTACK' */
+    #ifndef CMB_CSTACK_BLOCK_NAME
+    #define CMB_CSTACK_BLOCK_NAME          "CSTACK"
+    #endif
+    ...
+#elif defined(__GNUC__)
+    /* C stack block start address, defined on linker script file, default is _sstack */
+    #ifndef CMB_CSTACK_BLOCK_START
+    #define CMB_CSTACK_BLOCK_START         _sstack
+    #endif
+    /* C stack block end address, defined on linker script file, default is _estack */
+    #ifndef CMB_CSTACK_BLOCK_END
+    #define CMB_CSTACK_BLOCK_END           _estack
+    #endif
+    ...
+#else
+```
+
+比如在 Keil-MDK 编译器下会默认选择 `STACK` 作为主栈 block 的名称,但在一些特殊平台下,项目的主栈 block 名称可能不叫 `STACK`,导致 CmBacktrace 无法获取到正确的主栈信息,所以在初始化时会有如上的错误提示信息。
+
+解决这个问题一般有两个思路
+
+- 1、在 `cmb_cfg.h` 中重新定义主栈的信息,此时 CmBacktrace 会优先使用 `cmb_cfg.h` 中的配置信息;
+- 2、修改项目配置,如果是 Keil-MDK ,则在启动文件的开头位置,将主栈的名称修改为默认的 `STACK` ,其他编译器一般很少出现该问题。
+
 ### 2.6 许可
 ### 2.6 许可
 
 
 采用 MIT 开源协议,细节请阅读项目中的 LICENSE 文件内容。
 采用 MIT 开源协议,细节请阅读项目中的 LICENSE 文件内容。

+ 10 - 2
cm_backtrace.c

@@ -1,7 +1,7 @@
 /*
 /*
  * This file is part of the CmBacktrace Library.
  * This file is part of the CmBacktrace Library.
  *
  *
- * Copyright (c) 2016-2017, Armink, <armink.ztl@gmail.com>
+ * Copyright (c) 2016-2019, Armink, <armink.ztl@gmail.com>
  *
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files (the
  * a copy of this software and associated documentation files (the
@@ -62,6 +62,7 @@
 #endif
 #endif
 
 
 enum {
 enum {
+    PRINT_MAIN_STACK_CFG_ERROR,
     PRINT_FIRMWARE_INFO,
     PRINT_FIRMWARE_INFO,
     PRINT_ASSERT_ON_THREAD,
     PRINT_ASSERT_ON_THREAD,
     PRINT_ASSERT_ON_HANDLER,
     PRINT_ASSERT_ON_HANDLER,
@@ -103,6 +104,7 @@ enum {
 
 
 static const char * const print_info[] = {
 static const char * const print_info[] = {
 #if (CMB_PRINT_LANGUAGE == CMB_PRINT_LANGUAGE_ENGLISH)
 #if (CMB_PRINT_LANGUAGE == CMB_PRINT_LANGUAGE_ENGLISH)
+        [PRINT_MAIN_STACK_CFG_ERROR]  = "ERROR: Unable to get the main stack information, please check the configuration of the main stack",
         [PRINT_FIRMWARE_INFO]         = "Firmware name: %s, hardware version: %s, software version: %s",
         [PRINT_FIRMWARE_INFO]         = "Firmware name: %s, hardware version: %s, software version: %s",
         [PRINT_ASSERT_ON_THREAD]      = "Assert on thread %s",
         [PRINT_ASSERT_ON_THREAD]      = "Assert on thread %s",
         [PRINT_ASSERT_ON_HANDLER]     = "Assert on interrupt or bare metal(no OS) environment",
         [PRINT_ASSERT_ON_HANDLER]     = "Assert on interrupt or bare metal(no OS) environment",
@@ -140,7 +142,8 @@ static const char * const print_info[] = {
         [PRINT_DFSR_EXTERNAL]         = "Debug fault is caused by EDBGRQ signal asserted",
         [PRINT_DFSR_EXTERNAL]         = "Debug fault is caused by EDBGRQ signal asserted",
         [PRINT_MMAR]                  = "The memory management fault occurred address is %08x",
         [PRINT_MMAR]                  = "The memory management fault occurred address is %08x",
         [PRINT_BFAR]                  = "The bus fault occurred address is %08x",
         [PRINT_BFAR]                  = "The bus fault occurred address is %08x",
-#elif (CMB_PRINT_LANGUAGE == CMB_PRINT_LANUUAGE_CHINESE)
+#elif (CMB_PRINT_LANGUAGE == CMB_PRINT_LANGUAGE_CHINESE)
+        [PRINT_MAIN_STACK_CFG_ERROR]  = "错误:无法获取主栈信息,请检查主栈的相关配置",
         [PRINT_FIRMWARE_INFO]         = "固件名称:%s,硬件版本号:%s,软件版本号:%s",
         [PRINT_FIRMWARE_INFO]         = "固件名称:%s,硬件版本号:%s,软件版本号:%s",
         [PRINT_ASSERT_ON_THREAD]      = "在线程(%s)中发生断言",
         [PRINT_ASSERT_ON_THREAD]      = "在线程(%s)中发生断言",
         [PRINT_ASSERT_ON_HANDLER]     = "在中断或裸机环境下发生断言",
         [PRINT_ASSERT_ON_HANDLER]     = "在中断或裸机环境下发生断言",
@@ -229,6 +232,11 @@ void cm_backtrace_init(const char *firmware_name, const char *hardware_ver, cons
     #error "not supported compiler"
     #error "not supported compiler"
 #endif
 #endif
 
 
+    if (main_stack_size == 0) {
+        cmb_println(print_info[PRINT_MAIN_STACK_CFG_ERROR]);
+        return;
+    }
+
     init_ok = true;
     init_ok = true;
 }
 }
 
 

+ 1 - 1
cmb_cfg.h

@@ -63,6 +63,6 @@
 #if defined(PKG_CMBACKTRACE_PRINT_ENGLISH)
 #if defined(PKG_CMBACKTRACE_PRINT_ENGLISH)
     #define CMB_PRINT_LANGUAGE         CMB_PRINT_LANGUAGE_ENGLISH
     #define CMB_PRINT_LANGUAGE         CMB_PRINT_LANGUAGE_ENGLISH
 #elif defined(PKG_CMBACKTRACE_PRINT_CHINESE)
 #elif defined(PKG_CMBACKTRACE_PRINT_CHINESE)
-    #define CMB_PRINT_LANGUAGE         CMB_PRINT_LANUUAGE_CHINESE
+    #define CMB_PRINT_LANGUAGE         CMB_PRINT_LANGUAGE_ENGLISH
 #endif /* PKG_CMBACKTRACE_PRINT_ENGLISH */
 #endif /* PKG_CMBACKTRACE_PRINT_ENGLISH */
 #endif /* _CMB_CFG_H_ */
 #endif /* _CMB_CFG_H_ */

+ 3 - 3
cmb_def.h

@@ -1,7 +1,7 @@
 /*
 /*
  * This file is part of the CmBacktrace Library.
  * This file is part of the CmBacktrace Library.
  *
  *
- * Copyright (c) 2016-2018, Armink, <armink.ztl@gmail.com>
+ * Copyright (c) 2016-2019, Armink, <armink.ztl@gmail.com>
  *
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files (the
  * a copy of this software and associated documentation files (the
@@ -34,7 +34,7 @@
 #include <stdlib.h>
 #include <stdlib.h>
 
 
 /* library software version number */
 /* library software version number */
-#define CMB_SW_VERSION                "1.2.1"
+#define CMB_SW_VERSION                "1.3.0"
 
 
 #define CMB_CPU_ARM_CORTEX_M0          0
 #define CMB_CPU_ARM_CORTEX_M0          0
 #define CMB_CPU_ARM_CORTEX_M3          1
 #define CMB_CPU_ARM_CORTEX_M3          1
@@ -47,7 +47,7 @@
 #define CMB_OS_PLATFORM_FREERTOS       3
 #define CMB_OS_PLATFORM_FREERTOS       3
 
 
 #define CMB_PRINT_LANGUAGE_ENGLISH     0
 #define CMB_PRINT_LANGUAGE_ENGLISH     0
-#define CMB_PRINT_LANUUAGE_CHINESE     1
+#define CMB_PRINT_LANGUAGE_CHINESE     1
 
 
 /* name max length, default size: 32 */
 /* name max length, default size: 32 */
 #ifndef CMB_NAME_MAX
 #ifndef CMB_NAME_MAX