Skip to content

Commit f063d5b

Browse files
bors[bot]horazont
andauthored
Merge #438
438: Un-publish crate::rcc::Config::get_clocks r=burrbull a=horazont The existence of a crate::rcc::Clocks value is supposed to assert that the MCU clocks have been configured and that they cannot be changed anymore. That works by consuming the only instance of CFGR in the corresponding function and then returning a Clocks value. However, having crate::rcc::config::Config::get_clocks public implies that external code can, at any time, generate a Clocks value: by simply constructing a Config instance (all fields are public) and calling the function. ```rust #![no_std] #![no_main] use panic_halt as _; use stm32f1xx_hal as hal; use cortex_m_rt::entry; #[entry] fn main() -> ! { let clocks: hal::rcc::Clocks = hal::rcc::Config{ hse: Some(8000000), pllmul: Some(8), hpre: hal::rcc::HPre::DIV1, ppre1: hal::rcc::PPre::DIV2, ppre2: hal::rcc::PPre::DIV1, adcpre: hal::rcc::AdcPre::DIV8, usbpre: hal::rcc::UsbPre::DIV1, }.get_clocks(); loop{} } ``` This is a breaking change, obviously, but there are no non-breaking alternatives. Fixes #437. Co-authored-by: Jonas Schäfer <j.wielicki@sotecware.net>
2 parents 6c6c8c5 + 4909f29 commit f063d5b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/rcc.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,10 @@ impl Config {
661661
adcpre: apre_bits,
662662
}
663663
}
664-
pub fn get_clocks(&self) -> Clocks {
664+
665+
// NOTE: to maintain the invariant that the existence of a Clocks
666+
// value implies frozen clocks, this function must not be pub.
667+
fn get_clocks(&self) -> Clocks {
665668
let sysclk = if let Some(pllmul_bits) = self.pllmul {
666669
let pllsrcclk = if let Some(hse) = self.hse {
667670
hse

0 commit comments

Comments
 (0)