@@ -147,7 +147,7 @@ static bool mbed_error_is_handler(const mbed_error_ctx *ctx)
147147 bool is_handler = false;
148148 if (ctx && mbed_error_is_hw_fault (ctx -> error_status )) {
149149 mbed_fault_context_t * mfc = (mbed_fault_context_t * )ctx -> error_value ;
150- if (mfc && mfc -> EXC_RETURN & 0x8 ) {
150+ if (mfc && !( mfc -> EXC_RETURN & 0x8 ) ) {
151151 is_handler = true;
152152 }
153153 }
@@ -495,7 +495,7 @@ static void print_stack_dump_core(uint32_t stack_start, uint32_t stack_size, uin
495495#if MBED_STACK_DUMP_ENABLED
496496#define STACK_DUMP_WIDTH 8
497497#define INT_ALIGN_MASK (~(sizeof(int) - 1))
498- mbed_error_printf ("\n\ nStack Dump: %s" , postfix );
498+ mbed_error_printf ("\nStack Dump: %s" , postfix );
499499 uint32_t st_end = (stack_start + stack_size ) & INT_ALIGN_MASK ;
500500 uint32_t st = (stack_sp ) & INT_ALIGN_MASK ;
501501 for (; st <= st_end ; st += sizeof (int ) * STACK_DUMP_WIDTH ) {
@@ -520,16 +520,21 @@ static void print_stack_dump(uint32_t stack_start, uint32_t stack_size, uint32_t
520520 // Stack dump extra for handler stack which may have accessed MSP.
521521 mbed_fault_context_t * mfc = (mbed_fault_context_t * )ctx -> error_value ;
522522 uint32_t msp_sp = mfc -> MSP ;
523+ uint32_t psp_sp = mfc -> PSP ;
523524 if (mfc && !(mfc -> EXC_RETURN & 0x4 )) {
524525 // MSP mode. Then SP_reg is more correct.
525526 msp_sp = mfc -> SP_reg ;
527+ } else {
528+ // PSP mode. Then SP_reg is more correct.
529+ psp_sp = mfc -> SP_reg ;
526530 }
527531 // Do not access beyond INITIAL_SP.
528532 uint32_t msp_size = MAX (0 , (int )INITIAL_SP - (int )msp_sp - (int )sizeof (int ));
529533 print_stack_dump_core (msp_sp , msp_size , msp_sp , "MSP" );
534+
535+ stack_sp = psp_sp ;
530536 }
531537
532- // Handler thread may have accessed PSP.
533538 print_stack_dump_core (stack_start , stack_size , stack_sp , "PSP" );
534539#endif // MBED_STACK_DUMP_ENABLED
535540}
0 commit comments