diff --git a/src/bsp/platform/stm32fx/xi_bsp_time_stm32fx.c b/src/bsp/platform/stm32fx/xi_bsp_time_stm32fx.c index f34fc025..55dcadf0 100644 --- a/src/bsp/platform/stm32fx/xi_bsp_time_stm32fx.c +++ b/src/bsp/platform/stm32fx/xi_bsp_time_stm32fx.c @@ -13,17 +13,23 @@ #endif #include +static uint32_t ticks_at_start = 0; + void xi_bsp_time_init() { xi_bsp_time_sntp_init( NULL ); + if (xi_bsp_time_sntp_getseconds_posix() != 0) + { + ticks_at_start = HAL_GetTick(); + } } xi_time_t xi_bsp_time_getcurrenttime_seconds() { - return xi_bsp_time_sntp_getseconds_posix() + HAL_GetTick() / 1000; + return xi_bsp_time_sntp_getseconds_posix() + (HAL_GetTick()-ticks_at_start) / 1000; } xi_time_t xi_bsp_time_getcurrenttime_milliseconds() { - return xi_bsp_time_sntp_getseconds_posix() + HAL_GetTick() / 1000; + return xi_bsp_time_sntp_getseconds_posix() + (HAL_GetTick()-ticks_at_start) / 1000; }