stm32ral/stm32f4/instances/
syscfg_f429_f469.rs

1#![allow(non_snake_case, non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3//! System configuration controller
4//!
5//! Used by: stm32f429, stm32f469
6
7#[cfg(not(feature = "nosync"))]
8pub use crate::stm32f4::peripherals::syscfg_v4::Instance;
9pub use crate::stm32f4::peripherals::syscfg_v4::{RegisterBlock, ResetValues};
10pub use crate::stm32f4::peripherals::syscfg_v4::{
11    CMPCR, EXTICR1, EXTICR2, EXTICR3, EXTICR4, MEMRM, PMC,
12};
13
14/// Access functions for the SYSCFG peripheral instance
15pub mod SYSCFG {
16    use super::ResetValues;
17
18    #[cfg(not(feature = "nosync"))]
19    use super::Instance;
20
21    #[cfg(not(feature = "nosync"))]
22    const INSTANCE: Instance = Instance {
23        addr: 0x40013800,
24        _marker: ::core::marker::PhantomData,
25    };
26
27    /// Reset values for each field in SYSCFG
28    pub const reset: ResetValues = ResetValues {
29        MEMRM: 0x00000000,
30        PMC: 0x00000000,
31        EXTICR1: 0x00000000,
32        EXTICR2: 0x00000000,
33        EXTICR3: 0x00000000,
34        EXTICR4: 0x00000000,
35        CMPCR: 0x00000000,
36    };
37
38    #[cfg(not(feature = "nosync"))]
39    #[allow(renamed_and_removed_lints)]
40    #[allow(private_no_mangle_statics)]
41    #[no_mangle]
42    static mut SYSCFG_TAKEN: bool = false;
43
44    /// Safe access to SYSCFG
45    ///
46    /// This function returns `Some(Instance)` if this instance is not
47    /// currently taken, and `None` if it is. This ensures that if you
48    /// do get `Some(Instance)`, you are ensured unique access to
49    /// the peripheral and there cannot be data races (unless other
50    /// code uses `unsafe`, of course). You can then pass the
51    /// `Instance` around to other functions as required. When you're
52    /// done with it, you can call `release(instance)` to return it.
53    ///
54    /// `Instance` itself dereferences to a `RegisterBlock`, which
55    /// provides access to the peripheral's registers.
56    #[cfg(not(feature = "nosync"))]
57    #[inline]
58    pub fn take() -> Option<Instance> {
59        external_cortex_m::interrupt::free(|_| unsafe {
60            if SYSCFG_TAKEN {
61                None
62            } else {
63                SYSCFG_TAKEN = true;
64                Some(INSTANCE)
65            }
66        })
67    }
68
69    /// Release exclusive access to SYSCFG
70    ///
71    /// This function allows you to return an `Instance` so that it
72    /// is available to `take()` again. This function will panic if
73    /// you return a different `Instance` or if this instance is not
74    /// already taken.
75    #[cfg(not(feature = "nosync"))]
76    #[inline]
77    pub fn release(inst: Instance) {
78        external_cortex_m::interrupt::free(|_| unsafe {
79            if SYSCFG_TAKEN && inst.addr == INSTANCE.addr {
80                SYSCFG_TAKEN = false;
81            } else {
82                panic!("Released a peripheral which was not taken");
83            }
84        });
85    }
86
87    /// Unsafely steal SYSCFG
88    ///
89    /// This function is similar to take() but forcibly takes the
90    /// Instance, marking it as taken irregardless of its previous
91    /// state.
92    #[cfg(not(feature = "nosync"))]
93    #[inline]
94    pub unsafe fn steal() -> Instance {
95        SYSCFG_TAKEN = true;
96        INSTANCE
97    }
98}
99
100/// Raw pointer to SYSCFG
101///
102/// Dereferencing this is unsafe because you are not ensured unique
103/// access to the peripheral, so you may encounter data races with
104/// other users of this peripheral. It is up to you to ensure you
105/// will not cause data races.
106///
107/// This constant is provided for ease of use in unsafe code: you can
108/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
109pub const SYSCFG: *const RegisterBlock = 0x40013800 as *const _;