Merge pull request #1617 from xoviat/const-rcc

stm32/rcc: allow const-propagation
This commit is contained in:
Dario Nieuwenhuis 2023-07-04 22:31:55 +00:00 committed by GitHub
commit eb57bb298f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 5 deletions

View File

@ -348,9 +348,7 @@ fn main() {
g.extend(quote! { g.extend(quote! {
impl crate::rcc::sealed::RccPeripheral for peripherals::#pname { impl crate::rcc::sealed::RccPeripheral for peripherals::#pname {
fn frequency() -> crate::time::Hertz { fn frequency() -> crate::time::Hertz {
critical_section::with(|_| unsafe { unsafe { crate::rcc::get_freqs().#clk }
crate::rcc::get_freqs().#clk
})
} }
fn enable() { fn enable() {
critical_section::with(|_| { critical_section::with(|_| {

View File

@ -83,12 +83,12 @@ static mut CLOCK_FREQS: MaybeUninit<Clocks> = MaybeUninit::uninit();
/// Safety: Sets a mutable global. /// Safety: Sets a mutable global.
pub(crate) unsafe fn set_freqs(freqs: Clocks) { pub(crate) unsafe fn set_freqs(freqs: Clocks) {
debug!("rcc: {:?}", freqs); debug!("rcc: {:?}", freqs);
CLOCK_FREQS.as_mut_ptr().write(freqs); CLOCK_FREQS = MaybeUninit::new(freqs);
} }
/// Safety: Reads a mutable global. /// Safety: Reads a mutable global.
pub(crate) unsafe fn get_freqs() -> &'static Clocks { pub(crate) unsafe fn get_freqs() -> &'static Clocks {
&*CLOCK_FREQS.as_ptr() CLOCK_FREQS.assume_init_ref()
} }
#[cfg(feature = "unstable-pac")] #[cfg(feature = "unstable-pac")]