rcc.rs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. //! # Reset & Control Clock
  2. use core::cmp;
  3. use crate::pac::{rcc, PWR, RCC};
  4. use cast::u32;
  5. use crate::flash::ACR;
  6. use crate::time::Hertz;
  7. use crate::backup_domain::BackupDomain;
  8. /// Extension trait that constrains the `RCC` peripheral
  9. pub trait RccExt {
  10. /// Constrains the `RCC` peripheral so it plays nicely with the other abstractions
  11. fn constrain(self) -> Rcc;
  12. }
  13. impl RccExt for RCC {
  14. fn constrain(self) -> Rcc {
  15. Rcc {
  16. ahb: AHB { _0: () },
  17. apb1: APB1 { _0: () },
  18. apb2: APB2 { _0: () },
  19. cfgr: CFGR {
  20. hse: None,
  21. hclk: None,
  22. pclk1: None,
  23. pclk2: None,
  24. sysclk: None,
  25. adcclk: None,
  26. },
  27. bkp: BKP { _0: () },
  28. }
  29. }
  30. }
  31. /// Constrained RCC peripheral
  32. ///
  33. /// Aquired by calling the [constrain](../trait.RccExt.html#tymethod.constrain) method
  34. /// on the Rcc struct from the `PAC`
  35. ///
  36. /// ```rust
  37. /// let dp = pac::Peripherals::take().unwrap();
  38. /// let mut rcc = dp.RCC.constrain();
  39. /// ```
  40. pub struct Rcc {
  41. /// AMBA High-performance Bus (AHB) registers
  42. pub ahb: AHB,
  43. /// Advanced Peripheral Bus 1 (APB1) registers
  44. pub apb1: APB1,
  45. /// Advanced Peripheral Bus 2 (APB2) registers
  46. pub apb2: APB2,
  47. pub cfgr: CFGR,
  48. pub bkp: BKP,
  49. }
  50. /// AMBA High-performance Bus (AHB) registers
  51. ///
  52. /// Aquired through the `Rcc` registers:
  53. ///
  54. /// ```rust
  55. /// let dp = pac::Peripherals::take().unwrap();
  56. /// let mut rcc = dp.RCC.constrain();
  57. /// function_that_uses_ahb(&mut rcc.ahb)
  58. /// ```
  59. pub struct AHB {
  60. _0: (),
  61. }
  62. impl AHB {
  63. // TODO remove `allow`
  64. #[allow(dead_code)]
  65. pub(crate) fn enr(&mut self) -> &rcc::AHBENR {
  66. // NOTE(unsafe) this proxy grants exclusive access to this register
  67. unsafe { &(*RCC::ptr()).ahbenr }
  68. }
  69. }
  70. /// Advanced Peripheral Bus 1 (APB1) registers
  71. ///
  72. /// Aquired through the `Rcc` registers:
  73. ///
  74. /// ```rust
  75. /// let dp = pac::Peripherals::take().unwrap();
  76. /// let mut rcc = dp.RCC.constrain();
  77. /// function_that_uses_apb1(&mut rcc.apb1)
  78. /// ```
  79. pub struct APB1 {
  80. _0: (),
  81. }
  82. impl APB1 {
  83. pub(crate) fn enr(&mut self) -> &rcc::APB1ENR {
  84. // NOTE(unsafe) this proxy grants exclusive access to this register
  85. unsafe { &(*RCC::ptr()).apb1enr }
  86. }
  87. pub(crate) fn rstr(&mut self) -> &rcc::APB1RSTR {
  88. // NOTE(unsafe) this proxy grants exclusive access to this register
  89. unsafe { &(*RCC::ptr()).apb1rstr }
  90. }
  91. }
  92. impl APB1 {
  93. /// Set power interface clock (PWREN) bit in RCC_APB1ENR
  94. pub fn set_pwren(&mut self) {
  95. self.enr().modify(|_r, w| w.pwren().set_bit())
  96. }
  97. }
  98. /// Advanced Peripheral Bus 2 (APB2) registers
  99. ///
  100. /// Aquired through the `Rcc` registers:
  101. ///
  102. /// ```rust
  103. /// let dp = pac::Peripherals::take().unwrap();
  104. /// let mut rcc = dp.RCC.constrain();
  105. /// function_that_uses_apb2(&mut rcc.apb2);
  106. /// ```
  107. pub struct APB2 {
  108. _0: (),
  109. }
  110. impl APB2 {
  111. pub(crate) fn enr(&mut self) -> &rcc::APB2ENR {
  112. // NOTE(unsafe) this proxy grants exclusive access to this register
  113. unsafe { &(*RCC::ptr()).apb2enr }
  114. }
  115. pub(crate) fn rstr(&mut self) -> &rcc::APB2RSTR {
  116. // NOTE(unsafe) this proxy grants exclusive access to this register
  117. unsafe { &(*RCC::ptr()).apb2rstr }
  118. }
  119. }
  120. const HSI: u32 = 8_000_000; // Hz
  121. /// Clock configuration register (CFGR)
  122. ///
  123. /// Used to configure the frequencies of the clocks present in the processor.
  124. ///
  125. /// After setting all frequencies, call the [freeze](#method.freeze) function to
  126. /// apply the configuration.
  127. ///
  128. /// **NOTE**: Currently, it is not guaranteed that the exact frequencies selected will be
  129. /// used, only frequencies close to it.
  130. pub struct CFGR {
  131. hse: Option<u32>,
  132. hclk: Option<u32>,
  133. pclk1: Option<u32>,
  134. pclk2: Option<u32>,
  135. sysclk: Option<u32>,
  136. adcclk: Option<u32>,
  137. }
  138. impl CFGR {
  139. /// Uses HSE (external oscillator) instead of HSI (internal RC oscillator) as the clock source.
  140. /// Will result in a hang if an external oscillator is not connected or it fails to start.
  141. /// The frequency specified must be the frequency of the external oscillator
  142. pub fn use_hse<F>(mut self, freq: F) -> Self
  143. where
  144. F: Into<Hertz>,
  145. {
  146. self.hse = Some(freq.into().0);
  147. self
  148. }
  149. /// Sets the desired frequency for the HCLK clock
  150. pub fn hclk<F>(mut self, freq: F) -> Self
  151. where
  152. F: Into<Hertz>,
  153. {
  154. self.hclk = Some(freq.into().0);
  155. self
  156. }
  157. /// Sets the desired frequency for the PCKL1 clock
  158. pub fn pclk1<F>(mut self, freq: F) -> Self
  159. where
  160. F: Into<Hertz>,
  161. {
  162. self.pclk1 = Some(freq.into().0);
  163. self
  164. }
  165. /// Sets the desired frequency for the PCLK2 clock
  166. pub fn pclk2<F>(mut self, freq: F) -> Self
  167. where
  168. F: Into<Hertz>,
  169. {
  170. self.pclk2 = Some(freq.into().0);
  171. self
  172. }
  173. /// Sets the desired frequency for the SYSCLK clock
  174. pub fn sysclk<F>(mut self, freq: F) -> Self
  175. where
  176. F: Into<Hertz>,
  177. {
  178. self.sysclk = Some(freq.into().0);
  179. self
  180. }
  181. /// Sets the desired frequency for the ADCCLK clock
  182. pub fn adcclk<F>(mut self, freq: F) -> Self
  183. where
  184. F: Into<Hertz>,
  185. {
  186. self.adcclk = Some(freq.into().0);
  187. self
  188. }
  189. /// Applies the clock configuration and returns a `Clocks` struct that signifies that the
  190. /// clocks are frozen, and contains the frequencies used. After this function is called,
  191. /// the clocks can not change
  192. ///
  193. /// Usage:
  194. ///
  195. /// ```rust
  196. /// let dp = pac::Peripherals::take().unwrap();
  197. /// let mut flash = dp.FLASH.constrain();
  198. /// let mut rcc = dp.RCC.constrain();
  199. /// let clocks = rcc.cfgr.freeze(&mut flash.acr);
  200. /// ```
  201. pub fn freeze(self, acr: &mut ACR) -> Clocks {
  202. let pllsrcclk = self.hse.unwrap_or(HSI / 2);
  203. let pllmul = self.sysclk.unwrap_or(pllsrcclk) / pllsrcclk;
  204. let (pllmul_bits, sysclk) = if pllmul == 1 {
  205. (None, self.hse.unwrap_or(HSI))
  206. } else {
  207. #[cfg(not(feature = "connectivity"))]
  208. let pllmul = cmp::min(cmp::max(pllmul, 1), 16);
  209. #[cfg(feature = "connectivity")]
  210. let pllmul = cmp::min(cmp::max(pllmul, 4), 9);
  211. (Some(pllmul as u8 - 2), pllsrcclk * pllmul)
  212. };
  213. assert!(sysclk <= 72_000_000);
  214. let hpre_bits = self
  215. .hclk
  216. .map(|hclk| match sysclk / hclk {
  217. 0 => unreachable!(),
  218. 1 => 0b0111,
  219. 2 => 0b1000,
  220. 3..=5 => 0b1001,
  221. 6..=11 => 0b1010,
  222. 12..=39 => 0b1011,
  223. 40..=95 => 0b1100,
  224. 96..=191 => 0b1101,
  225. 192..=383 => 0b1110,
  226. _ => 0b1111,
  227. })
  228. .unwrap_or(0b0111);
  229. let hclk = if hpre_bits >= 0b1100 {
  230. sysclk / (1 << (hpre_bits - 0b0110))
  231. } else {
  232. sysclk / (1 << (hpre_bits - 0b0111))
  233. };
  234. assert!(hclk <= 72_000_000);
  235. let ppre1_bits = self
  236. .pclk1
  237. .map(|pclk1| match hclk / pclk1 {
  238. 0 => unreachable!(),
  239. 1 => 0b011,
  240. 2 => 0b100,
  241. 3..=5 => 0b101,
  242. 6..=11 => 0b110,
  243. _ => 0b111,
  244. })
  245. .unwrap_or(0b011);
  246. let ppre1 = 1 << (ppre1_bits - 0b011);
  247. let pclk1 = hclk / u32(ppre1);
  248. assert!(pclk1 <= 36_000_000);
  249. let ppre2_bits = self
  250. .pclk2
  251. .map(|pclk2| match hclk / pclk2 {
  252. 0 => unreachable!(),
  253. 1 => 0b011,
  254. 2 => 0b100,
  255. 3..=5 => 0b101,
  256. 6..=11 => 0b110,
  257. _ => 0b111,
  258. })
  259. .unwrap_or(0b011);
  260. let ppre2 = 1 << (ppre2_bits - 0b011);
  261. let pclk2 = hclk / u32(ppre2);
  262. assert!(pclk2 <= 72_000_000);
  263. // adjust flash wait states
  264. #[cfg(any(feature = "stm32f103", feature = "connectivity"))]
  265. unsafe {
  266. acr.acr().write(|w| {
  267. w.latency().bits(if sysclk <= 24_000_000 {
  268. 0b000
  269. } else if sysclk <= 48_000_000 {
  270. 0b001
  271. } else {
  272. 0b010
  273. })
  274. })
  275. }
  276. // the USB clock is only valid if an external crystal is used, the PLL is enabled, and the
  277. // PLL output frequency is a supported one.
  278. // usbpre == false: divide clock by 1.5, otherwise no division
  279. let (usbpre, usbclk_valid) = match (self.hse, pllmul_bits, sysclk) {
  280. (Some(_), Some(_), 72_000_000) => (false, true),
  281. (Some(_), Some(_), 48_000_000) => (true, true),
  282. _ => (true, false),
  283. };
  284. let apre_bits: u8 = self
  285. .adcclk
  286. .map(|adcclk| match pclk2 / adcclk {
  287. 0..=2 => 0b00,
  288. 3..=4 => 0b01,
  289. 5..=7 => 0b10,
  290. _ => 0b11,
  291. })
  292. .unwrap_or(0b11);
  293. let apre = (apre_bits + 1) << 1;
  294. let adcclk = pclk2 / u32(apre);
  295. assert!(adcclk <= 14_000_000);
  296. let rcc = unsafe { &*RCC::ptr() };
  297. if self.hse.is_some() {
  298. // enable HSE and wait for it to be ready
  299. rcc.cr.modify(|_, w| w.hseon().set_bit());
  300. while rcc.cr.read().hserdy().bit_is_clear() {}
  301. }
  302. if let Some(pllmul_bits) = pllmul_bits {
  303. // enable PLL and wait for it to be ready
  304. #[allow(unused_unsafe)]
  305. rcc.cfgr.modify(|_, w| unsafe {
  306. w.pllmul()
  307. .bits(pllmul_bits)
  308. .pllsrc()
  309. .bit(self.hse.is_some())
  310. });
  311. rcc.cr.modify(|_, w| w.pllon().set_bit());
  312. while rcc.cr.read().pllrdy().bit_is_clear() {}
  313. }
  314. // set prescalers and clock source
  315. #[cfg(feature = "connectivity")]
  316. rcc.cfgr.modify(|_, w| unsafe {
  317. w.adcpre().bits(apre_bits);
  318. w.ppre2()
  319. .bits(ppre2_bits)
  320. .ppre1()
  321. .bits(ppre1_bits)
  322. .hpre()
  323. .bits(hpre_bits)
  324. .otgfspre()
  325. .bit(usbpre)
  326. .sw()
  327. .bits(if pllmul_bits.is_some() {
  328. // PLL
  329. 0b10
  330. } else if self.hse.is_some() {
  331. // HSE
  332. 0b1
  333. } else {
  334. // HSI
  335. 0b0
  336. })
  337. });
  338. #[cfg(feature = "stm32f103")]
  339. rcc.cfgr.modify(|_, w| unsafe {
  340. w.adcpre().bits(apre_bits);
  341. w.ppre2()
  342. .bits(ppre2_bits)
  343. .ppre1()
  344. .bits(ppre1_bits)
  345. .hpre()
  346. .bits(hpre_bits)
  347. .usbpre()
  348. .bit(usbpre)
  349. .sw()
  350. .bits(if pllmul_bits.is_some() {
  351. // PLL
  352. 0b10
  353. } else if self.hse.is_some() {
  354. // HSE
  355. 0b1
  356. } else {
  357. // HSI
  358. 0b0
  359. })
  360. });
  361. #[cfg(any(feature = "stm32f100", feature = "stm32f101"))]
  362. rcc.cfgr.modify(|_, w| unsafe {
  363. w.adcpre().bits(apre_bits);
  364. w.ppre2()
  365. .bits(ppre2_bits)
  366. .ppre1()
  367. .bits(ppre1_bits)
  368. .hpre()
  369. .bits(hpre_bits)
  370. .sw()
  371. .bits(if pllmul_bits.is_some() {
  372. // PLL
  373. 0b10
  374. } else if self.hse.is_some() {
  375. // HSE
  376. 0b1
  377. } else {
  378. // HSI
  379. 0b0
  380. })
  381. });
  382. Clocks {
  383. hclk: Hertz(hclk),
  384. pclk1: Hertz(pclk1),
  385. pclk2: Hertz(pclk2),
  386. ppre1,
  387. ppre2,
  388. sysclk: Hertz(sysclk),
  389. adcclk: Hertz(adcclk),
  390. usbclk_valid,
  391. }
  392. }
  393. }
  394. pub struct BKP {
  395. _0: (),
  396. }
  397. impl BKP {
  398. /// Enables write access to the registers in the backup domain
  399. pub fn constrain(self, bkp: crate::pac::BKP, apb1: &mut APB1, pwr: &mut PWR) -> BackupDomain {
  400. // Enable the backup interface by setting PWREN and BKPEN
  401. apb1.enr()
  402. .modify(|_r, w| w.bkpen().set_bit().pwren().set_bit());
  403. // Enable access to the backup registers
  404. pwr.cr.modify(|_r, w| w.dbp().set_bit());
  405. BackupDomain { _regs: bkp }
  406. }
  407. }
  408. /// Frozen clock frequencies
  409. ///
  410. /// The existence of this value indicates that the clock configuration can no longer be changed
  411. ///
  412. /// To acquire it, use the freeze function on the `rcc.cfgr` register. If desired, you can adjust
  413. /// the frequencies using the methods on [cfgr](struct.CFGR.html) before calling freeze.
  414. ///
  415. /// ```rust
  416. /// let dp = pac::Peripherals::take().unwrap();
  417. /// let mut rcc = dp.RCC.constrain();
  418. /// let mut flash = dp.FLASH.constrain();
  419. ///
  420. /// let clocks = rcc.cfgr.freeze(&mut flash.acr);
  421. /// ```
  422. #[derive(Clone, Copy)]
  423. pub struct Clocks {
  424. hclk: Hertz,
  425. pclk1: Hertz,
  426. pclk2: Hertz,
  427. ppre1: u8,
  428. ppre2: u8,
  429. sysclk: Hertz,
  430. adcclk: Hertz,
  431. usbclk_valid: bool,
  432. }
  433. impl Clocks {
  434. /// Returns the frequency of the AHB
  435. pub fn hclk(&self) -> Hertz {
  436. self.hclk
  437. }
  438. /// Returns the frequency of the APB1
  439. pub fn pclk1(&self) -> Hertz {
  440. self.pclk1
  441. }
  442. /// Returns the frequency of the APB2
  443. pub fn pclk2(&self) -> Hertz {
  444. self.pclk2
  445. }
  446. /// Returns the frequency of the APB1 Timers
  447. pub fn pclk1_tim(&self) -> Hertz {
  448. Hertz(self.pclk1.0 * if self.ppre1() == 1 { 1 } else { 2 })
  449. }
  450. /// Returns the frequency of the APB2 Timers
  451. pub fn pclk2_tim(&self) -> Hertz {
  452. Hertz(self.pclk2.0 * if self.ppre2() == 1 { 1 } else { 2 })
  453. }
  454. pub(crate) fn ppre1(&self) -> u8 {
  455. self.ppre1
  456. }
  457. // TODO remove `allow`
  458. #[allow(dead_code)]
  459. pub(crate) fn ppre2(&self) -> u8 {
  460. self.ppre2
  461. }
  462. /// Returns the system (core) frequency
  463. pub fn sysclk(&self) -> Hertz {
  464. self.sysclk
  465. }
  466. /// Returns the adc clock frequency
  467. pub fn adcclk(&self) -> Hertz {
  468. self.adcclk
  469. }
  470. /// Returns whether the USBCLK clock frequency is valid for the USB peripheral
  471. pub fn usbclk_valid(&self) -> bool {
  472. self.usbclk_valid
  473. }
  474. }
  475. pub trait GetBusFreq {
  476. fn get_frequency(clocks: &Clocks) -> Hertz;
  477. fn get_timer_frequency(clocks: &Clocks) -> Hertz {
  478. Self::get_frequency(clocks)
  479. }
  480. }
  481. impl GetBusFreq for AHB {
  482. fn get_frequency(clocks: &Clocks) -> Hertz {
  483. clocks.hclk
  484. }
  485. }
  486. impl GetBusFreq for APB1 {
  487. fn get_frequency(clocks: &Clocks) -> Hertz {
  488. clocks.pclk1
  489. }
  490. fn get_timer_frequency(clocks: &Clocks) -> Hertz {
  491. clocks.pclk1_tim()
  492. }
  493. }
  494. impl GetBusFreq for APB2 {
  495. fn get_frequency(clocks: &Clocks) -> Hertz {
  496. clocks.pclk2
  497. }
  498. fn get_timer_frequency(clocks: &Clocks) -> Hertz {
  499. clocks.pclk2_tim()
  500. }
  501. }
  502. pub(crate) mod sealed {
  503. /// Bus associated to peripheral
  504. pub trait RccBus {
  505. /// Bus type;
  506. type Bus;
  507. }
  508. }
  509. use sealed::RccBus;
  510. /// Enable/disable peripheral
  511. pub trait Enable: RccBus {
  512. fn enable(apb: &mut Self::Bus);
  513. fn disable(apb: &mut Self::Bus);
  514. }
  515. /// Reset peripheral
  516. pub trait Reset: RccBus {
  517. fn reset(apb: &mut Self::Bus);
  518. }
  519. macro_rules! bus {
  520. ($($PER:ident => ($apbX:ty, $peren:ident, $perrst:ident),)+) => {
  521. $(
  522. impl RccBus for crate::pac::$PER {
  523. type Bus = $apbX;
  524. }
  525. impl Enable for crate::pac::$PER {
  526. #[inline(always)]
  527. fn enable(apb: &mut Self::Bus) {
  528. apb.enr().modify(|_, w| w.$peren().set_bit());
  529. }
  530. #[inline(always)]
  531. fn disable(apb: &mut Self::Bus) {
  532. apb.enr().modify(|_, w| w.$peren().clear_bit());
  533. }
  534. }
  535. impl Reset for crate::pac::$PER {
  536. #[inline(always)]
  537. fn reset(apb: &mut Self::Bus) {
  538. apb.rstr().modify(|_, w| w.$perrst().set_bit());
  539. apb.rstr().modify(|_, w| w.$perrst().clear_bit());
  540. }
  541. }
  542. )+
  543. }
  544. }
  545. macro_rules! ahb_bus {
  546. ($($PER:ident => ($peren:ident),)+) => {
  547. $(
  548. impl RccBus for crate::pac::$PER {
  549. type Bus = AHB;
  550. }
  551. impl Enable for crate::pac::$PER {
  552. #[inline(always)]
  553. fn enable(apb: &mut Self::Bus) {
  554. apb.enr().modify(|_, w| w.$peren().set_bit());
  555. }
  556. #[inline(always)]
  557. fn disable(apb: &mut Self::Bus) {
  558. apb.enr().modify(|_, w| w.$peren().clear_bit());
  559. }
  560. }
  561. )+
  562. }
  563. }
  564. #[cfg(feature = "stm32f103")]
  565. bus! {
  566. ADC2 => (APB2, adc2en, adc2rst),
  567. CAN1 => (APB1, canen, canrst),
  568. }
  569. #[cfg(feature = "connectivity")]
  570. bus! {
  571. ADC2 => (APB2, adc2en, adc2rst),
  572. CAN1 => (APB1, can1en, can1rst),
  573. CAN2 => (APB1, can2en, can2rst),
  574. }
  575. #[cfg(all(feature = "stm32f103", feature = "high",))]
  576. bus! {
  577. ADC3 => (APB2, adc3en, adc3rst),
  578. }
  579. bus! {
  580. ADC1 => (APB2, adc1en, adc1rst),
  581. AFIO => (APB2, afioen, afiorst),
  582. GPIOA => (APB2, iopaen, ioparst),
  583. GPIOB => (APB2, iopben, iopbrst),
  584. GPIOC => (APB2, iopcen, iopcrst),
  585. GPIOD => (APB2, iopden, iopdrst),
  586. GPIOE => (APB2, iopeen, ioperst),
  587. I2C1 => (APB1, i2c1en, i2c1rst),
  588. I2C2 => (APB1, i2c2en, i2c2rst),
  589. SPI1 => (APB2, spi1en, spi1rst),
  590. SPI2 => (APB1, spi2en, spi2rst),
  591. USART1 => (APB2, usart1en, usart1rst),
  592. USART2 => (APB1, usart2en, usart2rst),
  593. USART3 => (APB1, usart3en, usart3rst),
  594. WWDG => (APB1, wwdgen, wwdgrst),
  595. }
  596. #[cfg(any(feature = "high", feature = "connectivity"))]
  597. bus! {
  598. SPI3 => (APB1, spi3en, spi3rst),
  599. }
  600. ahb_bus! {
  601. CRC => (crcen),
  602. DMA1 => (dma1en),
  603. DMA2 => (dma2en),
  604. }
  605. #[cfg(feature = "high")]
  606. ahb_bus! {
  607. FSMC => (fsmcen),
  608. }
  609. bus! {
  610. TIM2 => (APB1, tim2en, tim2rst),
  611. TIM3 => (APB1, tim3en, tim3rst),
  612. }
  613. #[cfg(any(feature = "stm32f100", feature = "stm32f103", feature = "connectivity"))]
  614. bus! {
  615. TIM1 => (APB2, tim1en, tim1rst),
  616. }
  617. #[cfg(any(feature = "stm32f100", feature = "high", feature = "connectivity"))]
  618. bus! {
  619. TIM6 => (APB1, tim6en, tim6rst),
  620. }
  621. #[cfg(any(
  622. all(feature = "high", any(feature = "stm32f101", feature = "stm32f103")),
  623. any(feature = "stm32f100", feature = "connectivity")
  624. ))]
  625. bus! {
  626. TIM7 => (APB1, tim7en, tim7rst),
  627. }
  628. #[cfg(feature = "stm32f100")]
  629. bus! {
  630. TIM15 => (APB2, tim15en, tim15rst),
  631. TIM16 => (APB2, tim16en, tim16rst),
  632. TIM17 => (APB2, tim17en, tim17rst),
  633. }
  634. #[cfg(feature = "medium")]
  635. bus! {
  636. TIM4 => (APB1, tim4en, tim4rst),
  637. }
  638. #[cfg(any(feature = "high", feature = "connectivity"))]
  639. bus! {
  640. TIM5 => (APB1, tim5en, tim5rst),
  641. }
  642. #[cfg(any(feature = "xl", all(feature = "stm32f100", feature = "high",)))]
  643. bus! {
  644. TIM12 => (APB1, tim12en, tim12rst),
  645. TIM13 => (APB1, tim13en, tim13rst),
  646. TIM14 => (APB1, tim14en, tim14rst),
  647. }
  648. #[cfg(all(feature = "stm32f103", feature = "high",))]
  649. bus! {
  650. TIM8 => (APB2, tim8en, tim8rst),
  651. }
  652. #[cfg(feature = "xl")]
  653. bus! {
  654. TIM9 => (APB2, tim9en, tim9rst),
  655. TIM10 => (APB2, tim10en, tim10rst),
  656. TIM11 => (APB2, tim11en, tim11rst),
  657. }
  658. #[cfg(any(feature = "stm32f102", feature = "stm32f103"))]
  659. bus! {
  660. USB => (APB1, usben, usbrst),
  661. }