Skip to content

Commit 494b996

Browse files
committed
Add top level docs explaining how to get access to rcc, afio, clocks and flash
1 parent bcd558f commit 494b996

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@
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
//!

src/rcc.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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
/// ```

0 commit comments

Comments
 (0)