@@ -39,41 +39,49 @@ mbed_fault_context_t fault_context;
39
39
mbed_fault_context_t * const mbed_fault_context = & fault_context ;
40
40
#endif
41
41
42
+ extern bool mbed_error_in_progress ;
43
+
42
44
//This is a handler function called from Fault handler to print the error information out.
43
45
//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
46
void mbed_fault_handler (uint32_t fault_type , const mbed_fault_context_t * mbed_fault_context_in )
45
47
{
46
48
mbed_error_status_t faultStatus = MBED_SUCCESS ;
47
49
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 ;
72
- }
73
- mbed_error_printf ("\n\nContext:" );
74
- print_context_info ();
50
+ /* Need to set the flag to ensure prints do not trigger a "mutex in ISR" trap
51
+ * if they're first prints since boot and we have to init the I/O system.
52
+ */
53
+ if (!core_util_atomic_exchange_bool (& mbed_error_in_progress , true)) {
54
+ mbed_error_printf ("\n++ MbedOS Fault Handler ++\n\nFaultType: " );
55
+
56
+ switch (fault_type ) {
57
+ case MEMMANAGE_FAULT_EXCEPTION :
58
+ mbed_error_printf ("MemManageFault" );
59
+ faultStatus = MBED_ERROR_MEMMANAGE_EXCEPTION ;
60
+ break ;
61
+
62
+ case BUS_FAULT_EXCEPTION :
63
+ mbed_error_printf ("BusFault" );
64
+ faultStatus = MBED_ERROR_BUSFAULT_EXCEPTION ;
65
+ break ;
66
+
67
+ case USAGE_FAULT_EXCEPTION :
68
+ mbed_error_printf ("UsageFault" );
69
+ faultStatus = MBED_ERROR_USAGEFAULT_EXCEPTION ;
70
+ break ;
71
+
72
+ //There is no way we can hit this code without getting an exception, so we have the default treated like hardfault
73
+ case HARD_FAULT_EXCEPTION :
74
+ default :
75
+ mbed_error_printf ("HardFault" );
76
+ faultStatus = MBED_ERROR_HARDFAULT_EXCEPTION ;
77
+ break ;
78
+ }
79
+ mbed_error_printf ("\n\nContext:" );
80
+ print_context_info ();
75
81
76
- mbed_error_printf ("\n\n-- MbedOS Fault Handler --\n\n" );
82
+ mbed_error_printf ("\n\n-- MbedOS Fault Handler --\n\n" );
83
+ core_util_atomic_store_bool (& mbed_error_in_progress , false);
84
+ }
77
85
78
86
//Now call mbed_error, to log the error and halt the system
79
87
mbed_error (faultStatus , "Fault exception" , (unsigned int )mbed_fault_context_in , NULL , 0 );
0 commit comments