Skip to main content
Senior
September 30, 2021
Question

RTC_TR and RTC_DR are not set on STM32H743

  • September 30, 2021
  • 12 replies
  • 3440 views

Hi,

I've used STM32CubeMX to configure my STM32H7 MCU, but RTC initial values which I set on CubeMX as default value are not set on RTC_TR and RTC_DR registers after debugging line by line when  MX_RTC_Init() is called. There is no fault reported or any hardfault..., and I've use LSI for RTC.

Please help in this simple issue which waste my time couple of days ...

Thanks.

This topic has been closed for replies.

12 replies

MHaji.1Author
Senior
October 3, 2021

Please some one help, on this topic ...

waclawek.jan
Super User
October 3, 2021

The 'H7 is an overly complicated design and I don't use it so maybe some step is different from the usual procedure for other STM32, but you are supposed to:

  • enable RTC clock in RCC
  • enable PWR clock in RCC (from reading RM0433 it appears that in 'H7 this is not necessary, as I don't see any bit in RCC registers which would accomplis this)
  • enable backup domain access by setting PWR_CR1.DBP (see Accessing the backup domain subchapter in RM0433), read back PWR_CR1 content (e.g. in debugger) to check
  • enable LSI in RCC_CSR and make sure it runs by checking the LSIRDY bit in the same register
  • in RCC_BDCR, select LSI as RTC clock in RTCSEL field and enable RTC by setting RTCEN bit; read back to confirm the settings are performed as intended (if not, you may need to reset the backup domain)
  • in RTC, you need to unlock RTC writes by writing the prescribed sequence to RTC_WPR, see RTC register write protection subchapter in RTC chapter of RM
  • enter RTC initialization mode by setting RTC_ISR.INIT=1 and waiting until RTC_ISR.INITF is set to 1 - see Calendar initialization and configuration subchapter
  • write time and date to RTC_TR and RTC_DR respectively
  • exit the initialization mode by clearing RTC_ISR.INIT

JW

MHaji.1Author
Senior
October 3, 2021

Thanks for your reply,

I should add, I can read RTC_TR and RTC_DR, but their values are started always from zero each time I start my code and in the following it work properly (count time), .. It seems RTC clock works properly but the problem is where I want set these registers...

Thanks.

waclawek.jan
Super User
October 3, 2021

> their values are started always from zero each time I start my code

Do you have battery connected to VBAT pin? If not, RTC is reset whenever VDD is removed.

If date/time is reset when system reset occurs without actually removing power, then it's software issue, but I don't use Cube and can't help there.

JW

MHaji.1Author
Senior
October 3, 2021

Yes, when system reset, date/Time is lost....

How we can find out removing write protection by writing 0xCA and 0x53 is done properly... Is there any other register to check for insurance?

waclawek.jan
Super User
October 3, 2021

> How we can find out removing write protection by writing 0xCA and 0x53 is done properly... Is there any other register to check for insurance?

You can't check it directly, but if it's not done properly, you won't be able to change RTC_ISR.INIT.

JW

MHaji.1Author
Senior
October 4, 2021

RTC_ISR.INIT is changed... but RTC_TR value does not change...:crying_face:

waclawek.jan
Super User
October 4, 2021

> RTC_TR value does not change...

How do you check it? Do you read RTC_DR after reading RTC_TR?

JW

MHaji.1Author
Senior
October 4, 2021

Once I write RTC_DR or RTC_TR, check its register on debugger just after witting, nothing changed ...

After initializing when my threads starts... I read RTC_TR and RTC_DR... It works properly but all start from zero and nothing was written on their registers.

There is something wrong here which I can not write any thing on RTC_DR and RTC_TR as initial time...

waclawek.jan
Super User
October 4, 2021

While in INIT mode, you won't see changes made to DR and TR registers (*).

You have to exit INIT mode and wait for reload (clear RSF and wait until hardware sets it), then you will see the new values of TR/DR.

JW

(*) unless you set RTC->CR.BYPSHAD

MHaji.1Author
Senior
October 5, 2021

1- I've checked all things, LSI is works fine, because I can read time and calendar...(Time is alive)

2- First write protection is disabled... I assume that it is worked because INITF and INIT could be set in next step.

2- I checked RTC_ISR when goning to Init mode, INITF and INIT are set and RSF is zero.

3- After assigning a value to RTC_TR, next step is exiting from init mode.

4- I checked, when ISR_INITF and RSF set to zero after some tick, RSF became one....

5- enabling write protection....

After all these steps which their code is developed by CubeMX and I checked all steps and registers... unfortunately RTC_DR and RTC_TR values dose not changed...and they start from some random numbers usually zero and one... It is so weird, I stuck in this simple part for a week....

Please check and help me... I have checked all thing which we discussed here.. no progress :loudly_crying_face:

@Community member​ 

@Community member​ 

Tesla DeLorean
Guru
October 5, 2021

Is this a custom board?

Have you tried porting/using some existing examples, perhaps built to printf() to your serial debug terminal?

STM32Cube_FW_H7_V1.8.0\Projects\STM32H743I-EVAL\Examples\RTC\RTC_TimeStamp\Src\main.c

Make sure clocking sources are working and correctly selected. Output LSI via MCO/PA8, or other pins you might be able to expose it on. Check it is running via RCC/PWR peripheral registers.

Write some code to dump all the interrelated registers, its going to be impossible to play guess-whats-wrong remotely, without some clean/clear code and full register dumps. No one is going to want to dig into register level code as it is involved and expensive. Work all the HAL examples.

Assume the RTC is going to be running several hundred times slower than the MCU, watch for timing, and write buffer flushing expectations.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..