rcc.rs 19 KB

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