aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/rcc/mco.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-stm32/src/rcc/mco.rs')
-rw-r--r--embassy-stm32/src/rcc/mco.rs37
1 files changed, 29 insertions, 8 deletions
diff --git a/embassy-stm32/src/rcc/mco.rs b/embassy-stm32/src/rcc/mco.rs
index 59ccc8cb5..0624fdf26 100644
--- a/embassy-stm32/src/rcc/mco.rs
+++ b/embassy-stm32/src/rcc/mco.rs
@@ -3,6 +3,7 @@ use core::marker::PhantomData;
3use embassy_hal_internal::PeripheralType; 3use embassy_hal_internal::PeripheralType;
4 4
5use crate::gpio::{AfType, OutputType, Speed}; 5use crate::gpio::{AfType, OutputType, Speed};
6use crate::pac::RCC;
6#[cfg(not(any(stm32f1, rcc_f0v1, rcc_f3v1, rcc_f37)))] 7#[cfg(not(any(stm32f1, rcc_f0v1, rcc_f3v1, rcc_f37)))]
7pub use crate::pac::rcc::vals::Mcopre as McoPrescaler; 8pub use crate::pac::rcc::vals::Mcopre as McoPrescaler;
8#[cfg(not(any( 9#[cfg(not(any(
@@ -15,7 +16,8 @@ pub use crate::pac::rcc::vals::Mcopre as McoPrescaler;
15 rcc_h7ab, 16 rcc_h7ab,
16 rcc_h7rm0433, 17 rcc_h7rm0433,
17 rcc_h7, 18 rcc_h7,
18 rcc_h7rs 19 rcc_h7rs,
20 rcc_n6
19)))] 21)))]
20pub use crate::pac::rcc::vals::Mcosel as McoSource; 22pub use crate::pac::rcc::vals::Mcosel as McoSource;
21#[cfg(any( 23#[cfg(any(
@@ -28,11 +30,11 @@ pub use crate::pac::rcc::vals::Mcosel as McoSource;
28 rcc_h7ab, 30 rcc_h7ab,
29 rcc_h7rm0433, 31 rcc_h7rm0433,
30 rcc_h7, 32 rcc_h7,
31 rcc_h7rs 33 rcc_h7rs,
34 rcc_n6
32))] 35))]
33pub use crate::pac::rcc::vals::{Mco1sel as Mco1Source, Mco2sel as Mco2Source}; 36pub use crate::pac::rcc::vals::{Mco1sel as Mco1Source, Mco2sel as Mco2Source};
34use crate::pac::RCC; 37use crate::{Peri, peripherals};
35use crate::{peripherals, Peri};
36 38
37#[cfg(any(stm32f1, rcc_f0v1, rcc_f3v1, rcc_f37))] 39#[cfg(any(stm32f1, rcc_f0v1, rcc_f3v1, rcc_f37))]
38#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] 40#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
@@ -59,10 +61,12 @@ macro_rules! impl_peri {
59 type Source = $source; 61 type Source = $source;
60 62
61 unsafe fn _apply_clock_settings(source: Self::Source, _prescaler: McoPrescaler) { 63 unsafe fn _apply_clock_settings(source: Self::Source, _prescaler: McoPrescaler) {
62 #[cfg(not(any(stm32u5, stm32wba)))] 64 #[cfg(not(any(stm32u5, stm32wba, stm32n6)))]
63 let r = RCC.cfgr(); 65 let r = RCC.cfgr();
64 #[cfg(any(stm32u5, stm32wba))] 66 #[cfg(any(stm32u5, stm32wba))]
65 let r = RCC.cfgr1(); 67 let r = RCC.cfgr1();
68 #[cfg(any(stm32n6))]
69 let r = RCC.ccipr5();
66 70
67 r.modify(|w| { 71 r.modify(|w| {
68 w.$set_source(source); 72 w.$set_source(source);
@@ -91,12 +95,29 @@ pub struct Mco<'d, T: McoInstance> {
91 95
92impl<'d, T: McoInstance> Mco<'d, T> { 96impl<'d, T: McoInstance> Mco<'d, T> {
93 /// Create a new MCO instance. 97 /// Create a new MCO instance.
94 pub fn new(_peri: Peri<'d, T>, pin: Peri<'d, impl McoPin<T>>, source: T::Source, prescaler: McoPrescaler) -> Self { 98 pub fn new(_peri: Peri<'d, T>, pin: Peri<'d, impl McoPin<T>>, source: T::Source, config: McoConfig) -> Self {
95 critical_section::with(|_| unsafe { 99 critical_section::with(|_| unsafe {
96 T::_apply_clock_settings(source, prescaler); 100 T::_apply_clock_settings(source, config.prescaler);
97 set_as_af!(pin, AfType::output(OutputType::PushPull, Speed::VeryHigh)); 101 set_as_af!(pin, AfType::output(OutputType::PushPull, config.speed));
98 }); 102 });
99 103
100 Self { phantom: PhantomData } 104 Self { phantom: PhantomData }
101 } 105 }
102} 106}
107
108#[non_exhaustive]
109pub struct McoConfig {
110 /// Master Clock Out prescaler
111 pub prescaler: McoPrescaler,
112 /// IO Drive Strength
113 pub speed: Speed,
114}
115
116impl Default for McoConfig {
117 fn default() -> Self {
118 Self {
119 prescaler: McoPrescaler::DIV1,
120 speed: Speed::VeryHigh,
121 }
122 }
123}