Skip to main content
Graduate
May 31, 2022
Question

Using RTC in CM4 context

  • May 31, 2022
  • 1 reply
  • 1101 views

Hello ,

I see from the stm32mpu wiki RTC is not available for CM4. I am porting one RTC project from F411 to CM4 .

0693W00000NqtdTQAR.png 

Is there any alternate to this which i can use having same functionality?

Br,

D

    This topic has been closed for replies.

    1 reply

    Technical Moderator
    May 31, 2022

    HI @darla14​ ,

    RTC and associated event (interrupts, alarms, etc..) belongs to Linux, but you could read time and date from Cortex-M4 using HAL functions and adding "stm32mp1xx_hal_rtc.c" in your project.

    e.g. something like this might work:

    #include "stm32mp1xx_hal_rtc.h"
    RTC_HandleTypeDef hrtc;
    RTC_TimeTypeDef sTime;
    RTC_DateTypeDef sDate;
     hrtc.Instance = RTC;
     /* RTC clock enable */
     __HAL_RCC_RTCAPB_CLK_ENABLE();
     HAL_RTC_GetTime(&hrtc, &sTime ,RTC_FORMAT_BIN);
     HAL_RTC_GetDate(&hrtc, &sDate ,RTC_FORMAT_BIN);

    Note that RTC might become not accessible when Linux is in low power.

    Depending on your usage, you might need some additional computation to adjust to Linux timezone as RTC is usually in UTC. See also https://wiki.st.com/stm32mpu/wiki/How_to_use_the_RTC for Linux information.

    Regards.

    darla14Author
    Graduate
    June 9, 2022

    in engineering mode I can see the rtc hours,minutes, seconds and sub-seconds increasing ...which is fine. but in production mode i am getting hard fault.

    is it even possible to use the rtc in the production mode in M4? How?

    if not what is the alternative to it on M4 side?

    best

    D

    Technical Moderator
    June 10, 2022

    Hi,

    Could you please precise in which function your get hardfault ?

    Maybe, as you tried in engineering mode, you have probably added some additional RTC init to make it working. Did you ensure the init linked to RTC (except what I listed above) are conditioned by "IS_ENGINEERING_BOOT_MODE()" ?

    Regards