From 13fc222ef45e16980aca221044ae41d106065ce1 Mon Sep 17 00:00:00 2001 From: Rogan Morrow Date: Fri, 29 Aug 2025 16:08:50 +1000 Subject: set XSPI clock source to HSI and reset after clock init; dont reset SYSCFG --- embassy-stm32/CHANGELOG.md | 1 + embassy-stm32/src/lib.rs | 2 +- embassy-stm32/src/rcc/h.rs | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/embassy-stm32/CHANGELOG.md b/embassy-stm32/CHANGELOG.md index dd82613d9..bf451da79 100644 --- a/embassy-stm32/CHANGELOG.md +++ b/embassy-stm32/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - chore: Updated stm32-metapac and stm32-data dependencies - feat: stm32/adc/v3: allow DMA reads to loop through enable channels - fix: Fix XSPI not disabling alternate bytes when they were previously enabled +- fix: Fix stm32h7rs init when using external flash via XSPI ## 0.3.0 - 2025-08-12 diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index e4a8ff0ab..3be98c462 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs @@ -526,7 +526,7 @@ fn init_hw(config: Config) -> Peripherals { } }); - #[cfg(not(any(stm32f1, stm32wb, stm32wl)))] + #[cfg(not(any(stm32f1, stm32wb, stm32wl, stm32h7rs)))] rcc::enable_and_reset_with_cs::(cs); #[cfg(not(any(stm32h5, stm32h7, stm32h7rs, stm32wb, stm32wl)))] rcc::enable_and_reset_with_cs::(cs); diff --git a/embassy-stm32/src/rcc/h.rs b/embassy-stm32/src/rcc/h.rs index 837210b6a..331db1968 100644 --- a/embassy-stm32/src/rcc/h.rs +++ b/embassy-stm32/src/rcc/h.rs @@ -1,7 +1,7 @@ use core::ops::RangeInclusive; #[cfg(stm32h7rs)] -use stm32_metapac::rcc::vals::Plldivst; +use stm32_metapac::rcc::vals::{Plldivst, Xspisel}; use crate::pac; pub use crate::pac::rcc::vals::{ @@ -430,6 +430,16 @@ pub(crate) unsafe fn init(config: Config) { } while !RCC.cr().read().hsirdy() {} + #[cfg(stm32h7rs)] + let (xspi1sel, xspi2sel) = { + // Save XSPI clock source settings and switch the clock source so it will use HSI + let xspi1sel = RCC.ahbperckselr().read().xspi1sel(); + let xspi2sel = RCC.ahbperckselr().read().xspi2sel(); + RCC.ahbperckselr().modify(|w| w.set_xspi1sel(Xspisel::HCLK5)); + RCC.ahbperckselr().modify(|w| w.set_xspi2sel(Xspisel::HCLK5)); + (xspi1sel, xspi2sel) + }; + // Use the HSI clock as system clock during the actual clock setup RCC.cfgr().modify(|w| w.set_sw(Sysclk::HSI)); while RCC.cfgr().read().sws() != Sysclk::HSI {} @@ -678,6 +688,13 @@ pub(crate) unsafe fn init(config: Config) { config.mux.init(); + #[cfg(stm32h7rs)] + { + // Set the XSPI clock source back to what it was originally + RCC.ahbperckselr().modify(|w| w.set_xspi1sel(xspi1sel)); + RCC.ahbperckselr().modify(|w| w.set_xspi2sel(xspi2sel)); + } + set_clocks!( sys: Some(sys), hclk1: Some(hclk), -- cgit