diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-01-03 00:29:58 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-01-03 00:29:58 +0000 |
| commit | 1f5fe9624160a602951b7f693f8199686e9cd9de (patch) | |
| tree | dee3898d59414b6cfd28d8103a3fe256dbdc0763 | |
| parent | a769ac188f2a9623db65acdcc27ffd26a95e3540 (diff) | |
| parent | d372cba266c7a110f314e74dfee589987b892383 (diff) | |
Merge pull request #2388 from AdinAck/g0-clocks
Add Missing Clocks on G0 to `Clocks`
| -rw-r--r-- | embassy-stm32/build.rs | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/g0.rs | 32 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/mod.rs | 16 |
3 files changed, 39 insertions, 13 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..aedc95bf3 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,26 @@ 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 hsi_div_8_freq = hsi_freq.map(|f| f / 8u32); | ||
| 303 | let lsi_freq = (sw == Sw::LSI).then_some(super::LSI_FREQ); | ||
| 304 | let hse_freq = (sw == Sw::HSE).then_some(sys_clk); | ||
| 289 | 305 | ||
| 290 | set_freqs(Clocks { | 306 | set_freqs(Clocks { |
| 291 | sys: sys_clk, | 307 | sys: sys_clk, |
| 292 | hclk1: ahb_freq, | 308 | hclk1: ahb_freq, |
| 293 | pclk1: apb_freq, | 309 | pclk1: apb_freq, |
| 294 | pclk1_tim: apb_tim_freq, | 310 | pclk1_tim: apb_tim_freq, |
| 311 | hsi: hsi_freq, | ||
| 312 | hsi48: None, | ||
| 313 | hsi_div_8: hsi_div_8_freq, | ||
| 314 | hse: hse_freq, | ||
| 315 | lse: lse_freq, | ||
| 316 | lsi: lsi_freq, | ||
| 317 | pll1_q: pll1_q_freq, | ||
| 318 | pll1_p: pll1_p_freq, | ||
| 295 | rtc, | 319 | rtc, |
| 296 | }); | 320 | }); |
| 297 | } | 321 | } |
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index 04a51110c..240ffc6d2 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,18 +160,20 @@ 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(any(stm32h5, stm32g0))] |
| 166 | pub hsi48: Option<Hertz>, | 166 | pub hsi48: Option<Hertz>, |
| 167 | #[cfg(stm32h5)] | 167 | #[cfg(stm32g0)] |
| 168 | pub hsi_div_8: Option<Hertz>, | ||
| 169 | #[cfg(any(stm32g0, stm32h5))] | ||
| 168 | pub lsi: Option<Hertz>, | 170 | pub lsi: Option<Hertz>, |
| 169 | #[cfg(any(stm32h5, stm32h7))] | 171 | #[cfg(any(stm32h5, stm32h7))] |
| 170 | pub csi: Option<Hertz>, | 172 | pub csi: Option<Hertz>, |
| 171 | 173 | ||
| 172 | #[cfg(any(stm32h5, stm32h7, rcc_l4, rcc_c0))] | 174 | #[cfg(any(stm32h5, stm32h7, rcc_l4, rcc_c0, stm32g0))] |
| 173 | pub lse: Option<Hertz>, | 175 | pub lse: Option<Hertz>, |
| 174 | #[cfg(any(stm32h5, stm32h7, stm32g4))] | 176 | #[cfg(any(stm32h5, stm32h7, stm32g0, stm32g4))] |
| 175 | pub hse: Option<Hertz>, | 177 | pub hse: Option<Hertz>, |
| 176 | 178 | ||
| 177 | #[cfg(stm32h5)] | 179 | #[cfg(stm32h5)] |
