Skip to content

crate::rcc::Clocks struct can be created trivially, violating its invariants #437

Closed
@horazont

Description

@horazont

The documentation of crate::rcc::Clocks claims:

The existence of this value indicates that the clock configuration can no longer be changed

But the following example code can be used to obtain a value of crate::rcc::Clocks without actually tying the clocks down:

#![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{}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions