|
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 | +#include "platform/source/TARGET_CORTEX_M/mbed_fault_handler.h" |
| 31 | +#endif |
29 | 32 | #ifdef MBED_CONF_RTOS_PRESENT
|
30 | 33 | #include "rtx_os.h"
|
31 | 34 | #endif
|
@@ -146,18 +149,37 @@ static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsign
|
146 | 149 |
|
147 | 150 | //Clear the context capturing buffer
|
148 | 151 | memset(¤t_error_ctx, 0, sizeof(mbed_error_ctx));
|
| 152 | + |
149 | 153 | //Capture error information
|
150 | 154 | current_error_ctx.error_status = error_status;
|
151 |
| - current_error_ctx.error_address = (uint32_t)caller; |
152 | 155 | current_error_ctx.error_value = error_value;
|
| 156 | + if (error_status == MBED_ERROR_MEMMANAGE_EXCEPTION || |
| 157 | + error_status == MBED_ERROR_BUSFAULT_EXCEPTION || |
| 158 | + error_status == MBED_ERROR_USAGEFAULT_EXCEPTION || |
| 159 | + error_status == MBED_ERROR_HARDFAULT_EXCEPTION) |
| 160 | + { |
| 161 | +#if defined(__CORTEX_M) |
| 162 | + mbed_fault_context_t *mfc = (mbed_fault_context_t*)error_value; |
| 163 | + current_error_ctx.error_address = (uint32_t)mfc->PC_reg; |
| 164 | + current_error_ctx.thread_current_sp = (uint32_t)mfc->SP_reg; |
| 165 | + // Note that the RTX thread itself is same even under fault exception handlers. |
| 166 | +#else |
| 167 | +#warning Please implement non Cortex-M handler for those error cases. |
| 168 | +#endif |
| 169 | + } |
| 170 | + else |
| 171 | + { |
| 172 | + current_error_ctx.error_address = (uint32_t)caller; |
| 173 | + current_error_ctx.thread_current_sp = (uint32_t)¤t_error_ctx; // Address local variable to get a stack pointer |
| 174 | + } |
| 175 | + |
153 | 176 | #ifdef MBED_CONF_RTOS_PRESENT
|
154 | 177 | //Capture thread info
|
155 | 178 | osRtxThread_t *current_thread = osRtxInfo.thread.run.curr;
|
156 | 179 | current_error_ctx.thread_id = (uint32_t)current_thread;
|
157 | 180 | current_error_ctx.thread_entry_address = (uint32_t)current_thread->thread_addr;
|
158 | 181 | current_error_ctx.thread_stack_size = current_thread->stack_size;
|
159 | 182 | current_error_ctx.thread_stack_mem = (uint32_t)current_thread->stack_mem;
|
160 |
| - current_error_ctx.thread_current_sp = (uint32_t)¤t_error_ctx; // Address local variable to get a stack pointer |
161 | 183 | #endif //MBED_CONF_RTOS_PRESENT
|
162 | 184 |
|
163 | 185 | #if MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED
|
|
0 commit comments