Skip to content

Commit 326d605

Browse files
aurel32MaureenHelm
authored andcommitted
drivers: bbram: stm32-bbram: fix write for devices with TAMP
On devices where the backup memory is part of the TAMP peripheral, the Backup Domain Protection prevents write to the backup registers. This fix disables the protection before writing registers and re-enables it afterwards. Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
1 parent e90c89d commit 326d605

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/bbram/bbram_stm32.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <zephyr/drivers/bbram.h>
1212
#include <zephyr/logging/log.h>
1313
#include <zephyr/sys/util.h>
14+
#include <stm32_ll_pwr.h>
1415
#include <stm32_ll_rtc.h>
1516
LOG_MODULE_REGISTER(bbram, CONFIG_BBRAM_LOG_LEVEL);
1617

@@ -65,6 +66,10 @@ static int bbram_stm32_write(const struct device *dev, size_t offset, size_t siz
6566
return -EFAULT;
6667
}
6768

69+
#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) || defined(PWR_DBPCR_DBP) || defined(PWR_DBPR_DBP)
70+
LL_PWR_EnableBkUpAccess();
71+
#endif /* PWR_CR_DBP || PWR_CR1_DBP || PWR_DBPCR_DBP || PWR_DBPR_DBP */
72+
6873
for (size_t written = 0; written < size; written += to_copy) {
6974
reg = STM32_BKP_REG(STM32_BKP_REG_INDEX(offset + written));
7075
begin = STM32_BKP_REG_BYTE_INDEX(offset + written);
@@ -73,6 +78,10 @@ static int bbram_stm32_write(const struct device *dev, size_t offset, size_t siz
7378
STM32_BKP_REG(STM32_BKP_REG_INDEX(offset + written)) = reg;
7479
}
7580

81+
#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) || defined(PWR_DBPCR_DBP) || defined(PWR_DBPR_DBP)
82+
LL_PWR_DisableBkUpAccess();
83+
#endif /* PWR_CR_DBP || PWR_CR1_DBP || PWR_DBPCR_DBP || PWR_DBPR_DBP */
84+
7685
return 0;
7786
}
7887

0 commit comments

Comments
 (0)