cancel
Showing results for 
Search instead for 
Did you mean: 

Using VBAT (CR2032 battery) in STM32H747I-DISCO board

Louie88
Associate III

Hi all,

I would like to keep RTC value (and keep the RTC working) during power off of the disco board, so I am planning to cut SB16 (soft bridge) from+3.3V and solder an external CR2032 +V battery to the board. My first questions are:

  1. How will I know that the battery is connected to VBAT pin of the MCU during initialization of RTC (from software)? The initialization generated by STM32CubeMX overwrites the date and time registers of the RTC. If the battery is connected the initialization could not modify the RTC clock value and I think it should do nothing with the battery backup RTC... I guess if the RTC is enabled during power on initialization then I have skip RTCInit(). Is this okay?
  2. Is there any example or tech paper how to use external battery for RTC and backup RAM? (Hidden secrets)
  3. Is the +3V CR2032 battery good pick (the 3V voltage) for backing up RTC?
  4. Any notes are welcome!

Thanks,

Louis

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SofLit
ST Employee

Hello,

For your first and  second question, you can refer to any Cube package offering RTC Calendar example:

This one for example: https://github.com/STMicroelectronics/STM32CubeF7/blob/master/Projects/STM32F769I_EVAL/Examples/RTC/RTC_Calendar/Src/main.c

To decide if you need to configure the RTC or not, this is the part of the code responsible of that:

 

  /*##-2- Check if Data stored in BackUp register1: No Need to reconfigure RTC#*/
  /* Read the Back Up Register 1 Data */
  if (HAL_RTCEx_BKUPRead(&RtcHandle, RTC_BKP_DR1) != 0x32F2)
  {
    /* Configure RTC Calendar */
    RTC_CalendarConfig();
  }
  else
  {
    /* Check if the Power On Reset flag is set */
    if (__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) != RESET)
    {
      /* Turn on LED2: Power on reset occurred */
      BSP_LED_On(LED2);
    }
    /* Check if Pin Reset flag is set */
    if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) != RESET)
    {
      /* Turn on LED4: External reset occurred */
      BSP_LED_On(LED4);
    }
    /* Clear source Reset Flag */
    __HAL_RCC_CLEAR_RESET_FLAGS();
  }

 

3- Yes. And CR1220 is also used on our eval boards.

Hope that helps.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS:
1 - This is NOT an online support (https://ols.st.com) but a collaborative space.
2 - Please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help.

View solution in original post

3 REPLIES 3
SofLit
ST Employee

Hello,

For your first and  second question, you can refer to any Cube package offering RTC Calendar example:

This one for example: https://github.com/STMicroelectronics/STM32CubeF7/blob/master/Projects/STM32F769I_EVAL/Examples/RTC/RTC_Calendar/Src/main.c

To decide if you need to configure the RTC or not, this is the part of the code responsible of that:

 

  /*##-2- Check if Data stored in BackUp register1: No Need to reconfigure RTC#*/
  /* Read the Back Up Register 1 Data */
  if (HAL_RTCEx_BKUPRead(&RtcHandle, RTC_BKP_DR1) != 0x32F2)
  {
    /* Configure RTC Calendar */
    RTC_CalendarConfig();
  }
  else
  {
    /* Check if the Power On Reset flag is set */
    if (__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) != RESET)
    {
      /* Turn on LED2: Power on reset occurred */
      BSP_LED_On(LED2);
    }
    /* Check if Pin Reset flag is set */
    if (__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) != RESET)
    {
      /* Turn on LED4: External reset occurred */
      BSP_LED_On(LED4);
    }
    /* Clear source Reset Flag */
    __HAL_RCC_CLEAR_RESET_FLAGS();
  }

 

3- Yes. And CR1220 is also used on our eval boards.

Hope that helps.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS:
1 - This is NOT an online support (https://ols.st.com) but a collaborative space.
2 - Please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help.
Louie88
Associate III

Hi SoLit,

Thank you for your very quick reply!

Clear, if I find this 0x32F2 magic number in the backup register then I do not need to do anything with the RTC during power on. From where this 0x32F2 come from?

Unfortunately STM does not provide battery backup in STM32H474I-DISCO board... probably it did not fit into the board...

Thanks again (for the example as well)

Best regards,

Louis

 

 


@Louie88 wrote:

From where this 0x32F2 come from?


I think it was a random number. After configuring the RTC, the value is written to the back up register (see the example):

  /*##-3- Writes a data in a RTC Backup data Register1 #######################*/
  HAL_RTCEx_BKUPWrite(&RtcHandle, RTC_BKP_DR1, 0x32F2);

So you can select any value you want.

And yes DISCO boards don't feature battery backup socket. Some DISCO boards have VBAT tied to VDD in the PCB. For some new DISCO boards, I pushed internally to to have at least a solder  bridge or connector for VBAT pin so the user can connect an external battery to it. You will see that in some new DISCO boards.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS:
1 - This is NOT an online support (https://ols.st.com) but a collaborative space.
2 - Please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help.