cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to maintain RTC ticking without any shifts while performing a power reset?

tarasov.alex.m
Associate III

/*UPDATE*/

It turned out that im my case the problem was in the start up routine:

There was a "Start up" project (written not by me) that was downloaded at 0 flash address and it was jumping to another address where my project was located.

I did not know that in this "Start up" project there was an RTC initialization (which prevented my RTC from running continuously).

Everything below this sentence is what I wrote before I knew where the problem is.

Good day!

I'm using RTC in a STM32F407VG controller.

I configured RTC_ALARM_A to generate an interrupt every second (this indicates when a second changes in RTC). By this interrupt, an oscilloscope and a reference 1Hz clock from another device (that is not being reset) I watch whether my RTC is ticking consistently.

With this setting it can be seen if MCU's RTC is shifting during power reset. And that's exactly what I'm observing (don't know the absolute value of the time shift, but I see that the phase of MCU's 1Hz clock output is changing randomly after power reset is done).

Can anyone tell me if there is anything that can be done to make RTC run continгously, even when a power reset is performed?

Also this things need to be mentioned:

  • I do use a battery for RTC and clocks are ticking while MCU is not powered.
  • I am not reinitializing the RTC periphery each time.
  • Backup registers preserve their values, so no "Backup domain reset" occures.
  • RTC clock is consistent during "System reset", this behavior is only seen when "Power reset" is done
15 REPLIES 15
turboscrew
Senior III

The startup code (start.S). You can also put a breakpoint there. You don't have to wait for main.

 Usually, though, there is just the reset vector entry that has the address of _start, and the code under that label only branches to main.

turboscrew
Senior III

The rtc_date_time_config_frst_time() puts the RTC_SECRET_DATA to the backup register 0?

That's the way I've been doing too.

tarasov.alex.m
Associate III

MCU starts in a Reset_Handler, which in my case is this:

THUMB
        PUBWEAK Reset_Handler
        SECTION .text:CODE:REORDER:NOROOT(2)
Reset_Handler
 
        LDR     R0, =SystemInit
        BLX     R0
        LDR     R0, =__iar_program_start
        BX      R0

"SystemItinit" contains this code:

void SystemInit(void)
{
  /* FPU settings ------------------------------------------------------------*/
  #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
    SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2));  /* set CP10 and CP11 Full Access */
  #endif
  /* Reset the RCC clock configuration to the default reset state ------------*/
  /* Set HSION bit */
  RCC->CR |= (uint32_t)0x00000001;
 
  /* Reset CFGR register */
  RCC->CFGR = 0x00000000;
 
  /* Reset HSEON, CSSON and PLLON bits */
  RCC->CR &= (uint32_t)0xFEF6FFFF;
 
  /* Reset PLLCFGR register */
  RCC->PLLCFGR = 0x24003010;
 
  /* Reset HSEBYP bit */
  RCC->CR &= (uint32_t)0xFFFBFFFF;
 
  /* Disable all interrupts */
  RCC->CIR = 0x00000000;
 
  /* Configure the Vector Table location add offset address ------------------*/
  SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
}

As you see, nothing here appeals to RTC or LSE.

tarasov.alex.m
Associate III

Oh, I found the problem.

I began working on this project when a bunch of coding had allready been done, so it was not me who made the start up routine.

There is a "Start up" project that is downloaded at 0 flash address and it jumps to another address where another project (the one I'm working in) is located.

It turned out that there is a useless RTC initialization (RTC is not being used there).

Nevertheless it was quite silly of me not to think about that possibility.

@turboscrew​ and @Community member​ really appreciate your help!

Yes, that's it.

Hi!

2 years later.

If I'm using that IF-statement and check if that is true, then I'm going to initizile the RTC?

Does the RTC run, even if the Vdd is not connected to a power supply? (Yes, Vbat is connected to 3 V).