This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Contribution to app_error_handler, reporting error location

Please allow me to suggest you change app_error handler and related functions to something like this:

void app_error_handler(ret_code_t error_code, uint32_t line_num, const uint8_t * p_file_name)
{
	uint32_t pc = 0;
#ifdef __GNUC__
	asm ("mov %0, lr" : "=r"(pc));
#endif

    error_info_t error_info =
    {
        .line_num    = line_num,
        .p_file_name = p_file_name,
        .err_code    = error_code,
    };
    app_error_fault_handler(NRF_FAULT_ID_SDK_ERROR, pc, (uint32_t)(&error_info));

    UNUSED_VARIABLE(error_info);
}

The change will make app_error_handler report the actual location of the program counter in app_error_fault_handler and not just zero.

Parents
  • Hi Morten.

    Thanks for the input. This functionality should already be in the code. If you look at for example the app_error_handler_gcc.c file, you can see in line 80 (    "X" (app_error_fault_handler)) that app_error_fault_handler() is called. And the functionality you request are present in that function in the file app_error_weak.c in line 82 (case NRF_FAULT_ID_SDK_ERROR).

            case NRF_FAULT_ID_SDK_ERROR:
            {
                error_info_t * p_info = (error_info_t *)info;
                NRF_LOG_ERROR("ERROR %u [%s] at %s:%u\r\nPC at: 0x%08x",
                              p_info->err_code,
                              nrf_strerror_get(p_info->err_code),
                              p_info->p_file_name,
                              p_info->line_num,
                              pc);
                 NRF_LOG_ERROR("End of error report");
                break;
            }

    Feel free of course to implement your own version of this code snippet if you like.

    Best regards.

    Andreas

Reply
  • Hi Morten.

    Thanks for the input. This functionality should already be in the code. If you look at for example the app_error_handler_gcc.c file, you can see in line 80 (    "X" (app_error_fault_handler)) that app_error_fault_handler() is called. And the functionality you request are present in that function in the file app_error_weak.c in line 82 (case NRF_FAULT_ID_SDK_ERROR).

            case NRF_FAULT_ID_SDK_ERROR:
            {
                error_info_t * p_info = (error_info_t *)info;
                NRF_LOG_ERROR("ERROR %u [%s] at %s:%u\r\nPC at: 0x%08x",
                              p_info->err_code,
                              nrf_strerror_get(p_info->err_code),
                              p_info->p_file_name,
                              p_info->line_num,
                              pc);
                 NRF_LOG_ERROR("End of error report");
                break;
            }

    Feel free of course to implement your own version of this code snippet if you like.

    Best regards.

    Andreas

Children
No Data
Related