Skip to content

Commit 26cb388

Browse files
committed
Use us_ticker_read while SDK is not ready
1 parent f12afde commit 26cb388

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

targets/TARGET_STM/hal_tick_common.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,19 @@
1717

1818
// Overwrite default HAL functions defined as "weak"
1919

20+
// This variable is set to 1 at the of mbed_sdk_init function.
21+
// The ticker_read_us function must not be called until the mbed_sdk_init is terminated.
22+
extern int mbed_sdk_inited;
23+
2024
uint32_t HAL_GetTick()
2125
{
22-
return ticker_read_us(get_us_ticker_data()) / 1000; // 1 ms tick is required for ST HAL
26+
// 1 ms tick is required for ST HAL driver
27+
if (mbed_sdk_inited) {
28+
return (ticker_read_us(get_us_ticker_data()) / 1000);
29+
}
30+
else {
31+
return (us_ticker_read() / 1000);
32+
}
2333
}
2434

2535
void HAL_SuspendTick(void)

targets/TARGET_STM/mbed_overrides.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
*/
2828
#include "cmsis.h"
2929

30+
int mbed_sdk_inited = 0;
31+
3032
// This function is called after RAM initialization and before main.
3133
void mbed_sdk_init()
3234
{
@@ -51,4 +53,6 @@ void mbed_sdk_init()
5153
AHB/APBx prescalers and Flash settings */
5254
SetSysClock();
5355
SystemCoreClockUpdate();
56+
57+
mbed_sdk_inited = 1;
5458
}

0 commit comments

Comments
 (0)