@@ -168,7 +168,7 @@ static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsign
168
168
//Increment error count
169
169
error_count ++ ;
170
170
171
- //Capture the fist system error and store it
171
+ //Capture the first system error and store it
172
172
if (error_count == 1 ) { //first error
173
173
memcpy (& first_error_ctx , & current_error_ctx , sizeof (mbed_error_ctx ));
174
174
}
@@ -281,7 +281,10 @@ WEAK MBED_NORETURN mbed_error_status_t mbed_error(mbed_error_status_t error_stat
281
281
last_error_ctx .is_error_processed = 0 ;//Set the flag that this is a new error
282
282
//Update the struct with crc
283
283
last_error_ctx .crc_error_ctx = compute_crc32 ( (unsigned char * )& last_error_ctx , ((uint32_t )& (last_error_ctx .crc_error_ctx ) - (uint32_t )& last_error_ctx ) );
284
+ //Protect report_error_ctx while we update it
285
+ core_util_critical_section_enter ();
284
286
memcpy (report_error_ctx , & last_error_ctx , sizeof (mbed_error_ctx ));
287
+ core_util_critical_section_exit ();
285
288
//We need not call delete_mbed_crc(crc_obj) here as we are going to reset the system anyway, and calling delete while handling a fatal error may cause nested exception
286
289
#if MBED_CONF_PLATFORM_FATAL_ERROR_AUTO_REBOOT_ENABLED
287
290
system_reset ();//do a system reset to get the system rebooted
@@ -310,7 +313,10 @@ mbed_error_status_t mbed_set_error_hook(mbed_error_hook_t error_hook_in)
310
313
mbed_error_status_t mbed_reset_reboot_error_info ()
311
314
{
312
315
#if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
313
- memset (report_error_ctx , 0 , sizeof (mbed_error_ctx ) );
316
+ //Protect for thread safety
317
+ core_util_critical_section_enter ();
318
+ memset (report_error_ctx , 0 , sizeof (mbed_error_ctx ) );
319
+ core_util_critical_section_exit ();
314
320
#endif
315
321
return MBED_SUCCESS ;
316
322
}
@@ -321,10 +327,12 @@ mbed_error_status_t mbed_reset_reboot_count()
321
327
#if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
322
328
if (is_reboot_error_valid ) {
323
329
uint32_t crc_val = 0 ;
330
+ core_util_critical_section_enter ();
324
331
report_error_ctx -> error_reboot_count = 0 ;//Set reboot count to 0
325
332
//Update CRC
326
333
crc_val = compute_crc32 ( (unsigned char * )report_error_ctx , ((uint32_t )& (report_error_ctx -> crc_error_ctx ) - (uint32_t )report_error_ctx ) );
327
334
report_error_ctx -> crc_error_ctx = crc_val ;
335
+ core_util_critical_section_exit ();
328
336
return MBED_SUCCESS ;
329
337
}
330
338
#endif
0 commit comments