Skip to content

Commit 05a70a5

Browse files
author
Mathias Gottschlag
committed
rcc: Add some additional documentation and a usage example.
1 parent 2ebb8ac commit 05a70a5

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/rcc/mod.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,44 @@
1+
//! Clock configuration.
2+
//!
3+
//! This module provides functionality to configure the RCC to generate the requested clocks.
4+
//!
5+
//! # Example
6+
//!
7+
//! ```
8+
//! let dp = stm32::Peripherals::take().unwrap();
9+
//! let clocks = rcc
10+
//! .cfgr
11+
//! .use_hse(8.mhz())
12+
//! .sysclk(168.mhz())
13+
//! .pclk1(24.mhz())
14+
//! .i2s_clk(86.mhz())
15+
//! .require_pll48clk()
16+
//! .freeze();
17+
//! // Test that the I2S clock is suitable for 48000KHz audio.
18+
//! assert!(clocks.i2s_clk().unwrap() == 48.mhz().into());
19+
//! ```
20+
//!
21+
//! # Limitations
22+
//!
23+
//! Unlike the clock configuration tool provided by ST, the code does not extensively search all
24+
//! possible configurations. Instead, it often relies on an iterative approach to reduce
25+
//! compitational complexity. On most MCUs the code will first generate a configuration for the 48
26+
//! MHz clock and the system clock without taking other requested clocks into account, even if the
27+
//! accuracy of these clocks is affected. **If you specific accuracy requirements, you should
28+
//! always check the resulting frequencies!**
29+
//!
30+
//! Whereas the hardware often supports flexible clock source selection and many clocks can be
31+
//! sourced from multiple PLLs, the code implements a fixed mapping between PLLs and clocks. The 48
32+
//! MHz clock is always generated by the main PLL, the I2S clocks are always generated by the I2S
33+
//! PLL (unless a matching external clock input is provided), and similarly the SAI clocks are
34+
//! always generated by the SAI PLL. It is therefore not possible to, for example, specify two
35+
//! different I2S frequencies unless you also provide a matching I2S_CKIN signal for one of them.
36+
//!
37+
//! Some MCUs have limited clock generation hardware and do not provide either I2S or SAI PLLs even
38+
//! though I2S or SAI are available. On the STM32F410, the I2S clock is generated by the main PLL,
39+
//! and on the STM32F413/423 SAI clocks are generated by the I2S PLL. On these MCUs, the actual
40+
//! frequencies may substantially deviate from the requested frequencies.
41+
142
use crate::stm32::rcc::cfgr::{HPRE_A, SW_A};
243
use crate::stm32::RCC;
344

0 commit comments

Comments
 (0)