Skip to content

Commit 71691c6

Browse files
author
Henrik Snöman
committed
WIP: Add h523 support
1 parent 5e7a293 commit 71691c6

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ sdmmc2 = [] # Only STM32H563/73 have SDMMC2
4343

4444
rt = ["stm32h5/rt"]
4545
stm32h503 = ["stm32h5/stm32h503", "device-selected", "rm0492"]
46+
stm32h523 = ["stm32h5/stm32h523", "device-selected", "rm0481", "h523_h533"]
4647
stm32h562 = ["stm32h5/stm32h562", "device-selected", "rm0481", "h56x_h573"]
4748
stm32h563 = ["stm32h5/stm32h563", "device-selected", "rm0481", "h56x_h573", "sdmmc2", "ethernet"]
4849
stm32h573 = ["stm32h5/stm32h573", "device-selected", "rm0481", "h56x_h573", "otfdec", "sdmmc2", "ethernet"]
@@ -55,7 +56,8 @@ log-semihost = ["log"]
5556

5657
[dependencies]
5758
cortex-m = { version = "^0.7.7", features = ["critical-section-single-core"] }
58-
stm32h5 = { package = "stm32h5-staging", version = "0.17.0" }
59+
stm32h5 = { git = "https://github.com/stm32-rs/stm32-rs-nightlies" }
60+
#stm32h5 = { package = "stm32h5-staging", version = "0.17.0" }
5961
fugit = "0.3.7"
6062
embedded-hal = "1.0.0"
6163
defmt = { version = "0.3.8", optional = true }

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
compile_error!(
77
"This crate requires one of the following device features enabled:
88
stm32h503
9+
stm32h523
910
stm32h562
1011
stm32h563
1112
stm32h573
@@ -18,6 +19,9 @@ compile_error!("Cannot not select both rm0492 and rm0481");
1819
#[cfg(feature = "stm32h503")]
1920
pub use stm32h5::stm32h503 as stm32;
2021

22+
#[cfg(feature = "stm32h523")]
23+
pub use stm32h5::stm32h523 as stm32;
24+
2125
#[cfg(feature = "stm32h562")]
2226
pub use stm32h5::stm32h562 as stm32;
2327

src/rcc/pll.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,17 @@ macro_rules! pll_divider_setup {
235235
}}
236236
};
237237
}
238-
238+
fn foo(rcc: RCC) {
239+
//rcc.pll1cfgr().modify(|_, w| w.divm1());
240+
//rcc.pll1cfgr().modify(|_, w| w.pll1m());
241+
}
239242
macro_rules! pll_setup {
240-
($pllX:ident, $odd_allowed:expr) => {
243+
($X:literal, $odd_allowed:expr) => {
241244
paste::item! {
242245
/// PLL Setup
243246
/// Returns (Option(pllX_p_ck), Option(pllX_q_ck), Option(pllX_r_ck))
244247
245-
pub(super) fn [< $pllX _setup >] (
248+
pub(super) fn [< pll $X _setup >] (
246249
&self,
247250
rcc: &RCC,
248251
pll: &PllConfig,
@@ -256,20 +259,20 @@ macro_rules! pll_setup {
256259
return (None, None, None);
257260
}
258261

259-
let pll_setup = vco_setup!(pllsrc, pll, rcc, $pllX, $odd_allowed);
262+
let pll_setup = vco_setup!(pllsrc, pll, rcc, [<pll $X>], $odd_allowed);
260263

261264
// Feedback divider. Integer only
262265
let pll_x_n = pll_setup.vco_out_target / pll_setup.ref_ck;
263266

264267
// Write dividers
265-
rcc.[< $pllX cfgr >]().modify(|_, w| unsafe {
266-
w.[< $pllX m >]()
268+
rcc.[< pll $X cfgr >]().modify(|_, w| unsafe {
269+
w.[< divm $X >]()
267270
.bits(pll_setup.pll_m as u8) }); // ref prescaler
268271

269272
// unsafe as not all values are permitted: see RM0492
270273
assert!(pll_x_n >= PLL_N_MIN);
271274
assert!(pll_x_n <= PLL_N_MAX);
272-
rcc.[<$pllX divr>]().modify(|_, w| unsafe { w.[<$pllX n>]().bits((pll_x_n - 1) as u16) });
275+
rcc.[<pll $X divr>]().modify(|_, w| unsafe { w.[< pll $X n>]().bits((pll_x_n - 1) as u16) });
273276

274277
let pll_x = pll_setup.pll_p.as_ref().or(pll_setup.pll_q.as_ref().or(pll_setup.pll_r.as_ref())).unwrap();
275278

@@ -279,10 +282,10 @@ macro_rules! pll_setup {
279282
// Calculate FRACN
280283
let pll_x_fracn = calc_fracn(pll_setup.ref_ck as f32, pll_x_n as f32, pll_x.div as f32, pll_x.ck as f32);
281284
//RCC_PLL1FRACR
282-
rcc.[<$pllX fracr>]().modify(|_, w| w.[<$pllX fracn>]().set(pll_x_fracn));
285+
rcc.[<pll $X fracr>]().modify(|_, w| w.[<pll $X fracn>]().set(pll_x_fracn));
283286
// Latch FRACN by resetting and setting it
284-
rcc.[<$pllX cfgr>]().modify(|_, w| w.[< $pllX fracen>]().reset() );
285-
rcc.[<$pllX cfgr>]().modify(|_, w| w.[< $pllX fracen>]().set_() );
287+
rcc.[<pll $X cfgr>]().modify(|_, w| w.[< pll $X fracen>]().reset() );
288+
rcc.[<pll $X cfgr>]().modify(|_, w| w.[< pll $X fracen>]().set_() );
286289

287290
calc_vco_ck(pll_setup.ref_ck, pll_x_n, pll_x_fracn)
288291
},
@@ -292,7 +295,7 @@ macro_rules! pll_setup {
292295
},
293296
};
294297

295-
pll_divider_setup! {($pllX, rcc, pll, vco_ck),
298+
pll_divider_setup! {([<pll $X>], rcc, pll, vco_ck),
296299
p: &pll_setup.pll_p,
297300
q: &pll_setup.pll_q,
298301
r: &pll_setup.pll_r }
@@ -326,8 +329,8 @@ fn calc_vco_ck(ref_ck: u32, pll_n: u32, pll_fracn: u16) -> u32 {
326329
}
327330

328331
impl Rcc {
329-
pll_setup! {pll1, false}
330-
pll_setup! {pll2, true}
332+
pll_setup! {1, false}
333+
pll_setup! {2, true}
331334
}
332335

333336
#[cfg(test)]

0 commit comments

Comments
 (0)