From a12648ff7a501b44a2c21acc43493260751abc0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Fri, 4 Sep 2020 21:33:54 +0200 Subject: [PATCH] Issue #18: Backup RAM: Make use of backup regulator optional --- stm-firmware/include/stm-periph/backup-ram.h | 4 +++- stm-firmware/stm-periph/backup-ram.c | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/stm-firmware/include/stm-periph/backup-ram.h b/stm-firmware/include/stm-periph/backup-ram.h index a2d2292..3f4a470 100644 --- a/stm-firmware/include/stm-periph/backup-ram.h +++ b/stm-firmware/include/stm-periph/backup-ram.h @@ -19,11 +19,13 @@ */ #include +#include /** * @brief Init the backup ram and make it accesible + * @param use_backup_regulator Enable the Backup VBAT regulator. It will be used, when VDD is powered off */ -void backup_ram_init(void); +void backup_ram_init(bool use_backup_regulator); /** * @brief Disable access to the backup RAM. This saves power diff --git a/stm-firmware/stm-periph/backup-ram.c b/stm-firmware/stm-periph/backup-ram.c index d2bca10..62ad992 100644 --- a/stm-firmware/stm-periph/backup-ram.c +++ b/stm-firmware/stm-periph/backup-ram.c @@ -34,18 +34,20 @@ #error "Backup RAM size ahs to be a power of two!" #endif -void backup_ram_init(void) +void backup_ram_init(bool use_backup_regulator) { rcc_manager_enable_clock(&RCC->APB1ENR, BITMASK_TO_BITNO(RCC_APB1ENR_PWREN)); /* Enable access to backup RAM register set */ PWR->CR |= PWR_CR_DBP; - /* Enable the backup regulator */ - PWR->CSR |= PWR_CSR_BRE; + if (use_backup_regulator) { + /* Enable the backup regulator */ + PWR->CSR |= PWR_CSR_BRE; - /* Wait until regulator is ready */ - while (!(PWR->CSR & PWR_CSR_BRR)); + /* Wait until regulator is ready */ + while (!(PWR->CSR & PWR_CSR_BRR)); + } /* Enable clock for backup ram interface */ rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(RCC_AHB1ENR_BKPSRAMEN));