|
26 | 26 | #include "platform/mbed_interface.h"
|
27 | 27 | #include "platform/mbed_power_mgmt.h"
|
28 | 28 | #include "platform/mbed_stats.h"
|
29 |
| -#if defined(__CORTEX_M) |
30 | 29 | #include "platform/source/TARGET_CORTEX_M/mbed_fault_handler.h"
|
31 |
| -#endif |
| 30 | +#include "mbed_rtx.h" |
32 | 31 | #ifdef MBED_CONF_RTOS_PRESENT
|
33 | 32 | #include "rtx_os.h"
|
34 | 33 | #endif
|
@@ -153,29 +152,40 @@ static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsign
|
153 | 152 | //Capture error information
|
154 | 153 | current_error_ctx.error_status = error_status;
|
155 | 154 | current_error_ctx.error_value = error_value;
|
156 |
| - if (error_status == MBED_ERROR_MEMMANAGE_EXCEPTION || |
| 155 | + bool bHWException = (error_status == MBED_ERROR_MEMMANAGE_EXCEPTION || |
157 | 156 | error_status == MBED_ERROR_BUSFAULT_EXCEPTION ||
|
158 | 157 | error_status == MBED_ERROR_USAGEFAULT_EXCEPTION ||
|
159 |
| - error_status == MBED_ERROR_HARDFAULT_EXCEPTION) { |
160 |
| -#if defined(__CORTEX_M) |
161 |
| - mbed_fault_context_t *mfc = (mbed_fault_context_t *)error_value; |
| 158 | + error_status == MBED_ERROR_HARDFAULT_EXCEPTION); |
| 159 | + mbed_fault_context_t *mfc = NULL; |
| 160 | + if (bHWException) { |
| 161 | + mfc = (mbed_fault_context_t *)error_value; |
162 | 162 | current_error_ctx.error_address = (uint32_t)mfc->PC_reg;
|
163 | 163 | // Note that this SP_reg is the correct SP value of the fault. PSP and MSP are slightly different due to HardFault_Handler.
|
164 | 164 | current_error_ctx.thread_current_sp = (uint32_t)mfc->SP_reg;
|
165 | 165 | // Note that the RTX thread itself is the same even under this fault exception handler.
|
166 |
| -#endif |
167 | 166 | } else {
|
168 | 167 | current_error_ctx.error_address = (uint32_t)caller;
|
169 | 168 | current_error_ctx.thread_current_sp = (uint32_t)¤t_error_ctx; // Address local variable to get a stack pointer
|
170 | 169 | }
|
171 | 170 |
|
172 | 171 | #ifdef MBED_CONF_RTOS_PRESENT
|
173 |
| - //Capture thread info |
174 |
| - osRtxThread_t *current_thread = osRtxInfo.thread.run.curr; |
175 |
| - current_error_ctx.thread_id = (uint32_t)current_thread; |
176 |
| - current_error_ctx.thread_entry_address = (uint32_t)current_thread->thread_addr; |
177 |
| - current_error_ctx.thread_stack_size = current_thread->stack_size; |
178 |
| - current_error_ctx.thread_stack_mem = (uint32_t)current_thread->stack_mem; |
| 172 | + if (mfc && !(mfc->EXC_RETURN & 0x4)) |
| 173 | + { |
| 174 | + // handler mode |
| 175 | + current_error_ctx.thread_id = 0; |
| 176 | + current_error_ctx.thread_entry_address = 0; |
| 177 | + current_error_ctx.thread_stack_size = MAX(0, INITIAL_SP - current_error_ctx.thread_current_sp - sizeof(int)); |
| 178 | + current_error_ctx.thread_stack_mem = current_error_ctx.thread_current_sp; |
| 179 | + } |
| 180 | + else |
| 181 | + { |
| 182 | + // Capture thread info in thread mode |
| 183 | + osRtxThread_t *current_thread = osRtxInfo.thread.run.curr; |
| 184 | + current_error_ctx.thread_id = (uint32_t)current_thread; |
| 185 | + current_error_ctx.thread_entry_address = (uint32_t)current_thread->thread_addr; |
| 186 | + current_error_ctx.thread_stack_size = current_thread->stack_size; |
| 187 | + current_error_ctx.thread_stack_mem = (uint32_t)current_thread->stack_mem; |
| 188 | + } |
179 | 189 | #endif //MBED_CONF_RTOS_PRESENT
|
180 | 190 |
|
181 | 191 | #if MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED
|
@@ -458,16 +468,20 @@ mbed_error_status_t mbed_clear_all_errors(void)
|
458 | 468 | return status;
|
459 | 469 | }
|
460 | 470 |
|
461 |
| -static inline const char *name_or_unnamed(const char *name) |
| 471 | +static inline const char *name_or_unnamed(const osRtxThread_t *thread) |
462 | 472 | {
|
| 473 | + if (!thread) |
| 474 | + return "<handler>"; |
| 475 | + |
| 476 | + const char *name = thread->name; |
463 | 477 | return name ? name : "<unnamed>";
|
464 | 478 | }
|
465 | 479 |
|
466 | 480 | #if MBED_CONF_PLATFORM_ERROR_ALL_THREADS_INFO && defined(MBED_CONF_RTOS_PRESENT)
|
467 | 481 | /* Prints info of a thread(using osRtxThread_t struct)*/
|
468 | 482 | static void print_thread(const osRtxThread_t *thread)
|
469 | 483 | {
|
470 |
| - mbed_error_printf("\n%s State: 0x%" PRIX8 " Entry: 0x%08" PRIX32 " Stack Size: 0x%08" PRIX32 " Mem: 0x%08" PRIX32 " SP: 0x%08" PRIX32, name_or_unnamed(thread->name), thread->state, thread->thread_addr, thread->stack_size, (uint32_t)thread->stack_mem, thread->sp); |
| 484 | + mbed_error_printf("\n%s State: 0x%" PRIX8 " Entry: 0x%08" PRIX32 " Stack Size: 0x%08" PRIX32 " Mem: 0x%08" PRIX32 " SP: 0x%08" PRIX32, name_or_unnamed(thread), thread->state, thread->thread_addr, thread->stack_size, (uint32_t)thread->stack_mem, thread->sp); |
471 | 485 | }
|
472 | 486 |
|
473 | 487 | /* Prints thread info from a list */
|
@@ -551,7 +565,7 @@ static void print_error_report(const mbed_error_ctx *ctx, const char *error_msg,
|
551 | 565 | mbed_error_printf("\nError Value: 0x%" PRIX32, ctx->error_value);
|
552 | 566 | #ifdef MBED_CONF_RTOS_PRESENT
|
553 | 567 | mbed_error_printf("\nCurrent Thread: %s Id: 0x%" PRIX32 " Entry: 0x%" PRIX32 " StackSize: 0x%" PRIX32 " StackMem: 0x%" PRIX32 " SP: 0x%" PRIX32 " ",
|
554 |
| - name_or_unnamed(((osRtxThread_t *)ctx->thread_id)->name), |
| 568 | + name_or_unnamed((osRtxThread_t *)ctx->thread_id), |
555 | 569 | ctx->thread_id, ctx->thread_entry_address, ctx->thread_stack_size, ctx->thread_stack_mem, ctx->thread_current_sp);
|
556 | 570 | #endif
|
557 | 571 |
|
|
0 commit comments