diff --git a/LICENSE b/LICENSE index 14b9746..d061e99 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ 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 a copy of this software and associated documentation files (the diff --git a/README.md b/README.md index 83052b3..4d575fb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 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 是什么 @@ -176,6 +176,44 @@ void cm_backtrace_fault(uint32_t fault_handler_lr, uint32_t fault_handler_sp) - 1、注释/删除其他文件中定义的 `HardFault_Handler` 函数,仅保留 cmb_fault.s 中的; - 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 许可 采用 MIT 开源协议,细节请阅读项目中的 LICENSE 文件内容。 diff --git a/cm_backtrace/cm_backtrace.c b/cm_backtrace/cm_backtrace.c index 05722c8..1bd2d8a 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-2017, Armink, + * Copyright (c) 2016-2019, Armink, * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -62,6 +62,7 @@ #endif enum { + PRINT_MAIN_STACK_CFG_ERROR, PRINT_FIRMWARE_INFO, PRINT_ASSERT_ON_THREAD, PRINT_ASSERT_ON_HANDLER, @@ -103,6 +104,7 @@ enum { static const char * const print_info[] = { #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_ASSERT_ON_THREAD] = "Assert on thread %s", [PRINT_ASSERT_ON_HANDLER] = "Assert on interrupt or bare metal(no OS) environment", @@ -141,6 +143,7 @@ static const char * const print_info[] = { [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_LANGUAGE_CHINESE) + [PRINT_MAIN_STACK_CFG_ERROR] = "޷ȡջϢջ", [PRINT_FIRMWARE_INFO] = "̼ƣ%sӲ汾ţ%s汾ţ%s", [PRINT_ASSERT_ON_THREAD] = "߳(%s)з", [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" #endif + if (main_stack_size == 0) { + cmb_println(print_info[PRINT_MAIN_STACK_CFG_ERROR]); + return; + } + init_ok = true; } diff --git a/cm_backtrace/cmb_def.h b/cm_backtrace/cmb_def.h index 197d62a..91aa4a2 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-2018, Armink, + * Copyright (c) 2016-2019, 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 "1.2.1" +#define CMB_SW_VERSION "1.3.0" #define CMB_CPU_ARM_CORTEX_M0 0 #define CMB_CPU_ARM_CORTEX_M3 1