diff --git a/include/libopencm3/stm32/l4/pwr.h b/include/libopencm3/stm32/l4/pwr.h index f4d2b911..04919327 100644 --- a/include/libopencm3/stm32/l4/pwr.h +++ b/include/libopencm3/stm32/l4/pwr.h @@ -170,6 +170,8 @@ enum pwr_vos_scale { BEGIN_DECLS void pwr_set_vos_scale(enum pwr_vos_scale scale); +void pwr_disable_backup_domain_write_protect(void); +void pwr_enable_backup_domain_write_protect(void); END_DECLS diff --git a/lib/stm32/l4/pwr.c b/lib/stm32/l4/pwr.c index e6f71296..e6bd877a 100644 --- a/lib/stm32/l4/pwr.c +++ b/lib/stm32/l4/pwr.c @@ -52,4 +52,24 @@ void pwr_set_vos_scale(enum pwr_vos_scale scale) } PWR_CR1 = reg32; } + +/** Disable Backup Domain Write Protection + * + * This allows backup domain registers to be changed. These registers are write + * protected after a reset. + */ +void pwr_disable_backup_domain_write_protect(void) +{ + PWR_CR1 |= PWR_CR1_DBP; +} + +/** Re-enable Backup Domain Write Protection + * + * This protects backup domain registers from inadvertent change. + */ +void pwr_enable_backup_domain_write_protect(void) +{ + PWR_CR1 &= ~PWR_CR1_DBP; +} + /**@}*/