This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to use APP_ERROR_HANDLER in custom function

Hi,

I try to use APP_ERROR_HANDLER(err_code) with a custom error code ( for example 25) in a custom function. Error code reported is correct, but error line and filename are not correct...

How to use correctly App_error.c lib in custom functions or others custom files ?

Thanks

  • APP_ERROR_HANDLER is a macro that will call the app_error_handler function with the file and line number where the macro is invoked. If, for example, you want the file and line number of the caller of your custom function to be reported, you can do something similar:

    void custom_function(uint32_t line_num, const uint8_t * p_file_name)
    {
        if (!some_operation())
            app_error_handler(25, line_num, p_file_name);
        ...
    }
    

    In your header,

    #define CUSTOM_FUNCTION() custom_function(__LINE__, (uint8_t *)__FILE__)
    

    And in code that uses it, use the macro:

    CUSTOM_FUNCTION();  // <- this file and line will be reported by errors in custom_function
    
Related