diff --git a/cm_backtrace/cm_backtrace.c b/cm_backtrace/cm_backtrace.c index 544676c..5ee5a11 100644 --- a/cm_backtrace/cm_backtrace.c +++ b/cm_backtrace/cm_backtrace.c @@ -31,33 +31,6 @@ #include #include -/* 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 -#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) #define SECTION_START(_name_) _name_##$$Base #define SECTION_END(_name_) _name_##$$Limit @@ -369,7 +342,7 @@ size_t cm_backtrace_call_stack(uint32_t *buffer, size_t size, uint32_t sp) { } } else { /* OS environment */ - if (__get_SP() == __get_PSP()) { + if (cmb_get_sp() == cmb_get_psp()) { get_cur_thread_stack_info(sp, &stack_start_addr, &stack_size); } #endif /* CMB_USING_OS_PLATFORM */ @@ -426,7 +399,7 @@ void cm_backtrace_assert(uint32_t sp) { CMB_ASSERT(init_ok); #ifdef CMB_USING_OS_PLATFORM - uint32_t cur_stack_pointer = __get_SP(); + uint32_t cur_stack_pointer = cmb_get_sp(); #endif cmb_println(""); @@ -434,14 +407,14 @@ void cm_backtrace_assert(uint32_t sp) { #ifdef CMB_USING_OS_PLATFORM /* OS environment */ - if (cur_stack_pointer == __get_MSP()) { + if (cur_stack_pointer == cmb_get_msp()) { cmb_println(print_info[PRINT_ASSERT_ON_HANDLER]); #ifdef CMB_USING_DUMP_STACK_INFO dump_main_stack(main_stack_start_addr, main_stack_size, (uint32_t *) sp); #endif /* CMB_USING_DUMP_STACK_INFO */ - } else if (cur_stack_pointer == __get_PSP()) { + } else if (cur_stack_pointer == cmb_get_psp()) { cmb_println(print_info[PRINT_ASSERT_ON_THREAD], get_cur_thread_name()); #ifdef CMB_USING_DUMP_STACK_INFO @@ -616,7 +589,7 @@ void cm_backtrace_fault(uint32_t fault_handler_lr, uint32_t fault_handler_sp) { /* check which stack was used before (MSP or PSP) */ if (on_thread_before_fault) { cmb_println(print_info[PRINT_FAULT_ON_THREAD], get_cur_thread_name() != NULL ? get_cur_thread_name() : "NO_NAME"); - saved_regs_addr = stack_pointer = __get_PSP(); + saved_regs_addr = stack_pointer = cmb_get_psp(); #ifdef CMB_USING_DUMP_STACK_INFO get_cur_thread_stack_info(stack_pointer, &stack_start_addr, &stack_size); diff --git a/cm_backtrace/cmb_def.h b/cm_backtrace/cmb_def.h index b4d0db8..b547cef 100644 --- a/cm_backtrace/cmb_def.h +++ b/cm_backtrace/cmb_def.h @@ -34,7 +34,7 @@ #include /* library software version number */ -#define CMB_SW_VERSION "0.2.0" +#define CMB_SW_VERSION "0.2.1" #define CMB_CPU_ARM_CORTEX_M0 0 #define CMB_CPU_ARM_CORTEX_M3 1 @@ -314,16 +314,51 @@ if (!(EXPR)) \ #endif /* (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_RTT) */ #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 cmb_get_msp, cmb_get_psp and cmb_get_sp function */ #if defined(__CC_ARM) - static __inline __asm uint32_t __get_SP(void) { + static __inline __asm uint32_t cmb_get_msp(void) { + mrs r0, msp + bx lr + } + static __inline __asm uint32_t cmb_get_psp(void) { + mrs r0, psp + bx lr + } + static __inline __asm uint32_t cmb_get_sp(void) { mov r0, sp bx lr } #elif defined(__ICCARM__) - #include + static uint32_t cmb_get_msp(void) + { + register uint32_t result; + __asm("MRS %0, msp" : "=r" (result)); + return(result); + } + static uint32_t cmb_get_psp(void) + { + register uint32_t result; + __asm("MRS %0, psp" : "=r" (result)); + return(result); + } + static uint32_t cmb_get_sp(void) + { + register uint32_t result; + __asm("MOV %0, sp" : "=r" (result)); + return(result); + } #elif defined(__GNUC__) - __attribute__( ( always_inline ) ) static inline uint32_t __get_SP(void) { + __attribute__( ( always_inline ) ) static inline uint32_t cmb_get_msp(void) { + register uint32_t result; + __asm volatile ("MRS %0, msp\n" : "=r" (result) ); + return(result); + } + __attribute__( ( always_inline ) ) static inline uint32_t cmb_get_psp(void) { + register uint32_t result; + __asm volatile ("MRS %0, psp\n" : "=r" (result) ); + return(result); + } + __attribute__( ( always_inline ) ) static inline uint32_t cmb_get_sp(void) { register uint32_t result; __asm volatile ("MOV %0, sp\n" : "=r" (result) ); return(result); diff --git a/demos/non_os/stm32f10x/components/others/bsp.c b/demos/non_os/stm32f10x/components/others/bsp.c index 1da9e84..018d3d8 100644 --- a/demos/non_os/stm32f10x/components/others/bsp.c +++ b/demos/non_os/stm32f10x/components/others/bsp.c @@ -155,7 +155,7 @@ void assert_failed(u8* file, u32 line) /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* Infinite loop */ - cm_backtrace_assert(__get_SP()); + cm_backtrace_assert(cmb_get_sp()); printf("assert failed at %s:%d \n", file, line); while (1) { } diff --git a/demos/os/ucosii/stm32f10x/components/others/bsp.c b/demos/os/ucosii/stm32f10x/components/others/bsp.c index e31dfc3..4223d83 100644 --- a/demos/os/ucosii/stm32f10x/components/others/bsp.c +++ b/demos/os/ucosii/stm32f10x/components/others/bsp.c @@ -361,7 +361,7 @@ void assert_failed(u8* file, u32 line) /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* Infinite loop */ - cm_backtrace_assert(__get_SP()); + cm_backtrace_assert(cmb_get_sp()); printf("assert failed at %s:%d \n", file, line); while (1) { }