Skip to main content
Pavel A.
Mar 10, 2021 6:56 AM UTC
Solved

STM32H743-EVAL2, why battery-backed RAM doesn't hold data?

I start from any simple Cube example, such as UART_Printf,

enable access to the backup RAM and write some data.

After reset by the reset button or NVIC_System_Reset data in the backup RAM is retained.

But after powering off the data is lost.

Do I miss some configuration steps to make the backup domain use the battery? Any jumper?

The battery ML1220 voltage is 2.75V when the board is disconnected from power.

Is this too low voltage? Googling shows that minimal voltage can be as low as 2.5V.

Apologize for a silly question but I cannot find solution in the board manual.

-- pa

This topic has been closed for replies.
waclawek.jan
waclawek.janBest answer
Super User
Mar 10, 2021 11:29 PM UTC

Do you have PWR_CR2.BREN set?

JW

6 replies

Uwe Bonnes
Chief
Mar 10, 2021 9:08 AM UTC

Carefully check how the mackup RAM is handled in the bootup process. Perhaps it is initialized during bootup. How is BKUP RAM listed in the linker?

Pavel A.
Pavel A.Author
Mar 10, 2021 5:18 PM UTC

Hi @Uwe Bonnes​ thank you for the reply.

My init code does not change the data if it sees a "magic" already written.

Since a pin reset (EVB reset button) does not disturb the data when a power supply is connected, I think my init code is ok.

> How is BKUP RAM listed in the linker?

Not listed at all, accessed thru a pointer.

Here is the code to enable access:

void unlock_bkp_RAM(void)
{
 __HAL_RCC_BKPRAM_CLK_ENABLE();
 __DSB();
 bool y = READ_BIT(PWR->CR1, PWR_CR1_DBP) == (PWR_CR1_DBP);
 if (!y) {
 HAL_PWR_EnableBkUpAccess();
 __DSB();
 }
}

#define BACKUP_RAM_BASE 0x38800000 
 
bool open_backup_store(void)
{
 unlock_bkp_RAM();
 struct my_backup_struct *ps = (struct my_backup_struct*) ((uintptr_t)BACKUP_RAM_BASE);
 if (ps->magic != MY_MAGIC) {
 printf("backup magic bad\n");
 goto reinit;
 }
 return true;
 reinit:
 .......................
}

-- pa

waclawek.jan
waclawek.janBest answer
Super User
Mar 10, 2021 11:29 PM UTC

Do you have PWR_CR2.BREN set?

JW

Pavel A.
Pavel A.Author
Mar 11, 2021 2:52 AM UTC

Jan,

No, PWR_CR2.BREN was not set.

Now I'm playing with it and don't understand what goes on there.

  • After POR reset, I set CR1.DBP and CR2.BREN and also CR3.VBE to charge the battery.

CR2.BRRDY becomes 1.

Write data to the backup RAM.

  • Then do NVIC_System_Reset or press the black reset button:

CR2 = 00010001 (BREN, BRRDY); CR3 = 00000142 (LDOEN, some reserved bit, VBE).

Data in backup RAM is present.

  • Then do power cycle.

RCC->RSR = 00FE0000: POR set

Set PWR->CR1.DBP and... CR2=00000000 CR3=00000042

So these bits do not survive power cycle.... what's the point to set them? What else is missing?

--pa

waclawek.jan
Super User
Mar 11, 2021 12:02 PM UTC

Pavel,

I'd recommend you to get rid of Cube and at least for the experiments, use bare register access, where you know exactly what are you doing.

Other than that, check if VBAT has always voltage within the bounds. Start with a true non-rechargeable battery (a CR2032 perhaps), without attempting to recharge it.

JW

Pavel A.
Pavel A.Author
Mar 11, 2021 4:40 PM UTC

Thanks Jan,

With PWR_CR2.BREN set the backup memory keeps the data.

It was a silly mistake on my part ((

Overlooked a jumper on the eval. board that connects the battery (JP11).

OTOH now I know to tell if the jumper is put and the battery installed, so can give a helpful message to the user.

Thanks,

-- pa