Skip to content

Commit bcd558f

Browse files
committed
Improve documentation for commonly used register blocks
1 parent ae870eb commit bcd558f

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1616
- Use `Deref` for I2C generic implementations instead of macros
1717
- Deprecate `Spi::free` and rename it to `Spi::release`
1818
- Improve `SPI` documentation
19+
- Improve `RCC` and `AFIO` register documentation
1920

2021
## [v0.6.0] - 2020-06-06
2122

src/afio.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ impl AfioExt for AFIO {
3333
}
3434
}
3535

36+
/// HAL wrapper around the AFIO registers
37+
///
38+
/// Aquired by calling [constrain](trait.AfioExt.html#constrain) on the [AFIO
39+
/// registers](../pac/struct.AFIO.html)
40+
///
41+
/// ```rust
42+
/// let p = pac::Peripherals::take().unwrap();
43+
/// let mut rcc = p.RCC.constrain();
44+
/// let mut afio = p.AFIO.constrain(&mut rcc.apb2);
3645
pub struct Parts {
3746
pub evcr: EVCR,
3847
pub mapr: MAPR,
@@ -53,6 +62,16 @@ impl EVCR {
5362
}
5463
}
5564

65+
/// AF remap and debug I/O configuration register (MAPR)
66+
///
67+
/// Aquired through the [Parts](struct.Parts.html) struct.
68+
///
69+
/// ```rust
70+
/// let dp = pac::Peripherals::take().unwrap();
71+
/// let mut rcc = dp.RCC.constrain();
72+
/// let mut afio = dp.AFIO.constrain(&mut rcc.apb2);
73+
/// function_using_mapr(&mut afio.mapr);
74+
/// ```
5675
pub struct MAPR {
5776
_0: (),
5877
jtag_enabled: bool,

src/rcc.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ pub struct Rcc {
4848
}
4949

5050
/// 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+
/// ```
5159
pub struct AHB {
5260
_0: (),
5361
}
@@ -62,6 +70,14 @@ impl AHB {
6270
}
6371

6472
/// Advanced Peripheral Bus 1 (APB1) registers
73+
///
74+
/// Aquired through the `Rcc` registers:
75+
///
76+
/// ```rust
77+
/// let dp = pac::Peripherals::take().unwrap();
78+
/// let mut rcc = dp.RCC.constrain();
79+
/// function_that_uses_apb1(&mut rcc.apb1)
80+
/// ```
6581
pub struct APB1 {
6682
_0: (),
6783
}
@@ -86,6 +102,14 @@ impl APB1 {
86102
}
87103

88104
/// Advanced Peripheral Bus 2 (APB2) registers
105+
///
106+
/// Aquired through the `Rcc` registers:
107+
///
108+
/// ```rust
109+
/// let dp = pac::Peripherals::take().unwrap();
110+
/// let mut rcc = dp.RCC.constrain();
111+
/// function_that_uses_apb2(&mut rcc.apb2);
112+
/// ```
89113
pub struct APB2 {
90114
_0: (),
91115
}
@@ -104,6 +128,15 @@ impl APB2 {
104128

105129
const HSI: u32 = 8_000_000; // Hz
106130

131+
/// Clock configuration register (CFGR)
132+
///
133+
/// Used to configure the frequencies of the clocks present in the processor.
134+
///
135+
/// After setting all frequencies, call the [freeze](#method.freeze) function to
136+
/// apply the configuration.
137+
///
138+
/// **NOTE**: Currently, it is not guaranteed that the exact frequencies selected will be
139+
/// used, only frequencies close to it.
107140
pub struct CFGR {
108141
hse: Option<u32>,
109142
hclk: Option<u32>,
@@ -116,6 +149,7 @@ pub struct CFGR {
116149
impl CFGR {
117150
/// Uses HSE (external oscillator) instead of HSI (internal RC oscillator) as the clock source.
118151
/// Will result in a hang if an external oscillator is not connected or it fails to start.
152+
/// The frequency specified must be the frequency of the external oscillator
119153
pub fn use_hse<F>(mut self, freq: F) -> Self
120154
where
121155
F: Into<Hertz>,
@@ -415,6 +449,16 @@ impl BKP {
415449
/// Frozen clock frequencies
416450
///
417451
/// The existence of this value indicates that the clock configuration can no longer be changed
452+
///
453+
/// To acquire it, use the freeze function on the `rcc.cfgr` register. If desired, you can adjust
454+
/// the frequencies using the methods on [cfgr](struct.CFGR.html) before calling freeze.
455+
///
456+
/// ```rust
457+
/// let dp = pac::Peripherals::take().unwrap();
458+
/// let mut rcc = dp.RCC.constrain();
459+
///
460+
/// let clocks = rcc.cfgr.freeze(&mut flash.acr);
461+
/// ```
418462
#[derive(Clone, Copy)]
419463
pub struct Clocks {
420464
hclk: Hertz,

0 commit comments

Comments
 (0)