Skip to content

Commit 66286f4

Browse files
committed
rcc_config_usb test
1 parent 6675fe2 commit 66286f4

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@ jobs:
3535
with:
3636
command: check
3737
args: --features=${{ matrix.mcu }},rt --examples
38+
- uses: actions-rs/cargo@v1
39+
with:
40+
command: test
41+
args: --features=${{ matrix.mcu }} --target x86_64-unknown-linux-gnu --lib

src/rcc.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ const HSI: u32 = 8_000_000; // Hz
105105
///
106106
/// **NOTE**: Currently, it is not guaranteed that the exact frequencies selected will be
107107
/// used, only frequencies close to it.
108+
#[derive(Debug, Default, PartialEq)]
108109
pub struct CFGR {
109110
hse: Option<u32>,
110111
hclk: Option<u32>,
@@ -335,7 +336,7 @@ impl BKP {
335336
///
336337
/// let clocks = rcc.cfgr.freeze(&mut flash.acr);
337338
/// ```
338-
#[derive(Clone, Copy)]
339+
#[derive(Clone, Copy, Debug, PartialEq)]
339340
pub struct Clocks {
340341
hclk: Hertz,
341342
pclk1: Hertz,
@@ -702,3 +703,39 @@ impl Config {
702703
}
703704
}
704705
}
706+
707+
#[test]
708+
fn rcc_config_usb() {
709+
use crate::time::U32Ext;
710+
let cfgr = CFGR::default()
711+
.use_hse(8.mhz())
712+
.sysclk(48.mhz())
713+
.pclk1(24.mhz());
714+
715+
let config = Config::from_cfgr(cfgr);
716+
let config_expected = Config {
717+
hse: Some(8_000_000),
718+
pllmul: Some(4),
719+
hpre: HPre::DIV1,
720+
ppre1: PPre::DIV2,
721+
ppre2: PPre::DIV1,
722+
#[cfg(any(feature = "stm32f103", feature = "connectivity"))]
723+
usbpre: UsbPre::DIV1,
724+
adcpre: AdcPre::DIV8,
725+
};
726+
assert_eq!(config, config_expected);
727+
728+
let clocks = config.get_clocks();
729+
let clocks_expected = Clocks {
730+
hclk: 48.mhz().into(),
731+
pclk1: 24.mhz().into(),
732+
pclk2: 48.mhz().into(),
733+
ppre1: 2,
734+
ppre2: 1,
735+
sysclk: 48.mhz().into(),
736+
adcclk: 6.mhz().into(),
737+
#[cfg(any(feature = "stm32f103", feature = "connectivity"))]
738+
usbclk_valid: true,
739+
};
740+
assert_eq!(clocks, clocks_expected);
741+
}

0 commit comments

Comments
 (0)