diff options
| author | Adin Ackerman <[email protected]> | 2024-01-02 16:03:23 -0800 |
|---|---|---|
| committer | Adin Ackerman <[email protected]> | 2024-01-02 16:03:23 -0800 |
| commit | 34713b4910d2d94a632ff8e3a161ab982fdab2ba (patch) | |
| tree | d88188286bb04a8915b51e4eb7682fce5de3d05c | |
| parent | a769ac188f2a9623db65acdcc27ffd26a95e3540 (diff) | |
fix g0 being left out of some clock controls
| -rw-r--r-- | embassy-stm32/build.rs | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/g0.rs | 27 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/mod.rs | 10 |
3 files changed, 30 insertions, 11 deletions
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index de03827e9..ef152acd1 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs | |||
| @@ -505,7 +505,7 @@ fn main() { | |||
| 505 | (TokenStream::new(), TokenStream::new()) | 505 | (TokenStream::new(), TokenStream::new()) |
| 506 | }; | 506 | }; |
| 507 | 507 | ||
| 508 | let mux_supported = HashSet::from(["c0", "h5", "h50", "h7", "h7ab", "h7rm0433", "g4", "l4"]) | 508 | let mux_supported = HashSet::from(["c0", "h5", "h50", "h7", "h7ab", "h7rm0433", "g0", "g4", "l4"]) |
| 509 | .contains(rcc_registers.version); | 509 | .contains(rcc_registers.version); |
| 510 | let mux_for = |mux: Option<&'static PeripheralRccRegister>| { | 510 | let mux_for = |mux: Option<&'static PeripheralRccRegister>| { |
| 511 | // restrict mux implementation to supported versions | 511 | // restrict mux implementation to supported versions |
| @@ -534,7 +534,7 @@ fn main() { | |||
| 534 | let variant_name = format_ident!("{}", v.name); | 534 | let variant_name = format_ident!("{}", v.name); |
| 535 | let clock_name = format_ident!("{}", v.name.to_ascii_lowercase()); | 535 | let clock_name = format_ident!("{}", v.name.to_ascii_lowercase()); |
| 536 | 536 | ||
| 537 | if v.name.starts_with("HCLK") || v.name.starts_with("PCLK") || v.name == "SYS" { | 537 | if v.name.starts_with("HCLK") || v.name.starts_with("PCLK") || v.name == "SYS" { |
| 538 | quote! { | 538 | quote! { |
| 539 | #enum_name::#variant_name => unsafe { crate::rcc::get_freqs().#clock_name }, | 539 | #enum_name::#variant_name => unsafe { crate::rcc::get_freqs().#clock_name }, |
| 540 | } | 540 | } |
diff --git a/embassy-stm32/src/rcc/g0.rs b/embassy-stm32/src/rcc/g0.rs index d3367b049..7f62031e5 100644 --- a/embassy-stm32/src/rcc/g0.rs +++ b/embassy-stm32/src/rcc/g0.rs | |||
| @@ -95,7 +95,7 @@ impl Default for Config { | |||
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | impl PllConfig { | 97 | impl PllConfig { |
| 98 | pub(crate) fn init(self) -> Hertz { | 98 | pub(crate) fn init(self) -> (Hertz, Option<Hertz>, Option<Hertz>) { |
| 99 | let (src, input_freq) = match self.source { | 99 | let (src, input_freq) = match self.source { |
| 100 | PllSource::HSI => (vals::Pllsrc::HSI, HSI_FREQ), | 100 | PllSource::HSI => (vals::Pllsrc::HSI, HSI_FREQ), |
| 101 | PllSource::HSE(freq, _) => (vals::Pllsrc::HSE, freq), | 101 | PllSource::HSE(freq, _) => (vals::Pllsrc::HSE, freq), |
| @@ -118,6 +118,9 @@ impl PllConfig { | |||
| 118 | // > Caution: The software must set this bitfield so as not to exceed 64 MHz on this clock. | 118 | // > Caution: The software must set this bitfield so as not to exceed 64 MHz on this clock. |
| 119 | debug_assert!(r_freq.0 <= 64_000_000); | 119 | debug_assert!(r_freq.0 <= 64_000_000); |
| 120 | 120 | ||
| 121 | let q_freq = self.q.map(|q| n_freq / q); | ||
| 122 | let p_freq = self.p.map(|p| n_freq / p); | ||
| 123 | |||
| 121 | // RM0454 § 5.2.3: | 124 | // RM0454 § 5.2.3: |
| 122 | // > To modify the PLL configuration, proceed as follows: | 125 | // > To modify the PLL configuration, proceed as follows: |
| 123 | // > 1. Disable the PLL by setting PLLON to 0 in Clock control register (RCC_CR). | 126 | // > 1. Disable the PLL by setting PLLON to 0 in Clock control register (RCC_CR). |
| @@ -172,11 +175,14 @@ impl PllConfig { | |||
| 172 | w.set_pllpen(self.p.is_some()); | 175 | w.set_pllpen(self.p.is_some()); |
| 173 | }); | 176 | }); |
| 174 | 177 | ||
| 175 | r_freq | 178 | (r_freq, q_freq, p_freq) |
| 176 | } | 179 | } |
| 177 | } | 180 | } |
| 178 | 181 | ||
| 179 | pub(crate) unsafe fn init(config: Config) { | 182 | pub(crate) unsafe fn init(config: Config) { |
| 183 | let mut pll1_q_freq = None; | ||
| 184 | let mut pll1_p_freq = None; | ||
| 185 | |||
| 180 | let (sys_clk, sw) = match config.mux { | 186 | let (sys_clk, sw) = match config.mux { |
| 181 | ClockSrc::HSI(div) => { | 187 | ClockSrc::HSI(div) => { |
| 182 | // Enable HSI | 188 | // Enable HSI |
| @@ -199,8 +205,12 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 199 | (freq, Sw::HSE) | 205 | (freq, Sw::HSE) |
| 200 | } | 206 | } |
| 201 | ClockSrc::PLL(pll) => { | 207 | ClockSrc::PLL(pll) => { |
| 202 | let freq = pll.init(); | 208 | let (r_freq, q_freq, p_freq) = pll.init(); |
| 203 | (freq, Sw::PLL1_R) | 209 | |
| 210 | pll1_q_freq = q_freq; | ||
| 211 | pll1_p_freq = p_freq; | ||
| 212 | |||
| 213 | (r_freq, Sw::PLL1_R) | ||
| 204 | } | 214 | } |
| 205 | ClockSrc::LSI => { | 215 | ClockSrc::LSI => { |
| 206 | // Enable LSI | 216 | // Enable LSI |
| @@ -286,12 +296,21 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 286 | } | 296 | } |
| 287 | 297 | ||
| 288 | let rtc = config.ls.init(); | 298 | let rtc = config.ls.init(); |
| 299 | let lse_freq = config.ls.lse.map(|lse| lse.frequency); | ||
| 300 | |||
| 301 | let hsi_freq = (sw == Sw::HSI).then_some(HSI_FREQ); | ||
| 302 | let lsi_freq = (sw == Sw::LSI).then_some(super::LSI_FREQ); | ||
| 289 | 303 | ||
| 290 | set_freqs(Clocks { | 304 | set_freqs(Clocks { |
| 291 | sys: sys_clk, | 305 | sys: sys_clk, |
| 292 | hclk1: ahb_freq, | 306 | hclk1: ahb_freq, |
| 293 | pclk1: apb_freq, | 307 | pclk1: apb_freq, |
| 294 | pclk1_tim: apb_tim_freq, | 308 | pclk1_tim: apb_tim_freq, |
| 309 | hsi: hsi_freq, | ||
| 310 | lse: lse_freq, | ||
| 311 | lsi: lsi_freq, | ||
| 312 | pll1_q: pll1_q_freq, | ||
| 313 | pll1_p: pll1_p_freq, | ||
| 295 | rtc, | 314 | rtc, |
| 296 | }); | 315 | }); |
| 297 | } | 316 | } |
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index 04a51110c..c4bee4c95 100644 --- a/embassy-stm32/src/rcc/mod.rs +++ b/embassy-stm32/src/rcc/mod.rs | |||
| @@ -121,9 +121,9 @@ pub struct Clocks { | |||
| 121 | #[cfg(rcc_l4)] | 121 | #[cfg(rcc_l4)] |
| 122 | pub pllsai2_p: Option<Hertz>, | 122 | pub pllsai2_p: Option<Hertz>, |
| 123 | 123 | ||
| 124 | #[cfg(any(stm32g4, rcc_l4))] | 124 | #[cfg(any(stm32g0, stm32g4, rcc_l4))] |
| 125 | pub pll1_p: Option<Hertz>, | 125 | pub pll1_p: Option<Hertz>, |
| 126 | #[cfg(any(stm32h5, stm32h7, stm32f2, stm32f4, stm32f7, rcc_l4, stm32g4))] | 126 | #[cfg(any(stm32h5, stm32h7, stm32f2, stm32f4, stm32f7, rcc_l4, stm32g0, stm32g4))] |
| 127 | pub pll1_q: Option<Hertz>, | 127 | pub pll1_q: Option<Hertz>, |
| 128 | #[cfg(any(stm32h5, stm32h7))] | 128 | #[cfg(any(stm32h5, stm32h7))] |
| 129 | pub pll2_p: Option<Hertz>, | 129 | pub pll2_p: Option<Hertz>, |
| @@ -160,16 +160,16 @@ pub struct Clocks { | |||
| 160 | 160 | ||
| 161 | pub rtc: Option<Hertz>, | 161 | pub rtc: Option<Hertz>, |
| 162 | 162 | ||
| 163 | #[cfg(any(stm32h5, stm32h7, rcc_l4, rcc_c0))] | 163 | #[cfg(any(stm32h5, stm32h7, rcc_l4, rcc_c0, stm32g0))] |
| 164 | pub hsi: Option<Hertz>, | 164 | pub hsi: Option<Hertz>, |
| 165 | #[cfg(stm32h5)] | 165 | #[cfg(stm32h5)] |
| 166 | pub hsi48: Option<Hertz>, | 166 | pub hsi48: Option<Hertz>, |
| 167 | #[cfg(stm32h5)] | 167 | #[cfg(any(stm32g0, stm32h5))] |
| 168 | pub lsi: Option<Hertz>, | 168 | pub lsi: Option<Hertz>, |
| 169 | #[cfg(any(stm32h5, stm32h7))] | 169 | #[cfg(any(stm32h5, stm32h7))] |
| 170 | pub csi: Option<Hertz>, | 170 | pub csi: Option<Hertz>, |
| 171 | 171 | ||
| 172 | #[cfg(any(stm32h5, stm32h7, rcc_l4, rcc_c0))] | 172 | #[cfg(any(stm32h5, stm32h7, rcc_l4, rcc_c0, stm32g0))] |
| 173 | pub lse: Option<Hertz>, | 173 | pub lse: Option<Hertz>, |
| 174 | #[cfg(any(stm32h5, stm32h7, stm32g4))] | 174 | #[cfg(any(stm32h5, stm32h7, stm32g4))] |
| 175 | pub hse: Option<Hertz>, | 175 | pub hse: Option<Hertz>, |
