2025-01-31 12:49 AM
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:
Thanks,
Louis
Solved! Go to Solution.
2025-01-31 01:00 AM - edited 2025-01-31 01:44 AM
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.
2025-01-31 01:00 AM - edited 2025-01-31 01:44 AM
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.
2025-01-31 01:28 AM
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
2025-01-31 01:37 AM - edited 2025-01-31 01:40 AM
@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.