Skip to content

Commit 9523bcf

Browse files
committed
Use elapsed time only for 16bit timer
1 parent fcdd529 commit 9523bcf

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

targets/TARGET_STM/hal_tick_common.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,24 @@
1414
* limitations under the License.
1515
*/
1616
#include "hal/us_ticker_api.h"
17+
#include "hal_tick.h"
1718

1819
// Overwrite default HAL functions defined as "weak"
1920

2021
// This variable is set to 1 at the of mbed_sdk_init function.
2122
// The ticker_read_us function must not be called until the mbed_sdk_init is terminated.
2223
extern int mbed_sdk_inited;
2324

25+
#if TIM_MST_16BIT
2426
// Variables also reset in HAL_InitTick()
2527
uint32_t prev_time = 0;
2628
uint32_t elapsed_time = 0;
29+
#endif
2730

2831
// 1 ms tick is required for ST HAL driver
2932
uint32_t HAL_GetTick()
3033
{
34+
#if TIM_MST_16BIT
3135
uint32_t new_time;
3236
if (mbed_sdk_inited) {
3337
// Apply the latest time recorded just before the sdk is inited
@@ -41,6 +45,14 @@ uint32_t HAL_GetTick()
4145
prev_time = new_time;
4246
return (elapsed_time / 1000);
4347
}
48+
#else // 32-bit timer
49+
if (mbed_sdk_inited) {
50+
return (ticker_read_us(get_us_ticker_data()) / 1000);
51+
}
52+
else {
53+
return (us_ticker_read() / 1000);
54+
}
55+
#endif
4456
}
4557

4658
void HAL_SuspendTick(void)

0 commit comments

Comments
 (0)