Skip to main content
ADsil
Associate
November 27, 2018
Question

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

  • November 27, 2018
  • 6 replies
  • 3901 views

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?

    This topic has been closed for replies.

    6 replies

    Tesla DeLorean
    Guru
    November 27, 2018

    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 VenmoUp vote any posts that you find helpful, it shows what's working..
    ADsil
    ADsilAuthor
    Associate
    November 28, 2018

    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
    Visitor II
    July 20, 2019

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

    waclawek.jan
    Super User
    July 20, 2019

    Post a minimal code demonstrating your problem.

    JW

    lckati31
    Visitor II
    July 21, 2019

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

    Piranha
    Principal III
    July 21, 2019
    // 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));

    lckati31
    Visitor II
    July 21, 2019

    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
    Principal III
    July 21, 2019
    	//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?

    waclawek.jan
    Super User
    July 21, 2019

    What is

    rtc_device_apis

    ?

    JW