diff options
| author | xoviat <[email protected]> | 2023-08-28 15:34:08 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2023-08-28 15:34:08 -0500 |
| commit | 70a5221b2e0d40a43794bf65fc4d84e0af8ab079 (patch) | |
| tree | 28ee1cfe2d72305aacbc6673534b5d9fbedf6c97 | |
| parent | b315c28d4eda4fe62747d7f626226862cbc92629 (diff) | |
stm32/bd: consolidate enable_rtc
| -rw-r--r-- | embassy-stm32/src/rcc/bd.rs | 39 |
1 files changed, 7 insertions, 32 deletions
diff --git a/embassy-stm32/src/rcc/bd.rs b/embassy-stm32/src/rcc/bd.rs index 0fc116ed8..4d8ed82aa 100644 --- a/embassy-stm32/src/rcc/bd.rs +++ b/embassy-stm32/src/rcc/bd.rs | |||
| @@ -87,13 +87,14 @@ impl BackupDomain { | |||
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | #[cfg(any( | 89 | #[cfg(any( |
| 90 | rtc_v2f0, rtc_v2f2, rtc_v2f3, rtc_v2f4, rtc_v2f7, rtc_v2h7, rtc_v2l0, rtc_v2l1, rtc_v2l4, rtc_v2wb | 90 | rtc_v2f0, rtc_v2f2, rtc_v2f3, rtc_v2f4, rtc_v2f7, rtc_v2h7, rtc_v2l0, rtc_v2l1, rtc_v2l4, rtc_v2wb, rtc_v3, |
| 91 | rtc_v3u5 | ||
| 91 | ))] | 92 | ))] |
| 92 | #[allow(dead_code)] | 93 | #[allow(dead_code)] |
| 93 | pub fn enable_rtc() { | 94 | pub fn enable_rtc() { |
| 94 | let reg = Self::read(); | 95 | let reg = Self::read(); |
| 95 | 96 | ||
| 96 | #[cfg(any(rtc_v2h7, rtc_v2l4, rtc_v2wb))] | 97 | #[cfg(any(rtc_v2h7, rtc_v2l4, rtc_v2wb, rtc_v3, rtc_v3u5))] |
| 97 | assert!(!reg.lsecsson(), "RTC is not compatible with LSE CSS, yet."); | 98 | assert!(!reg.lsecsson(), "RTC is not compatible with LSE CSS, yet."); |
| 98 | 99 | ||
| 99 | if !reg.rtcen() { | 100 | if !reg.rtcen() { |
| @@ -102,47 +103,21 @@ impl BackupDomain { | |||
| 102 | 103 | ||
| 103 | Self::modify(|w| { | 104 | Self::modify(|w| { |
| 104 | // Reset | 105 | // Reset |
| 105 | #[cfg(not(any(rtc_v2l0, rtc_v2l1)))] | 106 | #[cfg(not(any(rtc_v2l0, rtc_v2l1, rtc_v2f2)))] |
| 106 | w.set_bdrst(false); | 107 | w.set_bdrst(false); |
| 107 | 108 | ||
| 108 | w.set_rtcen(true); | 109 | w.set_rtcen(true); |
| 109 | w.set_rtcsel(reg.rtcsel()); | 110 | w.set_rtcsel(reg.rtcsel()); |
| 110 | 111 | ||
| 111 | // Restore bcdr | 112 | // Restore bcdr |
| 112 | #[cfg(any(rtc_v2l4, rtc_v2wb))] | 113 | #[cfg(any(rtc_v2l4, rtc_v2wb, rtc_v3, rtc_v3u5))] |
| 113 | w.set_lscosel(reg.lscosel()); | 114 | w.set_lscosel(reg.lscosel()); |
| 114 | #[cfg(any(rtc_v2l4, rtc_v2wb))] | 115 | #[cfg(any(rtc_v2l4, rtc_v2wb, rtc_v3, rtc_v3u5))] |
| 115 | w.set_lscoen(reg.lscoen()); | 116 | w.set_lscoen(reg.lscoen()); |
| 116 | 117 | ||
| 117 | w.set_lseon(reg.lseon()); | 118 | w.set_lseon(reg.lseon()); |
| 118 | 119 | ||
| 119 | #[cfg(any(rtc_v2f0, rtc_v2f7, rtc_v2h7, rtc_v2l4, rtc_v2wb))] | 120 | #[cfg(any(rtc_v2f0, rtc_v2f7, rtc_v2h7, rtc_v2l4, rtc_v2wb, rtc_v3, rtc_v3u5))] |
| 120 | w.set_lsedrv(reg.lsedrv()); | ||
| 121 | w.set_lsebyp(reg.lsebyp()); | ||
| 122 | }); | ||
| 123 | } | ||
| 124 | } | ||
| 125 | |||
| 126 | #[cfg(any(rtc_v3, rtc_v3u5))] | ||
| 127 | #[allow(dead_code)] | ||
| 128 | pub fn enable_rtc() { | ||
| 129 | let reg = Self::read(); | ||
| 130 | assert!(!reg.lsecsson(), "RTC is not compatible with LSE CSS, yet."); | ||
| 131 | |||
| 132 | if !reg.rtcen() { | ||
| 133 | Self::modify(|w| w.set_bdrst(true)); | ||
| 134 | |||
| 135 | Self::modify(|w| { | ||
| 136 | w.set_bdrst(false); | ||
| 137 | |||
| 138 | w.set_rtcen(true); | ||
| 139 | w.set_rtcsel(reg.rtcsel()); | ||
| 140 | |||
| 141 | // Restore bcdr | ||
| 142 | w.set_lscosel(reg.lscosel()); | ||
| 143 | w.set_lscoen(reg.lscoen()); | ||
| 144 | |||
| 145 | w.set_lseon(reg.lseon()); | ||
| 146 | w.set_lsedrv(reg.lsedrv()); | 121 | w.set_lsedrv(reg.lsedrv()); |
| 147 | w.set_lsebyp(reg.lsebyp()); | 122 | w.set_lsebyp(reg.lsebyp()); |
| 148 | }); | 123 | }); |
