The candidate code to enable correct crash report for HW fault crashes.

pull/11332/head
Andrew Chong 2019-08-26 15:35:42 +08:00
parent 0427bb7469
commit 9af7ea58d4
2 changed files with 25 additions and 3 deletions

View File

@ -76,7 +76,7 @@ void mbed_fault_handler(uint32_t fault_type, const mbed_fault_context_t *mbed_fa
mbed_error_printf("\n\n-- MbedOS Fault Handler --\n\n");
//Now call mbed_error, to log the error and halt the system
mbed_error(faultStatus, "Fault exception", mbed_fault_context->PC_reg, NULL, 0);
mbed_error(faultStatus, "Fault exception", (unsigned int)mbed_fault_context_in, NULL, 0);
}

View File

@ -26,6 +26,9 @@
#include "platform/mbed_interface.h"
#include "platform/mbed_power_mgmt.h"
#include "platform/mbed_stats.h"
#if defined(__CORTEX_M)
#include "platform/source/TARGET_CORTEX_M/mbed_fault_handler.h"
#endif
#ifdef MBED_CONF_RTOS_PRESENT
#include "rtx_os.h"
#endif
@ -146,10 +149,30 @@ static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsign
//Clear the context capturing buffer
memset(&current_error_ctx, 0, sizeof(mbed_error_ctx));
//Capture error information
current_error_ctx.error_status = error_status;
current_error_ctx.error_address = (uint32_t)caller;
current_error_ctx.error_value = error_value;
if (error_status == MBED_ERROR_MEMMANAGE_EXCEPTION ||
error_status == MBED_ERROR_BUSFAULT_EXCEPTION ||
error_status == MBED_ERROR_USAGEFAULT_EXCEPTION ||
error_status == MBED_ERROR_HARDFAULT_EXCEPTION)
{
#if defined(__CORTEX_M)
mbed_fault_context_t *mfc = (mbed_fault_context_t*)error_value;
current_error_ctx.error_address = (uint32_t)mfc->PC_reg;
current_error_ctx.thread_current_sp = (uint32_t)mfc->SP_reg;
// Note that the RTX thread itself is same even under fault exception handlers.
#else
#warning Please implement non Cortex-M handler for those error cases.
#endif
}
else
{
current_error_ctx.error_address = (uint32_t)caller;
current_error_ctx.thread_current_sp = (uint32_t)&current_error_ctx; // Address local variable to get a stack pointer
}
#ifdef MBED_CONF_RTOS_PRESENT
//Capture thread info
osRtxThread_t *current_thread = osRtxInfo.thread.run.curr;
@ -157,7 +180,6 @@ static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsign
current_error_ctx.thread_entry_address = (uint32_t)current_thread->thread_addr;
current_error_ctx.thread_stack_size = current_thread->stack_size;
current_error_ctx.thread_stack_mem = (uint32_t)current_thread->stack_mem;
current_error_ctx.thread_current_sp = (uint32_t)&current_error_ctx; // Address local variable to get a stack pointer
#endif //MBED_CONF_RTOS_PRESENT
#if MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED