diff options
| author | xoviat <[email protected]> | 2023-04-17 19:07:58 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2023-04-18 20:38:28 -0500 |
| commit | 4de4039417df43e45795fd3848cf02904151ddbb (patch) | |
| tree | 14d3226048f9f93fb2893838bb126c7aa1d55ec4 | |
| parent | f589247c1f80a6a9f95a16bedf7594cdef62185f (diff) | |
stm32/rtc: build more chips
| -rw-r--r-- | embassy-stm32/src/lib.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/rtc/v2.rs | 132 | ||||
| -rw-r--r-- | embassy-stm32/src/rtc/v3.rs | 39 |
3 files changed, 79 insertions, 94 deletions
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index 0dbc9e5c8..70e6aa2bf 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs | |||
| @@ -49,7 +49,7 @@ pub mod pwm; | |||
| 49 | pub mod qspi; | 49 | pub mod qspi; |
| 50 | #[cfg(rng)] | 50 | #[cfg(rng)] |
| 51 | pub mod rng; | 51 | pub mod rng; |
| 52 | #[cfg(all(rtc, not(any(rtc_v1, rtc_v2f0, rtc_v2f7, rtc_v3, rtc_v3u5))))] | 52 | #[cfg(all(rtc, not(rtc_v1)))] |
| 53 | pub mod rtc; | 53 | pub mod rtc; |
| 54 | #[cfg(sdmmc)] | 54 | #[cfg(sdmmc)] |
| 55 | pub mod sdmmc; | 55 | pub mod sdmmc; |
diff --git a/embassy-stm32/src/rtc/v2.rs b/embassy-stm32/src/rtc/v2.rs index abf3da3be..8ab06a59a 100644 --- a/embassy-stm32/src/rtc/v2.rs +++ b/embassy-stm32/src/rtc/v2.rs | |||
| @@ -9,7 +9,70 @@ impl<'d, T: Instance> super::Rtc<'d, T> { | |||
| 9 | pub(super) fn apply_config(&mut self, rtc_config: RtcConfig) { | 9 | pub(super) fn apply_config(&mut self, rtc_config: RtcConfig) { |
| 10 | // Unlock the backup domain | 10 | // Unlock the backup domain |
| 11 | unsafe { | 11 | unsafe { |
| 12 | unlock_backup_domain(rtc_config.clock_config as u8); | 12 | let clock_config = rtc_config.clock_config as u8; |
| 13 | |||
| 14 | #[cfg(not(rtc_v2wb))] | ||
| 15 | use stm32_metapac::rcc::vals::Rtcsel; | ||
| 16 | |||
| 17 | #[cfg(any(rtc_v2f2, rtc_v2f3, rtc_v2l1))] | ||
| 18 | let cr = crate::pac::PWR.cr(); | ||
| 19 | #[cfg(any(rtc_v2f4, rtc_v2f7, rtc_v2h7, rtc_v2l4, rtc_v2wb))] | ||
| 20 | let cr = crate::pac::PWR.cr1(); | ||
| 21 | |||
| 22 | // TODO: Missing from PAC for l0 and f0? | ||
| 23 | #[cfg(not(any(rtc_v2f0, rtc_v2l0)))] | ||
| 24 | { | ||
| 25 | cr.modify(|w| w.set_dbp(true)); | ||
| 26 | while !cr.read().dbp() {} | ||
| 27 | } | ||
| 28 | |||
| 29 | #[cfg(not(any(rtc_v2l0, rtc_v2l1)))] | ||
| 30 | let reg = crate::pac::RCC.bdcr().read(); | ||
| 31 | #[cfg(any(rtc_v2l0, rtc_v2l1))] | ||
| 32 | let reg = crate::pac::RCC.csr().read(); | ||
| 33 | |||
| 34 | #[cfg(any(rtc_v2h7, rtc_v2l4, rtc_v2wb))] | ||
| 35 | assert!(!reg.lsecsson(), "RTC is not compatible with LSE CSS, yet."); | ||
| 36 | |||
| 37 | #[cfg(rtc_v2wb)] | ||
| 38 | let rtcsel = reg.rtcsel(); | ||
| 39 | #[cfg(not(rtc_v2wb))] | ||
| 40 | let rtcsel = reg.rtcsel().0; | ||
| 41 | |||
| 42 | if !reg.rtcen() || rtcsel != clock_config { | ||
| 43 | #[cfg(not(any(rtc_v2l0, rtc_v2l1)))] | ||
| 44 | crate::pac::RCC.bdcr().modify(|w| w.set_bdrst(true)); | ||
| 45 | |||
| 46 | #[cfg(not(any(rtc_v2l0, rtc_v2l1)))] | ||
| 47 | let cr = crate::pac::RCC.bdcr(); | ||
| 48 | #[cfg(any(rtc_v2l0, rtc_v2l1))] | ||
| 49 | let cr = crate::pac::RCC.csr(); | ||
| 50 | |||
| 51 | cr.modify(|w| { | ||
| 52 | // Reset | ||
| 53 | #[cfg(not(any(rtc_v2l0, rtc_v2l1)))] | ||
| 54 | w.set_bdrst(false); | ||
| 55 | |||
| 56 | // Select RTC source | ||
| 57 | #[cfg(not(rtc_v2wb))] | ||
| 58 | w.set_rtcsel(Rtcsel(clock_config)); | ||
| 59 | #[cfg(rtc_v2wb)] | ||
| 60 | w.set_rtcsel(clock_config); | ||
| 61 | w.set_rtcen(true); | ||
| 62 | |||
| 63 | // Restore bcdr | ||
| 64 | #[cfg(any(rtc_v2l4, rtc_v2wb))] | ||
| 65 | w.set_lscosel(reg.lscosel()); | ||
| 66 | #[cfg(any(rtc_v2l4, rtc_v2wb))] | ||
| 67 | w.set_lscoen(reg.lscoen()); | ||
| 68 | |||
| 69 | w.set_lseon(reg.lseon()); | ||
| 70 | |||
| 71 | #[cfg(any(rtc_v2f0, rtc_v2f7, rtc_v2h7, rtc_v2l4, rtc_v2wb))] | ||
| 72 | w.set_lsedrv(reg.lsedrv()); | ||
| 73 | w.set_lsebyp(reg.lsebyp()); | ||
| 74 | }); | ||
| 75 | } | ||
| 13 | } | 76 | } |
| 14 | 77 | ||
| 15 | self.write(true, |rtc| unsafe { | 78 | self.write(true, |rtc| unsafe { |
| @@ -157,7 +220,7 @@ pub fn write_backup_register(rtc: &Rtc, register: usize, value: u32) { | |||
| 157 | } | 220 | } |
| 158 | 221 | ||
| 159 | pub(crate) unsafe fn enable_peripheral_clk() { | 222 | pub(crate) unsafe fn enable_peripheral_clk() { |
| 160 | #[cfg(any(rtc_v2f0, rtc_v2f7, rtc_v2l4, rtc_v2wb))] | 223 | #[cfg(any(rtc_v2l4, rtc_v2wb))] |
| 161 | { | 224 | { |
| 162 | // enable peripheral clock for communication | 225 | // enable peripheral clock for communication |
| 163 | crate::pac::RCC.apb1enr1().modify(|w| w.set_rtcapben(true)); | 226 | crate::pac::RCC.apb1enr1().modify(|w| w.set_rtcapben(true)); |
| @@ -168,68 +231,3 @@ pub(crate) unsafe fn enable_peripheral_clk() { | |||
| 168 | } | 231 | } |
| 169 | 232 | ||
| 170 | pub const BACKUP_REGISTER_COUNT: usize = 20; | 233 | pub const BACKUP_REGISTER_COUNT: usize = 20; |
| 171 | |||
| 172 | pub(super) unsafe fn unlock_backup_domain(clock_config: u8) { | ||
| 173 | #[cfg(not(rtc_v2wb))] | ||
| 174 | use stm32_metapac::rcc::vals::Rtcsel; | ||
| 175 | |||
| 176 | #[cfg(any(rtc_v2f2, rtc_v2f3, rtc_v2l1))] | ||
| 177 | let cr = crate::pac::PWR.cr(); | ||
| 178 | #[cfg(any(rtc_v2f0, rtc_v2f4, rtc_v2f7, rtc_v2h7, rtc_v2l4, rtc_v2wb))] | ||
| 179 | let cr = crate::pac::PWR.cr1(); | ||
| 180 | |||
| 181 | // TODO: Missing from PAC for l0? | ||
| 182 | #[cfg(not(rtc_v2l0))] | ||
| 183 | { | ||
| 184 | cr.modify(|w| w.set_dbp(true)); | ||
| 185 | while !cr.read().dbp() {} | ||
| 186 | } | ||
| 187 | |||
| 188 | #[cfg(not(any(rtc_v2l0, rtc_v2l1)))] | ||
| 189 | let reg = crate::pac::RCC.bdcr().read(); | ||
| 190 | #[cfg(any(rtc_v2l0, rtc_v2l1))] | ||
| 191 | let reg = crate::pac::RCC.csr().read(); | ||
| 192 | |||
| 193 | #[cfg(any(rtc_v2f0, rtc_v2f7, rtc_v2h7, rtc_v2l4, rtc_v2wb))] | ||
| 194 | assert!(!reg.lsecsson(), "RTC is not compatible with LSE CSS, yet."); | ||
| 195 | |||
| 196 | #[cfg(rtc_v2wb)] | ||
| 197 | let rtcsel = reg.rtcsel(); | ||
| 198 | #[cfg(not(rtc_v2wb))] | ||
| 199 | let rtcsel = reg.rtcsel().0; | ||
| 200 | |||
| 201 | if !reg.rtcen() || rtcsel != clock_config { | ||
| 202 | #[cfg(not(any(rtc_v2l0, rtc_v2l1)))] | ||
| 203 | crate::pac::RCC.bdcr().modify(|w| w.set_bdrst(true)); | ||
| 204 | |||
| 205 | #[cfg(not(any(rtc_v2l0, rtc_v2l1)))] | ||
| 206 | let cr = crate::pac::RCC.bdcr(); | ||
| 207 | #[cfg(any(rtc_v2l0, rtc_v2l1))] | ||
| 208 | let cr = crate::pac::RCC.csr(); | ||
| 209 | |||
| 210 | cr.modify(|w| { | ||
| 211 | // Reset | ||
| 212 | #[cfg(not(any(rtc_v2l0, rtc_v2l1)))] | ||
| 213 | w.set_bdrst(false); | ||
| 214 | |||
| 215 | // Select RTC source | ||
| 216 | #[cfg(not(rtc_v2wb))] | ||
| 217 | w.set_rtcsel(Rtcsel(clock_config)); | ||
| 218 | #[cfg(rtc_v2wb)] | ||
| 219 | w.set_rtcsel(clock_config); | ||
| 220 | w.set_rtcen(true); | ||
| 221 | |||
| 222 | // Restore bcdr | ||
| 223 | #[cfg(any(rtc_v2f0, rtc_v2f7, rtc_v2l4, rtc_v2wb))] | ||
| 224 | w.set_lscosel(reg.lscosel()); | ||
| 225 | #[cfg(any(rtc_v2f0, rtc_v2f7, rtc_v2l4, rtc_v2wb))] | ||
| 226 | w.set_lscoen(reg.lscoen()); | ||
| 227 | |||
| 228 | w.set_lseon(reg.lseon()); | ||
| 229 | |||
| 230 | #[cfg(any(rtc_v2f0, rtc_v2f7, rtc_v2h7, rtc_v2l4, rtc_v2wb))] | ||
| 231 | w.set_lsedrv(reg.lsedrv()); | ||
| 232 | w.set_lsebyp(reg.lsebyp()); | ||
| 233 | }); | ||
| 234 | } | ||
| 235 | } | ||
diff --git a/embassy-stm32/src/rtc/v3.rs b/embassy-stm32/src/rtc/v3.rs index 6998c48c2..c2b3c88c2 100644 --- a/embassy-stm32/src/rtc/v3.rs +++ b/embassy-stm32/src/rtc/v3.rs | |||
| @@ -9,43 +9,30 @@ impl<'d, T: Instance> super::Rtc<'d, T> { | |||
| 9 | pub(super) fn apply_config(&mut self, rtc_config: RtcConfig) { | 9 | pub(super) fn apply_config(&mut self, rtc_config: RtcConfig) { |
| 10 | // Unlock the backup domain | 10 | // Unlock the backup domain |
| 11 | unsafe { | 11 | unsafe { |
| 12 | #[cfg(feature = "stm32g0c1ve")] | 12 | #[cfg(any(rtc_v3u5, rcc_g0))] |
| 13 | use crate::pac::rcc::vals::Rtcsel; | ||
| 14 | #[cfg(not(any(rtc_v3u5, rcc_g0, rcc_g4, rcc_wl5, rcc_wle)))] | ||
| 15 | use crate::pac::rtc::vals::Rtcsel; | ||
| 16 | |||
| 17 | #[cfg(not(any(rtc_v3u5, rcc_wl5, rcc_wle)))] | ||
| 13 | { | 18 | { |
| 14 | crate::pac::PWR.cr1().modify(|w| w.set_dbp(true)); | 19 | crate::pac::PWR.cr1().modify(|w| w.set_dbp(true)); |
| 15 | while !crate::pac::PWR.cr1().read().dbp() {} | 20 | while !crate::pac::PWR.cr1().read().dbp() {} |
| 16 | } | 21 | } |
| 17 | 22 | #[cfg(any(rcc_wl5, rcc_wle))] | |
| 18 | #[cfg(not(any( | ||
| 19 | feature = "stm32g0c1ve", | ||
| 20 | feature = "stm32g491re", | ||
| 21 | feature = "stm32u585zi", | ||
| 22 | feature = "stm32g473cc" | ||
| 23 | )))] | ||
| 24 | { | 23 | { |
| 25 | crate::pac::PWR | 24 | use crate::pac::pwr::vals::Dbp; |
| 26 | .cr1() | 25 | |
| 27 | .modify(|w| w.set_dbp(stm32_metapac::pwr::vals::Dbp::ENABLED)); | 26 | crate::pac::PWR.cr1().modify(|w| w.set_dbp(Dbp::ENABLED)); |
| 28 | while crate::pac::PWR.cr1().read().dbp() != stm32_metapac::pwr::vals::Dbp::DISABLED {} | 27 | while crate::pac::PWR.cr1().read().dbp() != Dbp::ENABLED {} |
| 29 | } | 28 | } |
| 30 | 29 | ||
| 31 | let reg = crate::pac::RCC.bdcr().read(); | 30 | let reg = crate::pac::RCC.bdcr().read(); |
| 32 | assert!(!reg.lsecsson(), "RTC is not compatible with LSE CSS, yet."); | 31 | assert!(!reg.lsecsson(), "RTC is not compatible with LSE CSS, yet."); |
| 33 | 32 | ||
| 34 | let config_rtcsel = rtc_config.clock_config as u8; | 33 | let config_rtcsel = rtc_config.clock_config as u8; |
| 35 | #[cfg(not(any( | 34 | #[cfg(not(any(rcc_wl5, rcc_wle, rcc_g4)))] |
| 36 | feature = "stm32wl54jc-cm0p", | 35 | let config_rtcsel = Rtcsel(config_rtcsel); |
| 37 | feature = "stm32wle5ub", | ||
| 38 | feature = "stm32g0c1ve", | ||
| 39 | feature = "stm32wl55jc-cm4", | ||
| 40 | feature = "stm32wl55uc-cm4", | ||
| 41 | feature = "stm32g491re", | ||
| 42 | feature = "stm32g473cc", | ||
| 43 | feature = "stm32u585zi", | ||
| 44 | feature = "stm32wle5jb" | ||
| 45 | )))] | ||
| 46 | let config_rtcsel = stm32_metapac::rtc::vals::Rtcsel(config_rtcsel); | ||
| 47 | #[cfg(feature = "stm32g0c1ve")] | ||
| 48 | let config_rtcsel = stm32_metapac::rcc::vals::Rtcsel(config_rtcsel); | ||
| 49 | 36 | ||
| 50 | if !reg.rtcen() || reg.rtcsel() != config_rtcsel { | 37 | if !reg.rtcen() || reg.rtcsel() != config_rtcsel { |
| 51 | crate::pac::RCC.bdcr().modify(|w| w.set_bdrst(true)); | 38 | crate::pac::RCC.bdcr().modify(|w| w.set_bdrst(true)); |
