cancel
Showing results for 
Search instead for 
Did you mean: 

Using RTC in CM4 context

darla14
Senior

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

5 REPLIES 5
PatrickF
ST Employee

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.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

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

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

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hello @PatrickF​ 

I attach the call trace,

Its while getting the tick. Rest of the peripherals works well , if I comment this or run with this in engineering mode.

But as soon as I turn on the Production mode and debug this , I get this.

there is no change in the main code and it is as it is generated by CubeMX

if(IS_ENGINEERING_BOOT_MODE())

{

PeriphCommonClock_Config();

}

else

{

MX_IPCC_Init();

MX_OPENAMP_Init(RPMSG_REMOTE,NULL);

}

0693W00000NrbX0QAJ.png 

0693W00000NrbWgQAJ.png 

0693W00000NrbWRQAZ.png 

IS_ENGINEERING_BOOT_MODE is 0

Thanks in advance to look into this.

Best Regards,

D

Seems you are trying to init the RTC while it is already init by Linux when in production mode.

The code I have put should be enough to access RTC time/date.

The hardfault is likely coming from instruction before the GetTick, e.g. "SET_BIT(PWR->CR1..." which is not allowed in production mode (PWR is likely secured by Linux)

Regards,

Patrick

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.