I use this code to create millisecond resolution timestamps. secs = RTC_GetCounter(); ms = 1000 * ((RTC_XTAL_FREQUENCY - 1) - RTC_GetDivider()) / RTC_XTAL_FREQUENCY; I use the Standard Peripheral Library v3.0.0 functions instead of direct register accesses.