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

Use of MSP in error handler

We are currently getting intermittent errors in our ANT enabled application in field testing.  To try to understand where this is happening I want to send over ANT an indication of what line of code is causing the fault.

I had thought that the main stack pointer would be a good way to do this.  I am overriding the "app_error_fault_handler" function but putting in this code:

// Get stack pointer:
  uint32_t *sp = (uint32_t *) __get_MSP(); // Get stack pointer
  ia = sp[12];
  velo_status.error_status.stack_ptr = ia;
 

However the address returned is 0x000000BD which doesn't seem feasible.  Am I doing something wrong?  I have stolen the idea from the hard fault handler, and perhaps this just isn't possible in the app_error handler?

is there another way to go about it?  i can get the filename and line number, but that is a bit awkward to send over a 7 byte ANT payload.

Parents
  • Hi,

    I guess the offset is different compared to the hard fault handler because, on an assertion, the program goes through the app_error_handler() function first. I had to increment the stack pointer by two words instead of 12 in my case.

    How I tested it:

    1.  re-defined the app_error_fault_handler() like this:

    2. Inserted code to invoke the fault handler.

    3. Looked up the address from the debug console to verify that the PC indeed came from the error check added point 2. 

    Line 244 in main.c is the line following the APP_ERROR_CHECK(1); in point 2.

Reply
  • Hi,

    I guess the offset is different compared to the hard fault handler because, on an assertion, the program goes through the app_error_handler() function first. I had to increment the stack pointer by two words instead of 12 in my case.

    How I tested it:

    1.  re-defined the app_error_fault_handler() like this:

    2. Inserted code to invoke the fault handler.

    3. Looked up the address from the debug console to verify that the PC indeed came from the error check added point 2. 

    Line 244 in main.c is the line following the APP_ERROR_CHECK(1); in point 2.

Children
Related