32
32
void print_context_info (void );
33
33
34
34
#if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
35
- //Global for populating the context in exception handler
36
- mbed_fault_context_t * const mbed_fault_context = (mbed_fault_context_t * )(FAULT_CONTEXT_LOCATION );
35
+ //Global for populating the context in exception handler
36
+ mbed_fault_context_t * const mbed_fault_context = (mbed_fault_context_t * )(FAULT_CONTEXT_LOCATION );
37
37
#else
38
- mbed_fault_context_t fault_context ;
39
- mbed_fault_context_t * const mbed_fault_context = (mbed_fault_context_t * )& fault_context ;
40
- #endif
38
+ mbed_fault_context_t fault_context ;
39
+ mbed_fault_context_t * const mbed_fault_context = (mbed_fault_context_t * ) & fault_context ;
40
+ #endif
41
41
42
42
//This is a handler function called from Fault handler to print the error information out.
43
43
//This runs in fault context and uses special functions(defined in mbed_rtx_fault_handler.c) to print the information without using C-lib support.
44
- void mbed_fault_handler (uint32_t fault_type , void * mbed_fault_context_in )
44
+ void mbed_fault_handler (uint32_t fault_type , void * mbed_fault_context_in )
45
45
{
46
46
mbed_error_status_t faultStatus = MBED_SUCCESS ;
47
-
47
+
48
48
mbed_error_printf ("\n++ MbedOS Fault Handler ++\n\nFaultType: " );
49
-
50
- switch ( fault_type ) {
51
- case MEMMANAGE_FAULT_EXCEPTION :
52
- mbed_error_printf ("MemManageFault" );
53
- faultStatus = MBED_ERROR_MEMMANAGE_EXCEPTION ;
54
- break ;
55
-
56
- case BUS_FAULT_EXCEPTION :
57
- mbed_error_printf ("BusFault" );
58
- faultStatus = MBED_ERROR_BUSFAULT_EXCEPTION ;
59
- break ;
60
-
61
- case USAGE_FAULT_EXCEPTION :
62
- mbed_error_printf ("UsageFault" );
63
- faultStatus = MBED_ERROR_USAGEFAULT_EXCEPTION ;
64
- break ;
65
-
66
- //There is no way we can hit this code without getting an exception, so we have the default treated like hardfault
67
- case HARD_FAULT_EXCEPTION :
68
- default :
69
- mbed_error_printf ("HardFault" );
70
- faultStatus = MBED_ERROR_HARDFAULT_EXCEPTION ;
71
- break ;
49
+
50
+ switch ( fault_type ) {
51
+ case MEMMANAGE_FAULT_EXCEPTION :
52
+ mbed_error_printf ("MemManageFault" );
53
+ faultStatus = MBED_ERROR_MEMMANAGE_EXCEPTION ;
54
+ break ;
55
+
56
+ case BUS_FAULT_EXCEPTION :
57
+ mbed_error_printf ("BusFault" );
58
+ faultStatus = MBED_ERROR_BUSFAULT_EXCEPTION ;
59
+ break ;
60
+
61
+ case USAGE_FAULT_EXCEPTION :
62
+ mbed_error_printf ("UsageFault" );
63
+ faultStatus = MBED_ERROR_USAGEFAULT_EXCEPTION ;
64
+ break ;
65
+
66
+ //There is no way we can hit this code without getting an exception, so we have the default treated like hardfault
67
+ case HARD_FAULT_EXCEPTION :
68
+ default :
69
+ mbed_error_printf ("HardFault" );
70
+ faultStatus = MBED_ERROR_HARDFAULT_EXCEPTION ;
71
+ break ;
72
72
}
73
73
mbed_error_printf ("\n\nContext:" );
74
74
print_context_info ();
75
-
75
+
76
76
mbed_error_printf ("\n\n-- MbedOS Fault Handler --\n\n" );
77
-
77
+
78
78
//Now call mbed_error, to log the error and halt the system
79
- mbed_error ( faultStatus , "Fault exception" , mbed_fault_context -> PC_reg , NULL , 0 );
80
-
79
+ mbed_error (faultStatus , "Fault exception" , mbed_fault_context -> PC_reg , NULL , 0 );
80
+
81
81
}
82
82
83
83
MBED_NOINLINE void print_context_info (void )
84
84
{
85
85
//Context Regs
86
- for (int i = 0 ; i < 13 ;i ++ ) {
87
- mbed_error_printf ("\nR%-4d: %08" PRIX32 , i , ((uint32_t * )(mbed_fault_context ))[i ]);
86
+ for (int i = 0 ; i < 13 ; i ++ ) {
87
+ mbed_error_printf ("\nR%-4d: %08" PRIX32 , i , ((uint32_t * )(mbed_fault_context ))[i ]);
88
88
}
89
-
89
+
90
90
mbed_error_printf ("\nSP : %08" PRIX32
91
91
"\nLR : %08" PRIX32
92
92
"\nPC : %08" PRIX32
93
93
"\nxPSR : %08" PRIX32
94
94
"\nPSP : %08" PRIX32
95
- "\nMSP : %08" PRIX32 , mbed_fault_context -> SP_reg , mbed_fault_context -> LR_reg , mbed_fault_context -> PC_reg ,
96
- mbed_fault_context -> xPSR , mbed_fault_context -> PSP , mbed_fault_context -> MSP );
97
-
95
+ "\nMSP : %08" PRIX32 , mbed_fault_context -> SP_reg , mbed_fault_context -> LR_reg , mbed_fault_context -> PC_reg ,
96
+ mbed_fault_context -> xPSR , mbed_fault_context -> PSP , mbed_fault_context -> MSP );
97
+
98
98
//Capture CPUID to get core/cpu info
99
99
mbed_error_printf ("\nCPUID: %08" PRIX32 , SCB -> CPUID );
100
-
100
+
101
101
#if !defined(TARGET_M0 ) && !defined(TARGET_M0P )
102
102
//Capture fault information registers to infer the cause of exception
103
103
mbed_error_printf ("\nHFSR : %08" PRIX32
104
- "\nMMFSR: %08" PRIX32
105
- "\nBFSR : %08" PRIX32
106
- "\nUFSR : %08" PRIX32
107
- "\nDFSR : %08" PRIX32
108
- "\nAFSR : %08" PRIX32 ////Split/Capture CFSR into MMFSR, BFSR, UFSR
109
- , SCB -> HFSR , (0xFF & SCB -> CFSR ), ((0xFF00 & SCB -> CFSR ) >> 8 ), ((0xFFFF0000 & SCB -> CFSR ) >> 16 ), SCB -> DFSR , SCB -> AFSR );
110
-
104
+ "\nMMFSR: %08" PRIX32
105
+ "\nBFSR : %08" PRIX32
106
+ "\nUFSR : %08" PRIX32
107
+ "\nDFSR : %08" PRIX32
108
+ "\nAFSR : %08" PRIX32 ////Split/Capture CFSR into MMFSR, BFSR, UFSR
109
+ , SCB -> HFSR , (0xFF & SCB -> CFSR ), ((0xFF00 & SCB -> CFSR ) >> 8 ), ((0xFFFF0000 & SCB -> CFSR ) >> 16 ), SCB -> DFSR , SCB -> AFSR );
110
+
111
111
//Print MMFAR only if its valid as indicated by MMFSR
112
112
if ((0xFF & SCB -> CFSR ) & 0x80 ) {
113
113
mbed_error_printf ("\nMMFAR: %08" PRIX32 , SCB -> MMFAR );
@@ -117,39 +117,40 @@ MBED_NOINLINE void print_context_info(void)
117
117
mbed_error_printf ("\nBFAR : %08" PRIX32 , SCB -> BFAR );
118
118
}
119
119
#endif
120
-
120
+
121
121
//Print Mode
122
122
if (mbed_fault_context -> EXC_RETURN & 0x8 ) {
123
123
mbed_error_printf ("\nMode : Thread" );
124
124
//Print Priv level in Thread mode - We capture CONTROL reg which reflects the privilege.
125
- //Note that the CONTROL register captured still reflects the privilege status of the
125
+ //Note that the CONTROL register captured still reflects the privilege status of the
126
126
//thread mode eventhough we are in Handler mode by the time we capture it.
127
- if (mbed_fault_context -> CONTROL & 0x1 ) {
128
- mbed_error_printf ("\nPriv : User" );
127
+ if (mbed_fault_context -> CONTROL & 0x1 ) {
128
+ mbed_error_printf ("\nPriv : User" );
129
129
} else {
130
- mbed_error_printf ("\nPriv : Privileged" );
131
- }
130
+ mbed_error_printf ("\nPriv : Privileged" );
131
+ }
132
132
} else {
133
- mbed_error_printf ("\nMode : Handler" );
134
- mbed_error_printf ("\nPriv : Privileged" );
133
+ mbed_error_printf ("\nMode : Handler" );
134
+ mbed_error_printf ("\nPriv : Privileged" );
135
135
}
136
136
//Print Return Stack
137
137
if (mbed_fault_context -> EXC_RETURN & 0x4 ) {
138
- mbed_error_printf ("\nStack: PSP" );
138
+ mbed_error_printf ("\nStack: PSP" );
139
139
} else {
140
- mbed_error_printf ("\nStack: MSP" );
140
+ mbed_error_printf ("\nStack: MSP" );
141
141
}
142
142
}
143
143
144
- mbed_error_status_t mbed_get_reboot_fault_context (mbed_fault_context_t * fault_context )
144
+ mbed_error_status_t mbed_get_reboot_fault_context (mbed_fault_context_t * fault_context )
145
145
{
146
146
mbed_error_status_t status = MBED_MAKE_ERROR (MBED_MODULE_PLATFORM , MBED_ERROR_CODE_ITEM_NOT_FOUND );
147
147
#if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
148
- if (fault_context == NULL )
148
+ if (fault_context == NULL ) {
149
149
return MBED_MAKE_ERROR (MBED_MODULE_PLATFORM , MBED_ERROR_CODE_INVALID_ARGUMENT );
150
+ }
150
151
memcpy (fault_context , mbed_fault_context , sizeof (mbed_fault_context_t ));
151
152
status = MBED_SUCCESS ;
152
- #endif
153
+ #endif
153
154
return status ;
154
155
}
155
156
0 commit comments