2021-03-09 10:56 PM
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
Solved! Go to Solution.
2021-03-10 03:29 PM
2021-03-10 01:08 AM
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?
2021-03-10 09:18 AM
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
2021-03-10 03:29 PM
Do you have PWR_CR2.BREN set?
JW
2021-03-10 06:52 PM
Jan,
No, PWR_CR2.BREN was not set.
Now I'm playing with it and don't understand what goes on there.
CR2.BRRDY becomes 1.
Write data to the backup RAM.
CR2 = 00010001 (BREN, BRRDY); CR3 = 00000142 (LDOEN, some reserved bit, VBE).
Data in backup RAM is present.
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
2021-03-11 04:02 AM
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
2021-03-11 08:40 AM
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