@@ -147,7 +147,7 @@ static bool mbed_error_is_handler(const mbed_error_ctx *ctx)
147
147
bool is_handler = false;
148
148
if (ctx && mbed_error_is_hw_fault (ctx -> error_status )) {
149
149
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 ) ) {
151
151
is_handler = true;
152
152
}
153
153
}
@@ -495,7 +495,7 @@ static void print_stack_dump_core(uint32_t stack_start, uint32_t stack_size, uin
495
495
#if MBED_STACK_DUMP_ENABLED
496
496
#define STACK_DUMP_WIDTH 8
497
497
#define INT_ALIGN_MASK (~(sizeof(int) - 1))
498
- mbed_error_printf ("\n\ nStack Dump: %s" , postfix );
498
+ mbed_error_printf ("\nStack Dump: %s" , postfix );
499
499
uint32_t st_end = (stack_start + stack_size ) & INT_ALIGN_MASK ;
500
500
uint32_t st = (stack_sp ) & INT_ALIGN_MASK ;
501
501
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
520
520
// Stack dump extra for handler stack which may have accessed MSP.
521
521
mbed_fault_context_t * mfc = (mbed_fault_context_t * )ctx -> error_value ;
522
522
uint32_t msp_sp = mfc -> MSP ;
523
+ uint32_t psp_sp = mfc -> PSP ;
523
524
if (mfc && !(mfc -> EXC_RETURN & 0x4 )) {
524
525
// MSP mode. Then SP_reg is more correct.
525
526
msp_sp = mfc -> SP_reg ;
527
+ } else {
528
+ // PSP mode. Then SP_reg is more correct.
529
+ psp_sp = mfc -> SP_reg ;
526
530
}
527
531
// Do not access beyond INITIAL_SP.
528
532
uint32_t msp_size = MAX (0 , (int )INITIAL_SP - (int )msp_sp - (int )sizeof (int ));
529
533
print_stack_dump_core (msp_sp , msp_size , msp_sp , "MSP" );
534
+
535
+ stack_sp = psp_sp ;
530
536
}
531
537
532
- // Handler thread may have accessed PSP.
533
538
print_stack_dump_core (stack_start , stack_size , stack_sp , "PSP" );
534
539
#endif // MBED_STACK_DUMP_ENABLED
535
540
}
0 commit comments