aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Enderle <[email protected]>2024-11-07 13:23:39 +0100
committerChristian Enderle <[email protected]>2024-11-07 13:32:07 +0100
commit7231032f977fe4a1a486dfd963f7105b01bf684d (patch)
tree70cf3ebde26b320f5a996bf644be24dff8dfdb31
parent7a2f8399d362b659e426878ba5342fb4a99486ec (diff)
RCC: added msik for stm32u5
-rw-r--r--embassy-stm32/src/rcc/u5.rs42
1 files changed, 36 insertions, 6 deletions
diff --git a/embassy-stm32/src/rcc/u5.rs b/embassy-stm32/src/rcc/u5.rs
index 1e2bfe62d..bb3d5f320 100644
--- a/embassy-stm32/src/rcc/u5.rs
+++ b/embassy-stm32/src/rcc/u5.rs
@@ -62,7 +62,8 @@ pub struct Pll {
62#[derive(Clone, Copy)] 62#[derive(Clone, Copy)]
63pub struct Config { 63pub struct Config {
64 // base clock sources 64 // base clock sources
65 pub msi: Option<MSIRange>, 65 pub msis: Option<MSIRange>,
66 pub msik: Option<MSIRange>,
66 pub hsi: bool, 67 pub hsi: bool,
67 pub hse: Option<Hse>, 68 pub hse: Option<Hse>,
68 pub hsi48: Option<super::Hsi48Config>, 69 pub hsi48: Option<super::Hsi48Config>,
@@ -94,7 +95,8 @@ pub struct Config {
94impl Default for Config { 95impl Default for Config {
95 fn default() -> Self { 96 fn default() -> Self {
96 Self { 97 Self {
97 msi: Some(Msirange::RANGE_4MHZ), 98 msis: Some(Msirange::RANGE_4MHZ),
99 msik: Some(Msirange::RANGE_4MHZ),
98 hse: None, 100 hse: None,
99 hsi: false, 101 hsi: false,
100 hsi48: Some(Default::default()), 102 hsi48: Some(Default::default()),
@@ -118,7 +120,7 @@ pub(crate) unsafe fn init(config: Config) {
118 PWR.vosr().modify(|w| w.set_vos(config.voltage_range)); 120 PWR.vosr().modify(|w| w.set_vos(config.voltage_range));
119 while !PWR.vosr().read().vosrdy() {} 121 while !PWR.vosr().read().vosrdy() {}
120 122
121 let msi = config.msi.map(|range| { 123 let msis = config.msis.map(|range| {
122 // Check MSI output per RM0456 § 11.4.10 124 // Check MSI output per RM0456 § 11.4.10
123 match config.voltage_range { 125 match config.voltage_range {
124 VoltageScale::RANGE4 => { 126 VoltageScale::RANGE4 => {
@@ -147,6 +149,34 @@ pub(crate) unsafe fn init(config: Config) {
147 msirange_to_hertz(range) 149 msirange_to_hertz(range)
148 }); 150 });
149 151
152 let msik = config.msik.map(|range| {
153 // Check MSI output per RM0456 § 11.4.10
154 match config.voltage_range {
155 VoltageScale::RANGE4 => {
156 assert!(msirange_to_hertz(range).0 <= 24_000_000);
157 }
158 _ => {}
159 }
160
161 // RM0456 § 11.8.2: spin until MSIS is off or MSIS is ready before setting its range
162 loop {
163 let cr = RCC.cr().read();
164 if cr.msikon() == false || cr.msikrdy() == true {
165 break;
166 }
167 }
168
169 RCC.icscr1().modify(|w| {
170 w.set_msikrange(range);
171 w.set_msirgsel(Msirgsel::ICSCR1);
172 });
173 RCC.cr().write(|w| {
174 w.set_msikon(true);
175 });
176 while !RCC.cr().read().msikrdy() {}
177 msirange_to_hertz(range)
178 });
179
150 let hsi = config.hsi.then(|| { 180 let hsi = config.hsi.then(|| {
151 RCC.cr().write(|w| w.set_hsion(true)); 181 RCC.cr().write(|w| w.set_hsion(true));
152 while !RCC.cr().read().hsirdy() {} 182 while !RCC.cr().read().hsirdy() {}
@@ -181,7 +211,7 @@ pub(crate) unsafe fn init(config: Config) {
181 211
182 let hsi48 = config.hsi48.map(super::init_hsi48); 212 let hsi48 = config.hsi48.map(super::init_hsi48);
183 213
184 let pll_input = PllInput { hse, hsi, msi }; 214 let pll_input = PllInput { hse, hsi, msi: msis };
185 let pll1 = init_pll(PllInstance::Pll1, config.pll1, &pll_input, config.voltage_range); 215 let pll1 = init_pll(PllInstance::Pll1, config.pll1, &pll_input, config.voltage_range);
186 let pll2 = init_pll(PllInstance::Pll2, config.pll2, &pll_input, config.voltage_range); 216 let pll2 = init_pll(PllInstance::Pll2, config.pll2, &pll_input, config.voltage_range);
187 let pll3 = init_pll(PllInstance::Pll3, config.pll3, &pll_input, config.voltage_range); 217 let pll3 = init_pll(PllInstance::Pll3, config.pll3, &pll_input, config.voltage_range);
@@ -189,7 +219,7 @@ pub(crate) unsafe fn init(config: Config) {
189 let sys_clk = match config.sys { 219 let sys_clk = match config.sys {
190 Sysclk::HSE => hse.unwrap(), 220 Sysclk::HSE => hse.unwrap(),
191 Sysclk::HSI => hsi.unwrap(), 221 Sysclk::HSI => hsi.unwrap(),
192 Sysclk::MSIS => msi.unwrap(), 222 Sysclk::MSIS => msis.unwrap(),
193 Sysclk::PLL1_R => pll1.r.unwrap(), 223 Sysclk::PLL1_R => pll1.r.unwrap(),
194 }; 224 };
195 225
@@ -276,6 +306,7 @@ pub(crate) unsafe fn init(config: Config) {
276 pclk3: Some(pclk3), 306 pclk3: Some(pclk3),
277 pclk1_tim: Some(pclk1_tim), 307 pclk1_tim: Some(pclk1_tim),
278 pclk2_tim: Some(pclk2_tim), 308 pclk2_tim: Some(pclk2_tim),
309 msik: msik,
279 hsi48: hsi48, 310 hsi48: hsi48,
280 rtc: rtc, 311 rtc: rtc,
281 hse: hse, 312 hse: hse,
@@ -300,7 +331,6 @@ pub(crate) unsafe fn init(config: Config) {
300 hsi48_div_2: None, 331 hsi48_div_2: None,
301 lse: None, 332 lse: None,
302 lsi: None, 333 lsi: None,
303 msik: None,
304 shsi: None, 334 shsi: None,
305 shsi_div_2: None, 335 shsi_div_2: None,
306 ); 336 );