RTC Losing time after power restart
Hello all,
I am working on RTC of STM32F401RC. I have connected a new CR2032 battery to VBAT.
My problem is that when I restart the power I lose time. I have disabled the calendar generation and setting time manually so there is no possibility of time reset due to SW. Apart from that, I also tried to set the backup register and read it after power restart, the backup register also resets to 0.
To make sure I also tried on other MCU STM32F407, and it still has the same issue. The RTC circuit for both F401 and F407 boards is the same and are populated on my custom designed boards.
In order to make sure the battery is not the issue, I used a new different battery, and also tried powering VBAT using 3.3V derived from different board and still the time gets reset.
Here is the schematic of my RTC circuit.

Main Code:

Here is my RTC init function:
static void MX_RTC_Init(void)
{
/* USER CODE BEGIN RTC_Init 0 */
/* USER CODE END RTC_Init 0 */
RTC_TimeTypeDef sTime = {0};
RTC_DateTypeDef sDate = {0};
/* USER CODE BEGIN RTC_Init 1 */
/* USER CODE END RTC_Init 1 */
/** Initialize RTC Only
*/
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 127;
hrtc.Init.SynchPrediv = 255;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN Check_RTC_BKUP */
/* USER CODE END Check_RTC_BKUP */
/* USER CODE BEGIN RTC_Init 2 */
/* USER CODE END RTC_Init 2 */
}
Please help me with this. I am kind of stuck and must solve this problem.
