Skip to content

Commit c2076b5

Browse files
committed
mbed_error: Simplify read of stack pointer
1 parent e20edbd commit c2076b5

File tree

1 file changed

+1
-26
lines changed

1 file changed

+1
-26
lines changed

platform/mbed_error.c

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,6 @@
2929
#include <stdio.h>
3030
#endif
3131

32-
//Helper macro to get the current SP
33-
#define GET_CURRENT_SP(sp) \
34-
{ \
35-
/*If in Handler mode we are always using MSP*/ \
36-
if ( __get_IPSR() != 0U ) { \
37-
sp = __get_MSP(); \
38-
} else { \
39-
/*Look into CONTROL.SPSEL value*/ \
40-
if ((__get_CONTROL() & 2U) == 0U) { \
41-
sp = __get_MSP();/*Read MSP*/ \
42-
} else { \
43-
sp = __get_PSP();/*Read PSP*/ \
44-
} \
45-
} \
46-
}
47-
4832
#ifndef NDEBUG
4933
#define ERROR_REPORT(ctx, error_msg) print_error_report(ctx, error_msg)
5034
#else
@@ -132,10 +116,7 @@ static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsign
132116
current_error_ctx.thread_entry_address = (uint32_t)current_thread->thread_addr;
133117
current_error_ctx.thread_stack_size = current_thread->stack_size;
134118
current_error_ctx.thread_stack_mem = (uint32_t)current_thread->stack_mem;
135-
#ifdef TARGET_CORTEX_M
136-
GET_CURRENT_SP(current_error_ctx.thread_current_sp);
137-
#endif //TARGET_CORTEX_M
138-
119+
current_error_ctx.thread_current_sp = (uint32_t)&current_error_ctx; // Address local variable to get a stack pointer
139120
#endif //MBED_CONF_RTOS_PRESENT
140121

141122
#if MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED
@@ -368,14 +349,8 @@ static void print_error_report(mbed_error_ctx *ctx, const char *error_msg)
368349
#endif
369350

370351
mbed_error_printf("\nError Value: 0x%X", ctx->error_value);
371-
#ifdef TARGET_CORTEX_M
372352
mbed_error_printf("\nCurrent Thread: Id: 0x%X Entry: 0x%X StackSize: 0x%X StackMem: 0x%X SP: 0x%X ",
373353
ctx->thread_id, ctx->thread_entry_address, ctx->thread_stack_size, ctx->thread_stack_mem, ctx->thread_current_sp);
374-
#else
375-
//For Cortex-A targets we dont have support to capture the current SP
376-
mbed_error_printf("\nCurrent Thread: Id: 0x%X Entry: 0x%X StackSize: 0x%X StackMem: 0x%X ",
377-
ctx->thread_id, ctx->thread_entry_address, ctx->thread_stack_size, ctx->thread_stack_mem);
378-
#endif //TARGET_CORTEX_M
379354

380355
#if MBED_CONF_PLATFORM_ERROR_ALL_THREADS_INFO && defined(MBED_CONF_RTOS_PRESENT)
381356
mbed_error_printf("\nNext:");

0 commit comments

Comments
 (0)