diff --git a/targets/TARGET_STM/hal_tick_common.c b/targets/TARGET_STM/hal_tick_common.c index b5f3aff9b3..d9421729ba 100644 --- a/targets/TARGET_STM/hal_tick_common.c +++ b/targets/TARGET_STM/hal_tick_common.c @@ -17,9 +17,19 @@ // Overwrite default HAL functions defined as "weak" +// This variable is set to 1 at the of mbed_sdk_init function. +// The ticker_read_us function must not be called until the mbed_sdk_init is terminated. +extern int mbed_sdk_inited; + uint32_t HAL_GetTick() { - return ticker_read_us(get_us_ticker_data()) / 1000; // 1 ms tick is required for ST HAL + // 1 ms tick is required for ST HAL driver + if (mbed_sdk_inited) { + return (ticker_read_us(get_us_ticker_data()) / 1000); + } + else { + return (us_ticker_read() / 1000); + } } void HAL_SuspendTick(void) diff --git a/targets/TARGET_STM/mbed_overrides.c b/targets/TARGET_STM/mbed_overrides.c index f2c1d71175..9f794ed339 100644 --- a/targets/TARGET_STM/mbed_overrides.c +++ b/targets/TARGET_STM/mbed_overrides.c @@ -27,6 +27,8 @@ */ #include "cmsis.h" +int mbed_sdk_inited = 0; + // This function is called after RAM initialization and before main. void mbed_sdk_init() { @@ -51,4 +53,6 @@ void mbed_sdk_init() AHB/APBx prescalers and Flash settings */ SetSysClock(); SystemCoreClockUpdate(); + + mbed_sdk_inited = 1; }