Hello,
H7 offers 4Ko of backup ram in addition to the 32 backups registers that are present on other MCU families.
For now, backup memory is lost when power is cut even is vbat is wired to a battery.
Backup regulator is enabled bia PWR_CR2_BREN bit, and one should wait that PWR_CR2_BRRDY is up to confirm that backup regulator is enabled.
As <Sigprof> has found on the discord channel (thanks to him), PWR_CR1_DBP must be set to authorize changing BREN value, and the order of setting these bits is inverted.
I propose a patch to fix backup memory persistence.
Alexandre
backup domain initialisation bug for H7
- alex31
- Posts: 412
- Joined: Fri May 25, 2012 10:23 am
- Location: toulouse, france
- Has thanked: 47 times
- Been thanked: 80 times
- Contact:
backup domain initialisation bug for H7
- Attachments
-
- backupDomainInitH7.patch.zip
- (847 Bytes) Downloaded 99 times
-
- Posts: 1
- Joined: Wed Jul 24, 2024 9:47 am
Re: backup domain initialisation bug for H7
Before enabling the backup regulator (BREN), you need to set the DBP (Disable Backup Domain Write Protection) bit.
After setting DBP, you can then set the BREN (Backup Regulator Enable) bit.
Here’s how you can do it programmatically (assuming you're writing in C or a similar language).
After setting DBP, you can then set the BREN (Backup Regulator Enable) bit.
Here’s how you can do it programmatically (assuming you're writing in C or a similar language).
- Giovanni
- Site Admin
- Posts: 14563
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1111 times
- Been thanked: 937 times
- Contact:
Re: backup domain initialisation bug for H7
anatolewilson wrote:Before enabling the backup regulator (BREN), you need to set the DBP (Disable Backup Domain Write Protection) bit.
After setting DBP, you can then set the BREN (Backup Regulator Enable) bit.
Here’s how you can do it programmatically (assuming you're writing in C or a similar language).
Hi,
Is this about code on repository or the patch proposed by Alex31?
Giovanni
- FXCoder
- Posts: 393
- Joined: Sun Jun 12, 2016 4:10 am
- Location: Sydney, Australia
- Has thanked: 184 times
- Been thanked: 131 times
Re: backup domain initialisation bug for H7
It is possible with the current (trunk) repository code to achieve the desired result via the setting in mcuconf.h
Code: Select all
#define STM32_PWR_CR1 (PWR_CR1_SVOS_1 | PWR_CR1_SVOS_0 \
| PWR_CR1_DBP)
#define STM32_PWR_CR2 (PWR_CR2_BREN | PWR_CR2_MONEN)
-
- Posts: 29
- Joined: Sat Mar 17, 2018 2:51 pm
- Has thanked: 8 times
- Been thanked: 15 times
Re: backup domain initialisation bug for H7
as of my knowledge, the 4k backup sram requires
* PWR->CR1 |= PWR_CR1_DBP_Msk; # disable backup protection
* PWR->CR2 |= PWR_CR2_BREN_Msk; # backup regulator enable
* while (!(PWR->CR2 & PWR_CR2_BRRDY_Msk)); # backup regulator ready
* i think the values stored in backup sram will not survive a reset (as the backup regulator is off after a reset??), but they may survive the sleep/suspend states.
* setting disable backup protection may not be required for reading, but enabling the BREN bit.
please correct me, if i am wrong!
the 32 backups registers (4 byte each) do NOT require the backup regulator. they can be read anytime. for writing, the backup protection needs to be disabled:
* PWR->CR1 |= PWR_CR1_DBP_Msk # disable backup protection
unfortunately, setting RCC->BDCR = RCC_BDCR_BDRST (which happens currently (r16597) in ChibiOS at os/hal/ports/STM32/STM32H7xx/hal_lld.c:66 aka stm32_clock_init() → init_bkp_domain()) clears the backup registers and possibly also the backup sram, as reported in viewtopic.php?f=35&t=6378.
* PWR->CR1 |= PWR_CR1_DBP_Msk; # disable backup protection
* PWR->CR2 |= PWR_CR2_BREN_Msk; # backup regulator enable
* while (!(PWR->CR2 & PWR_CR2_BRRDY_Msk)); # backup regulator ready
* i think the values stored in backup sram will not survive a reset (as the backup regulator is off after a reset??), but they may survive the sleep/suspend states.
* setting disable backup protection may not be required for reading, but enabling the BREN bit.
please correct me, if i am wrong!
the 32 backups registers (4 byte each) do NOT require the backup regulator. they can be read anytime. for writing, the backup protection needs to be disabled:
* PWR->CR1 |= PWR_CR1_DBP_Msk # disable backup protection
unfortunately, setting RCC->BDCR = RCC_BDCR_BDRST (which happens currently (r16597) in ChibiOS at os/hal/ports/STM32/STM32H7xx/hal_lld.c:66 aka stm32_clock_init() → init_bkp_domain()) clears the backup registers and possibly also the backup sram, as reported in viewtopic.php?f=35&t=6378.
Who is online
Users browsing this forum: No registered users and 4 guests