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

System reset after Soft device assert

I am using SDK 17 currently and nrf52840. I have read through the Q&As in the Dev zone and have not found the exact answer. So it might be a good idea to ask here Slight smile

I understand that in rare cases when the soft device asserts, one should call system reset function to recover. 

My question is: If I use the following code, will the function sd_nvic_SystemReset() ever be executed?

void assert_nrf_callback(uint16_t line_num, const uint8_t * p_file_name)
{
    app_error_handler(DEAD_BEEF, line_num, p_file_name);
    sd_nvic_SystemReset();
}

Will the system stuck inside the app_error_handler() function, instead of doing the reset? Thanks for your help.

Parents
  • app_error_handler will forward the error to app_error_fault_handler, unless the app_error_fault_handler is redefined. Depending on the preprocessor flags this will either halt (in debug mode) or reset:

    #ifndef DEBUG
        NRF_LOG_WARNING("System reset");
        NVIC_SystemReset();
    #else
        app_error_save_and_stop(id, pc, info);
    #endif // DEBUG

  • Thank you very much. I am using nrf52840 dk and project in release mode. I would like to double-confirm this, since I found that the code that forward the error to app_error_fault_handler is greyed out in app_error_handler_gcc.c. Instead, the following assembly code is used:

    void app_error_handler(ret_code_t error_code, uint32_t line_num, const uint8_t * p_file_name)
    {
        __ASM volatile(
    
        "push {lr}                      \n"
    
        /* reserve space on stack for error_info_t struct - preserve 8byte stack aligment */
        "sub sp, sp, %0                 \n"
    
        /* prepare error_info_t struct */
        "str r0, [sp, %1]               \n"
        "str r1, [sp, %3]               \n"
        "str r2, [sp, %2]               \n"
    
        /* prepare arguments and call function: app_error_fault_handler */
        "ldr r0, =%4                    \n"
        "mov r1, lr                     \n"
        "mov r2, sp                     \n"
        "bl  %5                         \n"
    
        /* release stack */
        "add sp, sp, %0                 \n"
    
        "pop {pc}                       \n"
        ".ltorg                         \n"
    
        : /* Outputs */
        : /* Inputs */
        "I" (APP_ERROR_ERROR_INFO_SIZE_ALIGNED_8BYTE),
        "I" (APP_ERROR_ERROR_INFO_OFFSET_ERR_CODE),
        "I" (APP_ERROR_ERROR_INFO_OFFSET_P_FILE_NAME),
        "I" (APP_ERROR_ERROR_INFO_OFFSET_LINE_NUM),
        "X" (NRF_FAULT_ID_SDK_ERROR),
        "X" (app_error_fault_handler)
        : /* Clobbers */
        "r0", "r1", "r2"
        );
    }

  • This function will prepare the error messages and Branch to the function app_error_fault_handler (The bl instruction at line 19)

    Error handler documentation for reference: Error module

Reply Children
No Data
Related