Skip to content

Commit f67fe4a

Browse files
Merge pull request #6257 from SenRamakri/sen_FaultHandlerFixes
Fix for Crash dump formatting issues and adding more info to crash dump
2 parents cf4c7a5 + 72f45b8 commit f67fe4a

File tree

5 files changed

+50
-17
lines changed

5 files changed

+50
-17
lines changed

rtos/TARGET_CORTEX/TARGET_CORTEX_M/TOOLCHAIN_ARM/except.S

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,18 @@ Fault_Handler_Continue2
144144
MRS R2,MSP ; Get MSP
145145
STR R2,[R1]
146146
ADDS R1,#4
147-
LDR R3,=mbed_fault_handler ; Load address of mbedFaultHandler
147+
MOV R2,LR ; Get current LR(EXC_RETURN)
148+
STR R2,[R1]
149+
ADDS R1,#4
150+
MRS R2,CONTROL ; Get CONTROL Reg
151+
STR R2,[R1]
152+
LDR R3,=mbed_fault_handler ; Load address of mbedFaultHandler
148153
MOV R0,R12
149154
LDR R1,=mbed_fault_context
150155
LDR R2,=osRtxInfo
151156
BLX R3
152157
#endif
153-
B . ; Just in case we come back here
158+
B . ; Just in case we come back here
154159
ENDP
155160
156161
#endif

rtos/TARGET_CORTEX/TARGET_CORTEX_M/TOOLCHAIN_GCC/except.S

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,12 @@ Fault_Handler_Continue2:
176176
MRS R2,MSP // Get MSP
177177
STR R2,[R1]
178178
ADDS R1,#4
179-
LDR R3,=mbed_fault_handler // Load address of mbedFaultHandler
179+
MOV R2,LR // Get current LR(EXC_RETURN)
180+
STR R2,[R1]
181+
ADDS R1,#4
182+
MRS R2,CONTROL // Get CONTROL Reg
183+
STR R2,[R1]
184+
LDR R3,=mbed_fault_handler // Load address of mbedFaultHandler
180185
MOV R0,R12
181186
LDR R1,=mbed_fault_context
182187
LDR R2,=osRtxInfo

rtos/TARGET_CORTEX/TARGET_CORTEX_M/TOOLCHAIN_IAR/except.S

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,18 @@ Fault_Handler_Continue2
139139
MRS R2,MSP ; Get MSP
140140
STR R2,[R1]
141141
ADDS R1,#4
142-
LDR R3,=mbed_fault_handler ; Load address of mbedFaultHandler
142+
MOV R2,LR ; Get current LR(EXC_RETURN)
143+
STR R2,[R1]
144+
ADDS R1,#4
145+
MRS R2,CONTROL ; Get CONTROL Reg
146+
STR R2,[R1]
147+
LDR R3,=mbed_fault_handler ; Load address of mbedFaultHandler
143148
MOV R0,R12
144149
LDR R1,=mbed_fault_context
145150
LDR R2,=osRtxInfo
146151
BLX R3
147152
#endif
148-
B . ; Just in case we come back here
149-
#endif ; #if (MBED_FAULT_HANDLER_SUPPORT == 1)
153+
B . ; Just in case we come back here
154+
#endif ; #if (MBED_FAULT_HANDLER_SUPPORT == 1)
150155

151156
END

rtos/TARGET_CORTEX/TARGET_CORTEX_M/mbed_rtx_fault_handler.c

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,27 @@ void print_context_info()
143143
fault_print_str("\nBFAR : %",(uint32_t *)&SCB->BFAR);
144144
}
145145
#endif
146-
146+
//Print Mode
147+
if(mbed_fault_context.EXC_RETURN & 0x8) {
148+
fault_print_str("\nMode : Thread", NULL);
149+
//Print Priv level in Thread mode - We capture CONTROL reg which reflects the privilege.
150+
//Note that the CONTROL register captured still reflects the privilege status of the
151+
//thread mode eventhough we are in Handler mode by the time we capture it.
152+
if(mbed_fault_context.CONTROL & 0x1) {
153+
fault_print_str("\nPriv : User", NULL);
154+
} else {
155+
fault_print_str("\nPriv : Privileged", NULL);
156+
}
157+
} else {
158+
fault_print_str("\nMode : Handler", NULL);
159+
fault_print_str("\nPriv : Privileged", NULL);
160+
}
161+
//Print Return Stack
162+
if(mbed_fault_context.EXC_RETURN & 0x4) {
163+
fault_print_str("\nStack: PSP", NULL);
164+
} else {
165+
fault_print_str("\nStack: MSP", NULL);
166+
}
147167
}
148168

149169
/* Prints thread info from a list */
@@ -194,17 +214,13 @@ void fault_print_str(char *fmtstr, uint32_t *values)
194214
char hex_str[9]={0};
195215

196216
while(fmtstr[i] != '\0') {
197-
if(fmtstr[i] == '\n' || fmtstr[i] == '\r') {
198-
serial_putc(&stdio_uart, '\r');
199-
} else {
200-
if(fmtstr[i]=='%') {
201-
hex_to_str(values[vidx++],hex_str);
202-
for(idx=7; idx>=0; idx--) {
203-
serial_putc(&stdio_uart, hex_str[idx]);
204-
}
205-
} else {
206-
serial_putc(&stdio_uart, fmtstr[i]);
217+
if(fmtstr[i]=='%') {
218+
hex_to_str(values[vidx++],hex_str);
219+
for(idx=7; idx>=0; idx--) {
220+
serial_putc(&stdio_uart, hex_str[idx]);
207221
}
222+
} else {
223+
serial_putc(&stdio_uart, fmtstr[i]);
208224
}
209225
i++;
210226
}

rtos/TARGET_CORTEX/TARGET_CORTEX_M/mbed_rtx_fault_handler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ typedef struct {
3737
uint32_t xPSR;
3838
uint32_t PSP;
3939
uint32_t MSP;
40+
uint32_t EXC_RETURN;
41+
uint32_t CONTROL;
4042
} mbed_fault_context_t;
4143

4244
//Fault type definitions

0 commit comments

Comments
 (0)