File tree Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change 1919
2020#include "hal/us_ticker_api.h"
2121#include "us_ticker_defines.h"
22+ #include "mbed_critical.h"
2223
2324// This variable is set to 1 at the of mbed_sdk_init function.
2425// The ticker_read_us function must not be called until the mbed_sdk_init is terminated.
@@ -50,6 +51,9 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
5051
5152uint32_t HAL_GetTick ()
5253{
54+ // Prevent a task switch causing errors since this function isn't re-entrant
55+ core_util_critical_section_enter ();
56+
5357 uint32_t new_time = us_ticker_read ();
5458 uint32_t elapsed_time = (((new_time - prev_time ) & US_TICKER_MASK ) + prev_tick_remainder );
5559 prev_time = new_time ;
@@ -67,6 +71,8 @@ uint32_t HAL_GetTick()
6771 prev_tick_remainder = elapsed_time % 1000 ;
6872 }
6973 total_ticks += elapsed_ticks ;
74+
75+ core_util_critical_section_exit ();
7076 return total_ticks ;
7177}
7278
You can’t perform that action at this time.
0 commit comments