File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change 19
19
#if TIM_MST_16BIT
20
20
21
21
extern TIM_HandleTypeDef TimMasterHandle ;
22
+ extern uint32_t prev_time ;
23
+ extern uint32_t elapsed_time ;
22
24
23
25
volatile uint32_t PreviousVal = 0 ;
24
26
@@ -108,6 +110,10 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
108
110
TIM_MST_DBGMCU_FREEZE ;
109
111
#endif
110
112
113
+ // Used by HAL_GetTick()
114
+ prev_time = 0 ;
115
+ elapsed_time = 0 ;
116
+
111
117
return HAL_OK ;
112
118
}
113
119
Original file line number Diff line number Diff line change 21
21
// The ticker_read_us function must not be called until the mbed_sdk_init is terminated.
22
22
extern int mbed_sdk_inited ;
23
23
24
+ // Variables also reset in HAL_InitTick()
25
+ uint32_t prev_time = 0 ;
26
+ uint32_t elapsed_time = 0 ;
27
+
28
+ // 1 ms tick is required for ST HAL driver
24
29
uint32_t HAL_GetTick ()
25
30
{
26
- // 1 ms tick is required for ST HAL driver
31
+ uint32_t new_time ;
27
32
if (mbed_sdk_inited ) {
28
- return (ticker_read_us (get_us_ticker_data ()) / 1000 );
33
+ // Apply the latest time recorded just before the sdk is inited
34
+ new_time = ticker_read_us (get_us_ticker_data ()) + prev_time ;
35
+ prev_time = 0 ; // Use this time only once
36
+ return (new_time / 1000 );
29
37
}
30
38
else {
31
- return (us_ticker_read () / 1000 );
39
+ new_time = us_ticker_read ();
40
+ elapsed_time += (new_time - prev_time ) & 0xFFFF ; // Only use the lower 16 bits
41
+ prev_time = new_time ;
42
+ return (elapsed_time / 1000 );
32
43
}
33
44
}
34
45
You can’t perform that action at this time.
0 commit comments