cancel
Showing results for 
Search instead for 
Did you mean: 

How to unlock the write protection for the Real time clock in stm32f407

ADsil
Associate

Hi,

I'm currently trying out the configuration of RTC in the STM32F407G-DISC1 using Atollic truestudio.

I was successful in enabling RTC registers write access by setting the DBP bit in PWR_CR registers after system reset, but I'm unable to write the key values (0xca ,0x53) in the RTC_WPR registers so as to unlock the write protection on all the RTC registers.

How to fix this problem?

9 REPLIES 9

Check PWR and BKP domain clocks are on.

There are delay requirements in the unlock process, the library gets around this by using function calls, but if coded as linear instructions will likely fail.

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

Hi, Thanks for the insight!!

I have configured the various clocks accordingly and now the RTC is running but it starts from the prewriiten register values, Im still unable to write values in WPR and configure the date and time as I want.

lckati31
Associate II

Did you find the solution to this? I'm facing the same problem and unable to detect any fault.

Post a minimal code demonstrating your problem.

JW

This is the code we have written to set date and time. We are still working on getting the date and time.

Piranha
Chief II
// 4) wait till LSI is ready when LSIRDY is set
	  	while(1)
		{
			  if((RCC->CSR & RCC_CSR_LSIRDY)==1)
			  break;
		}
     			 
// 5) Enable LSI clock by LSION bit in RCC_CSR 
	
	  	RCC->CSR|=1UL;              //Enable LSI clock by enabling LSION bit in RCC_CSR

You must enable clock first and then wait for it to become stable (ready). Also look at LSI oscillator characteristics in datasheet. It has 17-47 kHz frequency "accuracy"... And that loop can be written as simple as:

while (!(RCC->CSR & RCC_CSR_LSIRDY));

Thanks for the feed. I made the necessary changes you mentioned but still the write protection isn't disabling. Also even though I'm enabling LSI clock, the HSI clock bit is also enabling while debugging. Do you have any idea why?

Piranha
Chief II
	//clear RSF flag
	RTC->ISR |=(0x00<<5);

Do You understand that it's useless to shift a zero or make OR with it? This line is writing ISR register value to itself and the effect is unpredictable and definitely not what was intended. Anyway RSF bit is for reading values, not writing. Reference manual section 26.3.5 describes initialization and configuration very clearly. What is the problem implementing it as described there?

What is

rtc_device_apis

?

JW