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 4444//! * C, D, E => `high` feature
4545//! * F, G => `xl` feature
4646//!
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+ //! ```
4767//!
4868//! ## Usage examples
4969//!
Original file line number Diff line number Diff line change @@ -203,6 +203,19 @@ impl CFGR {
203203 self
204204 }
205205
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+
206219 pub fn freeze ( self , acr : & mut ACR ) -> Clocks {
207220 let pllsrcclk = self . hse . unwrap_or ( HSI / 2 ) ;
208221
@@ -456,6 +469,7 @@ impl BKP {
456469/// ```rust
457470/// let dp = pac::Peripherals::take().unwrap();
458471/// let mut rcc = dp.RCC.constrain();
472+ /// let mut flash = dp.FLASH.constrain();
459473///
460474/// let clocks = rcc.cfgr.freeze(&mut flash.acr);
461475/// ```
You can’t perform that action at this time.
0 commit comments