1、【增加】GCC 编译器的支持。

Signed-off-by: armink <armink.ztl@gmail.com>
pull/1/head
armink 9 years ago
parent 19bc9c03a6
commit 62cef99707

@ -31,6 +31,33 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
/* include or export for supported __get_MSP, __get_PSP function */
#if defined(__CC_ARM)
static __inline __asm uint32_t __get_MSP(void) {
mrs r0, msp
bx lr
}
static __inline __asm uint32_t __get_PSP(void) {
mrs r0, psp
bx lr
}
#elif defined(__ICCARM__)
#include <intrinsics.h>
#elif defined(__GNUC__)
__attribute__( ( always_inline ) ) static inline uint32_t __get_MSP(void) {
register uint32_t result;
__asm volatile ("MRS %0, msp\n" : "=r" (result) );
return(result);
}
__attribute__( ( always_inline ) ) static inline uint32_t __get_PSP(void) {
register uint32_t result;
__asm volatile ("MRS %0, psp\n" : "=r" (result) );
return(result);
}
#else
#error "not supported compiler"
#endif
#if defined(__CC_ARM) #if defined(__CC_ARM)
#define SECTION_START(_name_) _name_##$$Base #define SECTION_START(_name_) _name_##$$Base
#define SECTION_END(_name_) _name_##$$Limit #define SECTION_END(_name_) _name_##$$Limit
@ -41,18 +68,20 @@
#define CODE_SECTION_START(_name_) IMAGE_SECTION_START(_name_) #define CODE_SECTION_START(_name_) IMAGE_SECTION_START(_name_)
#define CODE_SECTION_END(_name_) IMAGE_SECTION_END(_name_) #define CODE_SECTION_END(_name_) IMAGE_SECTION_END(_name_)
extern const int CODE_SECTION_START(CMB_CODE_SECTION_NAME);
extern const int CODE_SECTION_END(CMB_CODE_SECTION_NAME);
extern const int CSTACK_BLOCK_START(CMB_CSTACK_BLOCK_NAME); extern const int CSTACK_BLOCK_START(CMB_CSTACK_BLOCK_NAME);
extern const int CSTACK_BLOCK_END(CMB_CSTACK_BLOCK_NAME); extern const int CSTACK_BLOCK_END(CMB_CSTACK_BLOCK_NAME);
extern const int CODE_SECTION_START(CMB_CODE_SECTION_NAME);
extern const int CODE_SECTION_END(CMB_CODE_SECTION_NAME);
#elif defined(__ICCARM__) #elif defined(__ICCARM__)
#pragma section=CMB_CSTACK_BLOCK_NAME #pragma section=CMB_CSTACK_BLOCK_NAME
#pragma section=CMB_CODE_SECTION_NAME #pragma section=CMB_CODE_SECTION_NAME
#elif defined(__GNUC__) #elif defined(__GNUC__)
#error "not implemented, I hope you can do this" extern const int CMB_CSTACK_BLOCK_START;
//TODO 待实现 extern const int CMB_CSTACK_BLOCK_END;
extern const int CMB_CODE_SECTION_START;
extern const int CMB_CODE_SECTION_END;
#else #else
#error "not supported compiler" #error "not supported compiler"
#endif #endif
enum { enum {
@ -93,73 +122,73 @@ enum {
static const char *print_info[] = { static const char *print_info[] = {
#if (CMB_PRINT_LANGUAGE == CMB_PRINT_LANGUAGE_ENGLISH) #if (CMB_PRINT_LANGUAGE == CMB_PRINT_LANGUAGE_ENGLISH)
[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",
[PRINT_THREAD_STACK_INFO] = {"===== Thread stack information ====="}, [PRINT_THREAD_STACK_INFO] = "===== Thread stack information =====",
[PRINT_MAIN_STACK_INFO] = {"====== Main stack information ======"}, [PRINT_MAIN_STACK_INFO] = "====== Main stack information ======",
[PRINT_CALL_STACK_INFO] = {"Show more call stack info by run: addr2line -e %s%s -a -f %.*s"}, [PRINT_CALL_STACK_INFO] = "Show more call stack info by run: addr2line -e %s%s -a -f %.*s",
[PRINT_CALL_STACK_ERR] = {"Dump call stack has an error"}, [PRINT_CALL_STACK_ERR] = "Dump call stack has an error",
[PRINT_FAULT_ON_THREAD] = {"Fault on thread %s"}, [PRINT_FAULT_ON_THREAD] = "Fault on thread %s",
[PRINT_FAULT_ON_HANDLER] = {"Fault on interrupt or bare metal(no OS) environment"}, [PRINT_FAULT_ON_HANDLER] = "Fault on interrupt or bare metal(no OS) environment",
[PRINT_REGS_TITLE] = {"=================== Registers information ===================="}, [PRINT_REGS_TITLE] = "=================== Registers information ====================",
[PRINT_HFSR_VECTBL] = {"Hard fault is caused by failed vector fetch"}, [PRINT_HFSR_VECTBL] = "Hard fault is caused by failed vector fetch",
[PRINT_MFSR_IACCVIOL] = {"Memory management fault is caused by instruction access violation"}, [PRINT_MFSR_IACCVIOL] = "Memory management fault is caused by instruction access violation",
[PRINT_MFSR_DACCVIOL] = {"Memory management fault is caused by data access violation"}, [PRINT_MFSR_DACCVIOL] = "Memory management fault is caused by data access violation",
[PRINT_MFSR_MUNSTKERR] = {"Memory management fault is caused by unstacking error"}, [PRINT_MFSR_MUNSTKERR] = "Memory management fault is caused by unstacking error",
[PRINT_MFSR_MSTKERR] = {"Memory management fault is caused by stacking error"}, [PRINT_MFSR_MSTKERR] = "Memory management fault is caused by stacking error",
[PRINT_MFSR_MLSPERR] = {"Memory management fault is caused by floating-point lazy state preservation"}, [PRINT_MFSR_MLSPERR] = "Memory management fault is caused by floating-point lazy state preservation",
[PRINT_BFSR_IBUSERR] = {"Bus fault is caused by instruction access violation"}, [PRINT_BFSR_IBUSERR] = "Bus fault is caused by instruction access violation",
[PRINT_BFSR_PRECISERR] = {"Bus fault is caused by precise data access violation"}, [PRINT_BFSR_PRECISERR] = "Bus fault is caused by precise data access violation",
[PRINT_BFSR_IMPREISERR] = {"Bus fault is caused by imprecise data access violation"}, [PRINT_BFSR_IMPREISERR] = "Bus fault is caused by imprecise data access violation",
[PRINT_BFSR_UNSTKERR] = {"Bus fault is caused by unstacking error"}, [PRINT_BFSR_UNSTKERR] = "Bus fault is caused by unstacking error",
[PRINT_BFSR_STKERR] = {"Bus fault is caused by stacking error"}, [PRINT_BFSR_STKERR] = "Bus fault is caused by stacking error",
[PRINT_BFSR_LSPERR] = {"Bus fault is caused by floating-point lazy state preservation"}, [PRINT_BFSR_LSPERR] = "Bus fault is caused by floating-point lazy state preservation",
[PRINT_UFSR_UNDEFINSTR] = {"Usage fault is caused by attempts to execute an undefined instruction"}, [PRINT_UFSR_UNDEFINSTR] = "Usage fault is caused by attempts to execute an undefined instruction",
[PRINT_UFSR_INVSTATE] = {"Usage fault is caused by attempts to switch to an invalid state (e.g., ARM)"}, [PRINT_UFSR_INVSTATE] = "Usage fault is caused by attempts to switch to an invalid state (e.g., ARM)",
[PRINT_UFSR_INVPC] = {"Usage fault is caused by attempts to do an exception with a bad value in the EXC_RETURN number"}, [PRINT_UFSR_INVPC] = "Usage fault is caused by attempts to do an exception with a bad value in the EXC_RETURN number",
[PRINT_UFSR_NOCP] = {"Usage fault is caused by attempts to execute a coprocessor instruction"}, [PRINT_UFSR_NOCP] = "Usage fault is caused by attempts to execute a coprocessor instruction",
[PRINT_UFSR_UNALIGNED] = {"Usage fault is caused by indicates that an unaligned access fault has taken place"}, [PRINT_UFSR_UNALIGNED] = "Usage fault is caused by indicates that an unaligned access fault has taken place",
[PRINT_UFSR_DIVBYZERO] = {"Usage fault is caused by Indicates a divide by zero has taken place (can be set only if DIV_0_TRP is set)"}, [PRINT_UFSR_DIVBYZERO] = "Usage fault is caused by Indicates a divide by zero has taken place (can be set only if DIV_0_TRP is set)",
[PRINT_DFSR_HALTED] = {"Debug fault is caused by halt requested in NVIC"}, [PRINT_DFSR_HALTED] = "Debug fault is caused by halt requested in NVIC",
[PRINT_DFSR_BKPT] = {"Debug fault is caused by BKPT instruction executed"}, [PRINT_DFSR_BKPT] = "Debug fault is caused by BKPT instruction executed",
[PRINT_DFSR_DWTTRAP] = {"Debug fault is caused by DWT match occurred"}, [PRINT_DFSR_DWTTRAP] = "Debug fault is caused by DWT match occurred",
[PRINT_DFSR_VCATCH] = {"Debug fault is caused by Vector fetch occurred"}, [PRINT_DFSR_VCATCH] = "Debug fault is caused by Vector fetch occurred",
[PRINT_DFSR_EXTERNAL] = {"Debug fault is caused by EDBGRQ signal asserted"}, [PRINT_DFSR_EXTERNAL] = "Debug fault is caused by EDBGRQ signal asserted",
#elif (CMB_PRINT_LANGUAGE == CMB_PRINT_LANUUAGE_CHINESE) #elif (CMB_PRINT_LANGUAGE == CMB_PRINT_LANUUAGE_CHINESE)
[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] = "在中断或裸机环境下发生断言",
[PRINT_THREAD_STACK_INFO] = {"=========== 线程堆栈信息 ==========="}, [PRINT_THREAD_STACK_INFO] = "=========== 线程堆栈信息 ===========",
[PRINT_MAIN_STACK_INFO] = {"============ 主堆栈信息 ============"}, [PRINT_MAIN_STACK_INFO] = "============ 主堆栈信息 ============",
[PRINT_CALL_STACK_INFO] = {"查看更多函数调用栈信息请运行addr2line -e %s%s -a -f %.*s"}, [PRINT_CALL_STACK_INFO] = "查看更多函数调用栈信息请运行addr2line -e %s%s -a -f %.*s",
[PRINT_CALL_STACK_ERR] = {"获取函数调用栈失败"}, [PRINT_CALL_STACK_ERR] = "获取函数调用栈失败",
[PRINT_FAULT_ON_THREAD] = { "在线程(%s)中发生错误异常" }, [PRINT_FAULT_ON_THREAD] = "在线程(%s)中发生错误异常",
[PRINT_FAULT_ON_HANDLER] = {"在中断或裸机环境下发生错误异常"}, [PRINT_FAULT_ON_HANDLER] = "在中断或裸机环境下发生错误异常",
[PRINT_REGS_TITLE] = {"========================= 寄存器信息 ========================="}, [PRINT_REGS_TITLE] = "========================= 寄存器信息 =========================",
[PRINT_HFSR_VECTBL] = {"发生硬错误,原因:取中断向量时出错"}, [PRINT_HFSR_VECTBL] = "发生硬错误,原因:取中断向量时出错",
[PRINT_MFSR_IACCVIOL] = {"发生存储器管理错误,原因:企图从不允许访问的区域取指令"}, [PRINT_MFSR_IACCVIOL] = "发生存储器管理错误,原因:企图从不允许访问的区域取指令",
[PRINT_MFSR_DACCVIOL] = {"发生存储器管理错误,原因:企图从不允许访问的区域读、写数据"}, [PRINT_MFSR_DACCVIOL] = "发生存储器管理错误,原因:企图从不允许访问的区域读、写数据",
[PRINT_MFSR_MUNSTKERR] = {"发生存储器管理错误,原因:出栈时企图访问不被允许的区域"}, [PRINT_MFSR_MUNSTKERR] = "发生存储器管理错误,原因:出栈时企图访问不被允许的区域",
[PRINT_MFSR_MSTKERR] = {"发生存储器管理错误,原因:入栈时企图访问不被允许的区域"}, [PRINT_MFSR_MSTKERR] = "发生存储器管理错误,原因:入栈时企图访问不被允许的区域",
[PRINT_MFSR_MLSPERR] = {"发生存储器管理错误,原因:惰性保存浮点状态时发生错误"}, [PRINT_MFSR_MLSPERR] = "发生存储器管理错误,原因:惰性保存浮点状态时发生错误",
[PRINT_BFSR_IBUSERR] = {"发生总线错误,原因:指令总线错误"}, [PRINT_BFSR_IBUSERR] = "发生总线错误,原因:指令总线错误",
[PRINT_BFSR_PRECISERR] = {"发生总线错误,原因:精确的数据总线错误"}, [PRINT_BFSR_PRECISERR] = "发生总线错误,原因:精确的数据总线错误",
[PRINT_BFSR_IMPREISERR] = {"发生总线错误,原因:不精确的数据总线错误"}, [PRINT_BFSR_IMPREISERR] = "发生总线错误,原因:不精确的数据总线错误",
[PRINT_BFSR_UNSTKERR] = {"发生总线错误,原因:出栈时发生错误"}, [PRINT_BFSR_UNSTKERR] = "发生总线错误,原因:出栈时发生错误",
[PRINT_BFSR_STKERR] = {"发生总线错误,原因:入栈时发生错误"}, [PRINT_BFSR_STKERR] = "发生总线错误,原因:入栈时发生错误",
[PRINT_BFSR_LSPERR] = {"发生总线错误,原因:惰性保存浮点状态时发生错误"}, [PRINT_BFSR_LSPERR] = "发生总线错误,原因:惰性保存浮点状态时发生错误",
[PRINT_UFSR_UNDEFINSTR] = {"发生用法错误,原因:企图执行未定义指令"}, [PRINT_UFSR_UNDEFINSTR] = "发生用法错误,原因:企图执行未定义指令",
[PRINT_UFSR_INVSTATE] = {"发生用法错误,原因:试图切换到 ARM 状态"}, [PRINT_UFSR_INVSTATE] = "发生用法错误,原因:试图切换到 ARM 状态",
[PRINT_UFSR_INVPC] = {"发生用法错误,原因:无效的异常返回码"}, [PRINT_UFSR_INVPC] = "发生用法错误,原因:无效的异常返回码",
[PRINT_UFSR_NOCP] = {"发生用法错误,原因:企图执行协处理器指令"}, [PRINT_UFSR_NOCP] = "发生用法错误,原因:企图执行协处理器指令",
[PRINT_UFSR_UNALIGNED] = {"发生用法错误,原因:企图执行非对齐访问"}, [PRINT_UFSR_UNALIGNED] = "发生用法错误,原因:企图执行非对齐访问",
[PRINT_UFSR_DIVBYZERO] = {"发生用法错误,原因:企图执行除 0 操作"}, [PRINT_UFSR_DIVBYZERO] = "发生用法错误,原因:企图执行除 0 操作",
[PRINT_DFSR_HALTED] = {"发生调试错误原因NVIC 停机请求"}, [PRINT_DFSR_HALTED] = "发生调试错误原因NVIC 停机请求",
[PRINT_DFSR_BKPT] = {"发生调试错误,原因:执行 BKPT 指令"}, [PRINT_DFSR_BKPT] = "发生调试错误,原因:执行 BKPT 指令",
[PRINT_DFSR_DWTTRAP] = {"发生调试错误,原因:数据监测点匹配"}, [PRINT_DFSR_DWTTRAP] = "发生调试错误,原因:数据监测点匹配",
[PRINT_DFSR_VCATCH] = {"发生调试错误,原因:发生向量捕获"}, [PRINT_DFSR_VCATCH] = "发生调试错误,原因:发生向量捕获",
[PRINT_DFSR_EXTERNAL] = {"发生调试错误,原因:外部调试请求"}, [PRINT_DFSR_EXTERNAL] = "发生调试错误,原因:外部调试请求",
#else #else
#error "CMB_PRINT_LANGUAGE defined error in 'cmb_cfg.h'" #error "CMB_PRINT_LANGUAGE defined error in 'cmb_cfg.h'"
#endif #endif
@ -204,10 +233,12 @@ void cm_backtrace_init(const char *firmware_name, const char *hardware_ver, cons
code_start_addr = (uint32_t)__section_begin(CMB_CODE_SECTION_NAME); code_start_addr = (uint32_t)__section_begin(CMB_CODE_SECTION_NAME);
code_size = (uint32_t)__section_end(CMB_CODE_SECTION_NAME) - code_start_addr; code_size = (uint32_t)__section_end(CMB_CODE_SECTION_NAME) - code_start_addr;
#elif defined(__GNUC__) #elif defined(__GNUC__)
#error "not implemented, I hope you can do this" main_stack_start_addr = (uint32_t)(&CMB_CSTACK_BLOCK_START);
//TODO 待实现 main_stack_size = (uint32_t)(&CMB_CSTACK_BLOCK_END) - main_stack_start_addr;
code_start_addr = (uint32_t)(&CMB_CODE_SECTION_START);
code_size = (uint32_t)(&CMB_CODE_SECTION_END) - code_start_addr;
#else #else
#error "not supported compiler" #error "not supported compiler"
#endif #endif
init_ok = true; init_ok = true;
@ -317,8 +348,8 @@ static void dump_main_stack(uint32_t stack_start_addr, size_t stack_size, uint32
* @return depth * @return depth
*/ */
size_t cm_backtrace_call_stack(uint32_t *buffer, size_t size, uint32_t sp) { size_t cm_backtrace_call_stack(uint32_t *buffer, size_t size, uint32_t sp) {
uint32_t stack_start_addr = main_stack_start_addr, stack_size = main_stack_size, pc; uint32_t stack_start_addr = main_stack_start_addr, pc;
size_t depth = 0; size_t depth = 0, stack_size = main_stack_size;
bool regs_saved_lr_is_valid = false; bool regs_saved_lr_is_valid = false;
if (on_fault) { if (on_fault) {
@ -375,7 +406,7 @@ static void print_call_stack(uint32_t sp) {
cur_depth = cm_backtrace_call_stack(call_stack_buf, CMB_CALL_STACK_MAX_DEPTH, sp); cur_depth = cm_backtrace_call_stack(call_stack_buf, CMB_CALL_STACK_MAX_DEPTH, sp);
for (i = 0; i < cur_depth; i++) { for (i = 0; i < cur_depth; i++) {
sprintf(call_stack_info + i * (8 + 1), "%08x", call_stack_buf[i]); sprintf(call_stack_info + i * (8 + 1), "%08lx", call_stack_buf[i]);
call_stack_info[i * (8 + 1) + 8] = ' '; call_stack_info[i * (8 + 1) + 8] = ' ';
} }
@ -415,7 +446,8 @@ void cm_backtrace_assert(uint32_t sp) {
cmb_println(print_info[PRINT_ASSERT_ON_THREAD], get_cur_thread_name()); cmb_println(print_info[PRINT_ASSERT_ON_THREAD], get_cur_thread_name());
#ifdef CMB_USING_DUMP_STACK_INFO #ifdef CMB_USING_DUMP_STACK_INFO
uint32_t stack_start_addr, stack_size; uint32_t stack_start_addr;
size_t stack_size;
get_cur_thread_stack_info(sp, &stack_start_addr, &stack_size); get_cur_thread_stack_info(sp, &stack_start_addr, &stack_size);
dump_cur_thread_stack(stack_start_addr, stack_size, (uint32_t *) sp); dump_cur_thread_stack(stack_start_addr, stack_size, (uint32_t *) sp);
#endif /* CMB_USING_DUMP_STACK_INFO */ #endif /* CMB_USING_DUMP_STACK_INFO */
@ -562,7 +594,8 @@ void cm_backtrace_fault(uint32_t fault_handler_lr, uint32_t fault_handler_sp) {
const char *regs_name[] = { "R0 ", "R1 ", "R2 ", "R3 ", "R12", "LR ", "PC ", "PSR" }; const char *regs_name[] = { "R0 ", "R1 ", "R2 ", "R3 ", "R12", "LR ", "PC ", "PSR" };
#ifdef CMB_USING_DUMP_STACK_INFO #ifdef CMB_USING_DUMP_STACK_INFO
uint32_t stack_start_addr = main_stack_start_addr, stack_size = main_stack_size; uint32_t stack_start_addr = main_stack_start_addr;
size_t stack_size = main_stack_size;
#endif #endif
CMB_ASSERT(init_ok); CMB_ASSERT(init_ok);

@ -34,7 +34,7 @@
#include <stdlib.h> #include <stdlib.h>
/* library software version number */ /* library software version number */
#define CMB_SW_VERSION "0.1.0" #define CMB_SW_VERSION "0.1.1"
#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
@ -79,14 +79,21 @@
#define CMB_CODE_SECTION_NAME ".text" #define CMB_CODE_SECTION_NAME ".text"
#endif #endif
#elif defined(__GNUC__) #elif defined(__GNUC__)
//TODO ´ý²âÊÔ /* C stack block start address, defined on linker script file, default is _sstack */
/* C stack block name, default is STACK */ #ifndef CMB_CSTACK_BLOCK_START
#ifndef CMB_CSTACK_BLOCK_NAME #define CMB_CSTACK_BLOCK_START _sstack
#define CMB_CSTACK_BLOCK_NAME STACK
#endif #endif
/* code section name, default is ER_IROM1 */ /* C stack block end address, defined on linker script file, default is _estack */
#ifndef CMB_CODE_SECTION_NAME #ifndef CMB_CSTACK_BLOCK_END
#define CMB_CODE_SECTION_NAME ER_IROM1 #define CMB_CSTACK_BLOCK_END _estack
#endif
/* code section start address, defined on linker script file, default is _stext */
#ifndef CMB_CODE_SECTION_START
#define CMB_CODE_SECTION_START _stext
#endif
/* code section end address, defined on linker script file, default is _etext */
#ifndef CMB_CODE_SECTION_END
#define CMB_CODE_SECTION_END _etext
#endif #endif
#else #else
#error "not supported compiler" #error "not supported compiler"
@ -263,7 +270,7 @@ if (!(EXPR)) \
#elif defined(__ICCARM__) #elif defined(__ICCARM__)
#define CMB_ELF_FILE_EXTENSION_NAME ".out" #define CMB_ELF_FILE_EXTENSION_NAME ".out"
#elif defined(__GNUC__) #elif defined(__GNUC__)
#define CMB_ELF_FILE_EXTENSION_NAME ".o" #define CMB_ELF_FILE_EXTENSION_NAME ".elf"
#else #else
#error "not supported compiler" #error "not supported compiler"
#endif #endif
@ -302,17 +309,8 @@ if (!(EXPR)) \
#endif /* (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_RTT) */ #endif /* (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_RTT) */
#endif /* (defined(CMB_USING_BARE_METAL_PLATFORM) && defined(CMB_USING_OS_PLATFORM)) */ #endif /* (defined(CMB_USING_BARE_METAL_PLATFORM) && defined(CMB_USING_OS_PLATFORM)) */
/* include or export for supported, __get_SP function */
/* include or export for supported __get_MSP, __get_PSP, __get_SP function */
#if defined(__CC_ARM) #if defined(__CC_ARM)
static __inline __asm uint32_t __get_MSP(void) {
mrs r0, msp
bx lr
}
static __inline __asm uint32_t __get_PSP(void) {
mrs r0, psp
bx lr
}
static __inline __asm uint32_t __get_SP(void) { static __inline __asm uint32_t __get_SP(void) {
mov r0, sp mov r0, sp
bx lr bx lr
@ -320,20 +318,9 @@ if (!(EXPR)) \
#elif defined(__ICCARM__) #elif defined(__ICCARM__)
#include <intrinsics.h> #include <intrinsics.h>
#elif defined(__GNUC__) #elif defined(__GNUC__)
//TODO ´ý²âÊÔ
__attribute__( ( always_inline ) ) static inline uint32_t __get_MSP(void) {
register uint32_t result;
__asm volatile ("MRS %0, msp\n" : "=r" (result) );
return(result);
}
__attribute__( ( always_inline ) ) static inline uint32_t __get_PSP(void) {
register uint32_t result;
__asm volatile ("MRS %0, psp\n" : "=r" (result) );
return(result);
}
__attribute__( ( always_inline ) ) static inline uint32_t __get_SP(void) { __attribute__( ( always_inline ) ) static inline uint32_t __get_SP(void) {
register uint32_t result; register uint32_t result;
__asm volatile ("MRS %0, sp\n" : "=r" (result) ); __asm volatile ("MOV %0, sp\n" : "=r" (result) );
return(result); return(result);
} }
#else #else

@ -0,0 +1,43 @@
/*
* This file is part of the CmBacktrace Library.
*
* Copyright (c) 2016, 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
* 'Software'), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Function: Fault handler by GCC assembly code
* Created on: 2016-12-16
*/
.syntax unified
.thumb
.text
/* NOTE: If use this file's HardFault_Handler, please comments the HardFault_Handler code on other file. */
.global HardFault_Handler
.type HardFault_Handler, %function
HardFault_Handler:
MOV r0, lr /* get lr */
MOV r1, sp /* get stack pointer (current is MSP) */
BL cm_backtrace_fault
Fault_Loop:
BL Fault_Loop /* while(1) */

@ -1,45 +0,0 @@
;/*
; * This file is part of the CmBacktrace Library.
; *
; * Copyright (c) 2016, 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
; * 'Software'), to deal in the Software without restriction, including
; * without limitation the rights to use, copy, modify, merge, publish,
; * distribute, sublicense, and/or sell copies of the Software, and to
; * permit persons to whom the Software is furnished to do so, subject to
; * the following conditions:
; *
; * The above copyright notice and this permission notice shall be
; * included in all copies or substantial portions of the Software.
; *
; * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
; * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
; * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
; * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
; * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
; * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
; * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
; *
; * Function: Fault handler by GCC assembly code
; * Created on: 2016-12-16
; */
.syntax unified
.thumb
.text
; NOTE: If use this file's HardFault_Handler, please comments the HardFault_Handler code on other file.
IMPORT cm_backtrace_fault
EXPORT HardFault_Handler
HardFault_Handler:
MOV r0, lr ; get lr
MOV r1, sp ; get stack pointer (current is MSP)
BL cm_backtrace_fault
Fault_Loop
BL Fault_Loop ;while(1)
END
Loading…
Cancel
Save