My device is freezing and restarting

My device is either freezing or restarting, and i do not know why.

  • Why?

    In the SDK examples, we check return codes with the macro APP_ERROR_CHECK. This function calls the function app_error_handlerin app_error.c. Here we find this code:

    #ifndef DEBUG

    This means that by default, the response to ANY return code other than NRF_SUCCESS will cause a system reset.

    If we have defined DEBUG, this happens:

    m_error_code = error_code;
    m_line_num = line_num;
    m_p_file_name = p_file_name;

    We disable interrupts and stay in a loop forever. In this case we can either print out or read (with a debugger) the error code, line number and file name that returned the error code.

    Note the warning in the documentation of app_error_handler:

    @warning This handler is an example only and does not fit a final product. You need to analyze * how your product is supposed to react in case of error.

    Finding the error with the Keil debugger:

    1.Set optimization level 0 in target options -> C/C++ and define DEBUG in the preprocessor symbols. image description

    2.Place a break point next to while(loop); (right click ->Insert breakpoint)

    3.Run the program, and wait for the error to occur.

    4.Read the information by hovering the mouse cursor over the value. Alternatively you can add the values to a watch by doing right click->add to watch X. To display the values in decimal format rather than in hexadecimal, right click the variable (in watch window) and click on "Hexadecimal Display".

    image description

    Find more information about debugging with Keil here.

Reply Children
No Data