Skip to content

Commit 64fd2d9

Browse files
bors[bot]matticorichardeoin
authored
Merge #303
303: Add backup domain voltage regulator control r=richardeoin a=mattico Pretty simple, but it's useful for me. Checking the RM again the backup regulator is only used to power the backup SRAM, which can also be powered by V_CORE (the default). Junction temperature monitoring and battery voltage monitoring also require the backup voltage regulator to be enabled. Co-authored-by: Matt Ickstadt <mattico8@gmail.com> Co-authored-by: Richard Meadows <richardeoin@gmail.com>
2 parents dbb6625 + 2d5dfe5 commit 64fd2d9

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [Unreleased]
44

5+
* pwr: Add backup domain voltage regulator control [#303][303]
56
* MSRV increased to 1.56.1
67

78
## [v0.11.0] 2021-12-18
@@ -213,3 +214,4 @@
213214
[287]: https://github.com/stm32-rs/stm32h7xx-hal/pull/287
214215
[292]: https://github.com/stm32-rs/stm32h7xx-hal/pull/292
215216
[297]: https://github.com/stm32-rs/stm32h7xx-hal/pull/297
217+
[303]: https://github.com/stm32-rs/stm32h7xx-hal/pull/303

src/pwr.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ impl PwrExt for PWR {
8181
any(feature = "rm0433", feature = "rm0399")
8282
))]
8383
enable_vos0: false,
84+
backup_regulator: false,
8485
}
8586
}
8687
}
@@ -97,6 +98,7 @@ pub struct Pwr {
9798
any(feature = "rm0433", feature = "rm0399")
9899
))]
99100
enable_vos0: bool,
101+
backup_regulator: bool,
100102
}
101103

102104
/// Voltage Scale
@@ -332,6 +334,15 @@ impl Pwr {
332334
self
333335
}
334336

337+
/// Enable the backup domain voltage regulator
338+
///
339+
/// The backup domain voltage regulator maintains the contents of backup SRAM
340+
/// in Standby and VBAT modes.
341+
pub fn backup_regulator(mut self) -> Self {
342+
self.backup_regulator = true;
343+
self
344+
}
345+
335346
pub fn freeze(self) -> PowerConfiguration {
336347
// NB. The lower bytes of CR3 can only be written once after
337348
// POR, and must be written with a valid combination. Refer to
@@ -418,7 +429,14 @@ impl Pwr {
418429

419430
// Disable backup power domain write protection
420431
self.rb.cr1.modify(|_, w| w.dbp().set_bit());
421-
let backup = unsafe { BackupREC::new_singleton() };
432+
while self.rb.cr1.read().dbp().bit_is_clear() {}
433+
434+
if self.backup_regulator {
435+
self.rb.cr2.modify(|_, w| w.bren().set_bit());
436+
while self.rb.cr2.read().brrdy().bit_is_clear() {}
437+
}
438+
439+
let backup = unsafe { BackupREC::new_singleton(self.backup_regulator) };
422440

423441
PowerConfiguration {
424442
vos,

src/rcc/backup.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
pub struct BackupREC {
2828
#[cfg(feature = "rtc")]
2929
pub RTC: Rtc,
30+
backup_regulator: bool,
3031
}
3132

3233
impl BackupREC {
@@ -36,14 +37,20 @@ impl BackupREC {
3637
///
3738
/// Must only be called once, after the backup domain write
3839
/// protection is disabled.
39-
pub(crate) unsafe fn new_singleton() -> Self {
40+
pub(crate) unsafe fn new_singleton(backup_regulator: bool) -> Self {
4041
Self {
4142
#[cfg(feature = "rtc")]
4243
RTC: Rtc {
4344
_marker: core::marker::PhantomData,
4445
},
46+
backup_regulator,
4547
}
4648
}
49+
50+
/// Returns `true` if the Backup Domain Voltage Regulator is enabled
51+
pub fn backup_regulator_enabled(&self) -> bool {
52+
self.backup_regulator
53+
}
4754
}
4855

4956
#[cfg(feature = "rtc")]

0 commit comments

Comments
 (0)