Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time(NULL) not returning real RTC value after reboot #15487

Closed
lefebvresam opened this issue Jan 16, 2024 · 1 comment
Closed

time(NULL) not returning real RTC value after reboot #15487

lefebvresam opened this issue Jan 16, 2024 · 1 comment

Comments

@lefebvresam
Copy link

lefebvresam commented Jan 16, 2024

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:

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:

    /* RTC clock enable */
    __HAL_RCC_RTC_ENABLE();
    __HAL_RCC_RTCAPB_CLK_ENABLE();
    __HAL_RCC_RTCAPB_CLKAM_ENABLE();

Target(s) affected by this defect ?

MCU_STM32U575xG inherited from MCU_STM32U5

custom_targets.json

{
    "MCU_STM32U575xG": {
        "inherits": [
            "MCU_STM32U5"
        ],
        "public": false,
        "mbed_rom_size": "0x100000",
        "mbed_ram_size": "0xc0000",        
        "extra_labels_add": [
            "STM32U575xG"
        ],
        "macros_add": [
            "STM32U575xx"
        ]
    },
    "HMC20": {
        "inherits": [
            "MCU_STM32U575xG"
        ],
        "overrides": {
            "clock_source" : "USE_PLL_HSE_XTAL",
            "lse_available" : "1",
            "lse_drive_load_level" : "RCC_LSEDRIVE_HIGH"
        },
        "macros_add": [
            "HSE_VALUE=10000000UL"
        ],
        "device_name": "HMC20"
    }
}

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

@lefebvresam
Copy link
Author

Handled in mbed-ce#210

Issue Workflow automation moved this from Needs Triage to Done Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants