diff options
| author | everdrone <[email protected]> | 2025-09-21 14:52:54 +0200 |
|---|---|---|
| committer | everdrone <[email protected]> | 2025-09-21 14:52:54 +0200 |
| commit | 7b9116957a439a5e8488aa9d6f47bbb7b8a306a1 (patch) | |
| tree | 9838460dc1579a659f0e5be4119a9c69cf1154c8 | |
| parent | 500ffc0acb4014e334d9d1f23a45a1f65c02aa17 (diff) | |
Add `cfg`s for N6 family in BD
| -rw-r--r-- | embassy-stm32/src/rcc/bd.rs | 102 |
1 files changed, 82 insertions, 20 deletions
diff --git a/embassy-stm32/src/rcc/bd.rs b/embassy-stm32/src/rcc/bd.rs index e2c704405..e5f52c3c7 100644 --- a/embassy-stm32/src/rcc/bd.rs +++ b/embassy-stm32/src/rcc/bd.rs | |||
| @@ -66,9 +66,11 @@ fn unlock() {} | |||
| 66 | fn unlock() { | 66 | fn unlock() { |
| 67 | #[cfg(any(stm32f0, stm32f1, stm32f2, stm32f3, stm32l0, stm32l1))] | 67 | #[cfg(any(stm32f0, stm32f1, stm32f2, stm32f3, stm32l0, stm32l1))] |
| 68 | let cr = crate::pac::PWR.cr(); | 68 | let cr = crate::pac::PWR.cr(); |
| 69 | #[cfg(not(any(stm32f0, stm32f1, stm32f2, stm32f3, stm32l0, stm32l1, stm32u5, stm32h5, stm32wba)))] | 69 | #[cfg(not(any( |
| 70 | stm32f0, stm32f1, stm32f2, stm32f3, stm32l0, stm32l1, stm32u5, stm32h5, stm32wba, stm32n6 | ||
| 71 | )))] | ||
| 70 | let cr = crate::pac::PWR.cr1(); | 72 | let cr = crate::pac::PWR.cr1(); |
| 71 | #[cfg(any(stm32u5, stm32h5, stm32wba))] | 73 | #[cfg(any(stm32u5, stm32h5, stm32wba, stm32n6))] |
| 72 | let cr = crate::pac::PWR.dbpcr(); | 74 | let cr = crate::pac::PWR.dbpcr(); |
| 73 | 75 | ||
| 74 | cr.modify(|w| w.set_dbp(true)); | 76 | cr.modify(|w| w.set_dbp(true)); |
| @@ -175,14 +177,19 @@ impl LsConfig { | |||
| 175 | if self.lsi { | 177 | if self.lsi { |
| 176 | #[cfg(any(stm32u5, stm32h5, stm32wba))] | 178 | #[cfg(any(stm32u5, stm32h5, stm32wba))] |
| 177 | let csr = crate::pac::RCC.bdcr(); | 179 | let csr = crate::pac::RCC.bdcr(); |
| 178 | #[cfg(not(any(stm32u5, stm32h5, stm32wba, stm32c0)))] | 180 | #[cfg(stm32n6)] |
| 181 | let csr = crate::pac::RCC.sr(); | ||
| 182 | #[cfg(not(any(stm32u5, stm32h5, stm32wba, stm32c0, stm32n6)))] | ||
| 179 | let csr = crate::pac::RCC.csr(); | 183 | let csr = crate::pac::RCC.csr(); |
| 180 | #[cfg(any(stm32c0))] | 184 | #[cfg(stm32c0)] |
| 181 | let csr = crate::pac::RCC.csr2(); | 185 | let csr = crate::pac::RCC.csr2(); |
| 182 | 186 | ||
| 183 | #[cfg(not(any(rcc_wb, rcc_wba)))] | 187 | #[cfg(not(any(rcc_wb, rcc_wba, rcc_n6)))] |
| 184 | csr.modify(|w| w.set_lsion(true)); | 188 | csr.modify(|w| w.set_lsion(true)); |
| 185 | 189 | ||
| 190 | #[cfg(rcc_n6)] | ||
| 191 | crate::pac::RCC.cr().modify(|w| w.set_lsion(true)); | ||
| 192 | |||
| 186 | #[cfg(any(rcc_wb, rcc_wba))] | 193 | #[cfg(any(rcc_wb, rcc_wba))] |
| 187 | csr.modify(|w| w.set_lsi1on(true)); | 194 | csr.modify(|w| w.set_lsi1on(true)); |
| 188 | 195 | ||
| @@ -196,25 +203,58 @@ impl LsConfig { | |||
| 196 | // backup domain configuration (LSEON, RTCEN, RTCSEL) is kept across resets. | 203 | // backup domain configuration (LSEON, RTCEN, RTCSEL) is kept across resets. |
| 197 | // once set, changing it requires a backup domain reset. | 204 | // once set, changing it requires a backup domain reset. |
| 198 | // first check if the configuration matches what we want. | 205 | // first check if the configuration matches what we want. |
| 206 | // N6 has all the fields spread across multiple registers under RCC. | ||
| 199 | 207 | ||
| 200 | // check if it's already enabled and in the source we want. | 208 | // check if it's already enabled and in the source we want. |
| 209 | #[cfg(not(rcc_n6))] | ||
| 201 | let reg = bdcr().read(); | 210 | let reg = bdcr().read(); |
| 211 | #[cfg(rcc_n6)] | ||
| 212 | let reg = crate::pac::RCC.cr().read(); | ||
| 213 | #[cfg(rcc_n6)] | ||
| 214 | let apb4lenr = crate::pac::RCC.apb4lenr().read(); | ||
| 215 | #[cfg(rcc_n6)] | ||
| 216 | let ccipr7 = crate::pac::RCC.ccipr7().read(); | ||
| 217 | #[cfg(rcc_n6)] | ||
| 218 | let lsecfgr = crate::pac::RCC.lsecfgr().read(); | ||
| 219 | |||
| 202 | let mut ok = true; | 220 | let mut ok = true; |
| 203 | ok &= reg.rtcsel() == self.rtc; | 221 | #[cfg(not(rcc_n6))] |
| 204 | #[cfg(not(rcc_wba))] | 222 | { |
| 223 | ok &= reg.rtcsel() == self.rtc; | ||
| 224 | } | ||
| 225 | #[cfg(rcc_n6)] | ||
| 226 | { | ||
| 227 | ok &= ccipr7.rtcsel() == self.rtc; | ||
| 228 | } | ||
| 229 | #[cfg(not(any(rcc_wba, rcc_n6)))] | ||
| 205 | { | 230 | { |
| 206 | ok &= reg.rtcen() == (self.rtc != RtcClockSource::DISABLE); | 231 | ok &= reg.rtcen() == (self.rtc != RtcClockSource::DISABLE); |
| 207 | } | 232 | } |
| 233 | #[cfg(rcc_n6)] | ||
| 234 | { | ||
| 235 | ok &= apb4lenr.rtcen() == (self.rtc != RtcClockSource::DISABLE); | ||
| 236 | } | ||
| 208 | ok &= reg.lseon() == lse_en; | 237 | ok &= reg.lseon() == lse_en; |
| 209 | ok &= reg.lsebyp() == lse_byp; | 238 | #[cfg(not(rcc_n6))] |
| 239 | { | ||
| 240 | ok &= reg.lsebyp() == lse_byp; | ||
| 241 | } | ||
| 242 | #[cfg(rcc_n6)] | ||
| 243 | { | ||
| 244 | ok &= lsecfgr.lsebyp() == lse_byp; | ||
| 245 | } | ||
| 210 | #[cfg(any(rcc_l5, rcc_u5, rcc_wle, rcc_wl5, rcc_wba, rcc_u0))] | 246 | #[cfg(any(rcc_l5, rcc_u5, rcc_wle, rcc_wl5, rcc_wba, rcc_u0))] |
| 211 | if let Some(lse_sysen) = lse_sysen { | 247 | if let Some(lse_sysen) = lse_sysen { |
| 212 | ok &= reg.lsesysen() == lse_sysen; | 248 | ok &= reg.lsesysen() == lse_sysen; |
| 213 | } | 249 | } |
| 214 | #[cfg(not(any(rcc_f1, rcc_f1cl, rcc_f100, rcc_f2, rcc_f4, rcc_f410, rcc_l1)))] | 250 | #[cfg(not(any(rcc_f1, rcc_f1cl, rcc_f100, rcc_f2, rcc_f4, rcc_f410, rcc_l1, rcc_n6)))] |
| 215 | if let Some(lse_drv) = lse_drv { | 251 | if let Some(lse_drv) = lse_drv { |
| 216 | ok &= reg.lsedrv() == lse_drv.into(); | 252 | ok &= reg.lsedrv() == lse_drv.into(); |
| 217 | } | 253 | } |
| 254 | #[cfg(rcc_n6)] | ||
| 255 | if let Some(lse_drv) = lse_drv { | ||
| 256 | ok &= lsecfgr.lsedrv() == lse_drv.into(); | ||
| 257 | } | ||
| 218 | 258 | ||
| 219 | // if configuration is OK, we're done. | 259 | // if configuration is OK, we're done. |
| 220 | if ok { | 260 | if ok { |
| @@ -223,7 +263,7 @@ impl LsConfig { | |||
| 223 | } | 263 | } |
| 224 | 264 | ||
| 225 | // If not OK, reset backup domain and configure it. | 265 | // If not OK, reset backup domain and configure it. |
| 226 | #[cfg(not(any(rcc_l0, rcc_l0_v2, rcc_l1, stm32h5, stm32h7rs, stm32c0)))] | 266 | #[cfg(not(any(rcc_l0, rcc_l0_v2, rcc_l1, stm32h5, stm32h7rs, stm32c0, stm32n6)))] |
| 227 | { | 267 | { |
| 228 | bdcr().modify(|w| w.set_bdrst(true)); | 268 | bdcr().modify(|w| w.set_bdrst(true)); |
| 229 | bdcr().modify(|w| w.set_bdrst(false)); | 269 | bdcr().modify(|w| w.set_bdrst(false)); |
| @@ -236,7 +276,7 @@ impl LsConfig { | |||
| 236 | // STM32H503CB/EB/KB/RB device errata - 2.2.8 SRAM2 unduly erased upon a backup domain reset | 276 | // STM32H503CB/EB/KB/RB device errata - 2.2.8 SRAM2 unduly erased upon a backup domain reset |
| 237 | // STM32H562xx/563xx/573xx device errata - 2.2.14 SRAM2 is erased when the backup domain is reset | 277 | // STM32H562xx/563xx/573xx device errata - 2.2.14 SRAM2 is erased when the backup domain is reset |
| 238 | //#[cfg(any(stm32h5, stm32h7rs))] | 278 | //#[cfg(any(stm32h5, stm32h7rs))] |
| 239 | #[cfg(any(stm32h7rs))] | 279 | #[cfg(any(stm32h7rs, stm32n6))] |
| 240 | { | 280 | { |
| 241 | bdcr().modify(|w| w.set_vswrst(true)); | 281 | bdcr().modify(|w| w.set_vswrst(true)); |
| 242 | bdcr().modify(|w| w.set_vswrst(false)); | 282 | bdcr().modify(|w| w.set_vswrst(false)); |
| @@ -248,16 +288,31 @@ impl LsConfig { | |||
| 248 | } | 288 | } |
| 249 | 289 | ||
| 250 | if lse_en { | 290 | if lse_en { |
| 251 | bdcr().modify(|w| { | 291 | #[cfg(not(rcc_n6))] |
| 252 | #[cfg(not(any(rcc_f1, rcc_f1cl, rcc_f100, rcc_f2, rcc_f4, rcc_f410, rcc_l1)))] | 292 | { |
| 253 | if let Some(lse_drv) = lse_drv { | 293 | bdcr().modify(|w| { |
| 254 | w.set_lsedrv(lse_drv.into()); | 294 | #[cfg(not(any(rcc_f1, rcc_f1cl, rcc_f100, rcc_f2, rcc_f4, rcc_f410, rcc_l1)))] |
| 255 | } | 295 | if let Some(lse_drv) = lse_drv { |
| 256 | w.set_lsebyp(lse_byp); | 296 | w.set_lsedrv(lse_drv.into()); |
| 257 | w.set_lseon(true); | 297 | } |
| 258 | }); | 298 | w.set_lsebyp(lse_byp); |
| 299 | w.set_lseon(true); | ||
| 300 | }); | ||
| 259 | 301 | ||
| 260 | while !bdcr().read().lserdy() {} | 302 | while !bdcr().read().lserdy() {} |
| 303 | } | ||
| 304 | #[cfg(rcc_n6)] | ||
| 305 | { | ||
| 306 | crate::pac::RCC.lsecfgr().modify(|w| { | ||
| 307 | if let Some(lse_drv) = lse_drv { | ||
| 308 | w.set_lsedrv(lse_drv.into()); | ||
| 309 | } | ||
| 310 | w.set_lsebyp(lse_byp); | ||
| 311 | }); | ||
| 312 | crate::pac::RCC.cr().modify(|w| w.set_lseon(true)); | ||
| 313 | |||
| 314 | while !crate::pac::RCC.sr().read().lserdy() {} | ||
| 315 | } | ||
| 261 | 316 | ||
| 262 | #[cfg(any(rcc_l5, rcc_u5, rcc_wle, rcc_wl5, rcc_wba, rcc_u0))] | 317 | #[cfg(any(rcc_l5, rcc_u5, rcc_wle, rcc_wl5, rcc_wba, rcc_u0))] |
| 263 | if let Some(lse_sysen) = lse_sysen { | 318 | if let Some(lse_sysen) = lse_sysen { |
| @@ -272,6 +327,7 @@ impl LsConfig { | |||
| 272 | } | 327 | } |
| 273 | 328 | ||
| 274 | if self.rtc != RtcClockSource::DISABLE { | 329 | if self.rtc != RtcClockSource::DISABLE { |
| 330 | #[cfg(not(rcc_n6))] | ||
| 275 | bdcr().modify(|w| { | 331 | bdcr().modify(|w| { |
| 276 | #[cfg(any(rtc_v2h7, rtc_v2l4, rtc_v2wb, rtc_v3, rtc_v3u5))] | 332 | #[cfg(any(rtc_v2h7, rtc_v2l4, rtc_v2wb, rtc_v3, rtc_v3u5))] |
| 277 | assert!(!w.lsecsson(), "RTC is not compatible with LSE CSS, yet."); | 333 | assert!(!w.lsecsson(), "RTC is not compatible with LSE CSS, yet."); |
| @@ -280,6 +336,12 @@ impl LsConfig { | |||
| 280 | w.set_rtcen(true); | 336 | w.set_rtcen(true); |
| 281 | w.set_rtcsel(self.rtc); | 337 | w.set_rtcsel(self.rtc); |
| 282 | }); | 338 | }); |
| 339 | |||
| 340 | #[cfg(rcc_n6)] | ||
| 341 | { | ||
| 342 | crate::pac::RCC.ccipr7().modify(|w| w.set_rtcsel(self.rtc)); | ||
| 343 | crate::pac::RCC.apb4lenr().modify(|w| w.set_rtcen(true)) | ||
| 344 | } | ||
| 283 | } | 345 | } |
| 284 | 346 | ||
| 285 | trace!("BDCR configured: {:08x}", bdcr().read().0); | 347 | trace!("BDCR configured: {:08x}", bdcr().read().0); |
