@@ -39,41 +39,49 @@ mbed_fault_context_t fault_context;
3939mbed_fault_context_t * const mbed_fault_context = & fault_context ;
4040#endif
4141
42+ extern bool mbed_error_in_progress ;
43+
4244//This is a handler function called from Fault handler to print the error information out.
4345//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.
4446void mbed_fault_handler (uint32_t fault_type , const mbed_fault_context_t * mbed_fault_context_in )
4547{
4648 mbed_error_status_t faultStatus = MBED_SUCCESS ;
4749
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 ();
7581
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+ }
7785
7886 //Now call mbed_error, to log the error and halt the system
7987 mbed_error (faultStatus , "Fault exception" , (unsigned int )mbed_fault_context_in , NULL , 0 );
0 commit comments