cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H vbat

Paulo Rego
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

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.

View solution in original post

4 REPLIES 4

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

0693W00000aHYLkQAO.pngDid you refer to this?

Thanks,

Rego

Pavel A.
Evangelist III

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

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

Regards,

Rego