File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 44
44
//! * C, D, E => `high` feature
45
45
//! * F, G => `xl` feature
46
46
//!
47
+ //! ## Commonly used setup
48
+ //! Almost all peripherals require references to some registers in `RCC` and `AFIO`. The following
49
+ //! code shows how to set up those registers
50
+ //!
51
+ //! ```rust
52
+ //! // Get access to the device specific peripherals from the peripheral access crate
53
+ //! let dp = pac::Peripherals::take().unwrap();
54
+ //!
55
+ //! // Take ownership over the raw flash and rcc devices and convert them into the corresponding
56
+ //! // HAL structs
57
+ //! let mut flash = dp.FLASH.constrain();
58
+ //! let mut rcc = dp.RCC.constrain();
59
+ //!
60
+ //! // Freeze the configuration of all the clocks in the system and store the frozen frequencies in
61
+ //! // `clocks`
62
+ //! let clocks = rcc.cfgr.freeze(&mut flash.acr);
63
+ //!
64
+ //! // Prepare the alternate function I/O registers
65
+ //! let mut afio = dp.AFIO.constrain(&mut rcc.apb2);
66
+ //! ```
47
67
//!
48
68
//! ## Usage examples
49
69
//!
Original file line number Diff line number Diff line change @@ -203,6 +203,19 @@ impl CFGR {
203
203
self
204
204
}
205
205
206
+ /// Applies the clock configuration and returns a `Clocks` struct that signifies that the
207
+ /// clocks are frozen, and contains the frequencies used. After this function is called,
208
+ /// the clocks can not change
209
+ ///
210
+ /// Usage:
211
+ ///
212
+ /// ```rust
213
+ /// let dp = pac::Peripherals::take().unwrap();
214
+ /// let mut flash = dp.FLASH.constrain();
215
+ /// let mut rcc = dp.RCC.constrain();
216
+ /// let clocks = rcc.cfgr.freeze(&mut flash.acr);
217
+ /// ```
218
+
206
219
pub fn freeze ( self , acr : & mut ACR ) -> Clocks {
207
220
let pllsrcclk = self . hse . unwrap_or ( HSI / 2 ) ;
208
221
@@ -456,6 +469,7 @@ impl BKP {
456
469
/// ```rust
457
470
/// let dp = pac::Peripherals::take().unwrap();
458
471
/// let mut rcc = dp.RCC.constrain();
472
+ /// let mut flash = dp.FLASH.constrain();
459
473
///
460
474
/// let clocks = rcc.cfgr.freeze(&mut flash.acr);
461
475
/// ```
You can’t perform that action at this time.
0 commit comments