Skip to main content
Paulo Rego
Associate II
February 22, 2023
Solved

STM32H vbat

  • February 22, 2023
  • 4 replies
  • 2351 views

Hello everybody,

My name is Rego, as a hobby I work on displays, image processing, etc...

I'm not very familiar with ST, but I'm really enjoying these MCU.

I've already implemented RTC using VBAT and it works very well. Now I want SRAM backup,

On battery it loses data I can't understand the reason for the problem, can anyone help me?

thanks

This topic has been closed for replies.
Best answer by Pavel A.

Last time I did this on STM32H743-EVAL board, years ago.

If memory serves: enable the backup domain power regulator with HAL_PWREx_EnableBkUpReg()

Then unlock access to the backup RAM to read and write:

// Unlock access to backup RAM
void unlock_bkp_RAM(void)
{
 __HAL_RCC_BKPRAM_CLK_ENABLE();
 __DMB();
 if (!LL_PWR_IsEnabledBkUpAccess())
 {
 HAL_PWR_EnableBkUpAccess();
 __DMB();
 }
}

If the battery is rechargeable, you may need to turn on/off the charger, by HAL_PWREx_EnableBatteryCharging and HAL_PWREx_DisableBatteryCharging.

The Cube FW_H7 software package has examples of backup RAM and RTC registers use, look at these.

Enjoy.

4 replies

waclawek.jan
Super User
February 23, 2023

Ib don't use the 'H7 family but in other Hamilton for the backup SRAM to work under VBAT supply, a dedicated internal voltage regulator has to be switched on (in PWR module) Try to search for it in Reference Manual (RM).

JW

Paulo Rego
Associate II
February 23, 2023

0693W00000aHYLkQAO.pngDid you refer to this?

Thanks,

Rego

Pavel A.
Pavel A.Best answer
February 23, 2023

Last time I did this on STM32H743-EVAL board, years ago.

If memory serves: enable the backup domain power regulator with HAL_PWREx_EnableBkUpReg()

Then unlock access to the backup RAM to read and write:

// Unlock access to backup RAM
void unlock_bkp_RAM(void)
{
 __HAL_RCC_BKPRAM_CLK_ENABLE();
 __DMB();
 if (!LL_PWR_IsEnabledBkUpAccess())
 {
 HAL_PWR_EnableBkUpAccess();
 __DMB();
 }
}

If the battery is rechargeable, you may need to turn on/off the charger, by HAL_PWREx_EnableBatteryCharging and HAL_PWREx_DisableBatteryCharging.

The Cube FW_H7 software package has examples of backup RAM and RTC registers use, look at these.

Enjoy.

Paulo Rego
Associate II
February 25, 2023

Thanks for your help, it finally works,,!!:thumbs_up:

Regards,

Rego