The following code starts counting at 12:00:00 AM after each MCU reset and doesn't reflect the real RTC value:
int main()
{
while(1) {
time_t seconds = time(NULL);
char buffer[32];
strftime(buffer, 32, "%I:%M:%S %p", localtime(&seconds));
printf("%s \r", buffer);
int i = 100000;
while(i--); // keep busy (sleep gives programming issues with STLinkV2 clone and printf cannot flush)
}
}
After investigation the issue was solved when putting this code snippet in mbed_sdk_init() in mbed_overrides.c of STM target between the #if DEVICE_RTC/#endif lines or calling rtc_init() before the main function:
#if defined __HAL_RCC_RTCAPB_CLK_ENABLE
__HAL_RCC_RTCAPB_CLK_ENABLE();
#endif /* __HAL_RCC_RTCAPB_CLK_ENABLE */
A test in CubeIDE shows this HAL_RTC_MspInit function:
Description of defect
The following code starts counting at 12:00:00 AM after each MCU reset and doesn't reflect the real RTC value:
After investigation the issue was solved when putting this code snippet in mbed_sdk_init() in mbed_overrides.c of STM target between the #if DEVICE_RTC/#endif lines or calling rtc_init() before the main function:
A test in CubeIDE shows this HAL_RTC_MspInit function:
Target(s) affected by this defect ?
MCU_STM32U575xG inherited from MCU_STM32U5
custom_targets.json
Toolchain(s) (name and version) displaying this defect ?
NA
What version of Mbed-os are you using (tag or sha) ?
Mbed 7.59.0
What version(s) of tools are you using. List all that apply (E.g. mbed-cli)
CLI2
How is this defect reproduced ?
Create a test project