stm32ral/stm32f1/instances/
usart.rs

1#![allow(non_snake_case, non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3//! Universal synchronous asynchronous receiver transmitter
4//!
5//! Used by: stm32f100, stm32f101, stm32f102, stm32f103, stm32f107
6
7#[cfg(not(feature = "nosync"))]
8pub use crate::stm32f1::peripherals::usart::Instance;
9pub use crate::stm32f1::peripherals::usart::{RegisterBlock, ResetValues};
10pub use crate::stm32f1::peripherals::usart::{BRR, CR1, CR2, CR3, DR, GTPR, SR};
11
12/// Access functions for the USART1 peripheral instance
13pub mod USART1 {
14    use super::ResetValues;
15
16    #[cfg(not(feature = "nosync"))]
17    use super::Instance;
18
19    #[cfg(not(feature = "nosync"))]
20    const INSTANCE: Instance = Instance {
21        addr: 0x40013800,
22        _marker: ::core::marker::PhantomData,
23    };
24
25    /// Reset values for each field in USART1
26    pub const reset: ResetValues = ResetValues {
27        SR: 0x000000C0,
28        DR: 0x00000000,
29        BRR: 0x00000000,
30        CR1: 0x00000000,
31        CR2: 0x00000000,
32        CR3: 0x00000000,
33        GTPR: 0x00000000,
34    };
35
36    #[cfg(not(feature = "nosync"))]
37    #[allow(renamed_and_removed_lints)]
38    #[allow(private_no_mangle_statics)]
39    #[no_mangle]
40    static mut USART1_TAKEN: bool = false;
41
42    /// Safe access to USART1
43    ///
44    /// This function returns `Some(Instance)` if this instance is not
45    /// currently taken, and `None` if it is. This ensures that if you
46    /// do get `Some(Instance)`, you are ensured unique access to
47    /// the peripheral and there cannot be data races (unless other
48    /// code uses `unsafe`, of course). You can then pass the
49    /// `Instance` around to other functions as required. When you're
50    /// done with it, you can call `release(instance)` to return it.
51    ///
52    /// `Instance` itself dereferences to a `RegisterBlock`, which
53    /// provides access to the peripheral's registers.
54    #[cfg(not(feature = "nosync"))]
55    #[inline]
56    pub fn take() -> Option<Instance> {
57        external_cortex_m::interrupt::free(|_| unsafe {
58            if USART1_TAKEN {
59                None
60            } else {
61                USART1_TAKEN = true;
62                Some(INSTANCE)
63            }
64        })
65    }
66
67    /// Release exclusive access to USART1
68    ///
69    /// This function allows you to return an `Instance` so that it
70    /// is available to `take()` again. This function will panic if
71    /// you return a different `Instance` or if this instance is not
72    /// already taken.
73    #[cfg(not(feature = "nosync"))]
74    #[inline]
75    pub fn release(inst: Instance) {
76        external_cortex_m::interrupt::free(|_| unsafe {
77            if USART1_TAKEN && inst.addr == INSTANCE.addr {
78                USART1_TAKEN = false;
79            } else {
80                panic!("Released a peripheral which was not taken");
81            }
82        });
83    }
84
85    /// Unsafely steal USART1
86    ///
87    /// This function is similar to take() but forcibly takes the
88    /// Instance, marking it as taken irregardless of its previous
89    /// state.
90    #[cfg(not(feature = "nosync"))]
91    #[inline]
92    pub unsafe fn steal() -> Instance {
93        USART1_TAKEN = true;
94        INSTANCE
95    }
96}
97
98/// Raw pointer to USART1
99///
100/// Dereferencing this is unsafe because you are not ensured unique
101/// access to the peripheral, so you may encounter data races with
102/// other users of this peripheral. It is up to you to ensure you
103/// will not cause data races.
104///
105/// This constant is provided for ease of use in unsafe code: you can
106/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
107pub const USART1: *const RegisterBlock = 0x40013800 as *const _;
108
109/// Access functions for the USART2 peripheral instance
110pub mod USART2 {
111    use super::ResetValues;
112
113    #[cfg(not(feature = "nosync"))]
114    use super::Instance;
115
116    #[cfg(not(feature = "nosync"))]
117    const INSTANCE: Instance = Instance {
118        addr: 0x40004400,
119        _marker: ::core::marker::PhantomData,
120    };
121
122    /// Reset values for each field in USART2
123    pub const reset: ResetValues = ResetValues {
124        SR: 0x000000C0,
125        DR: 0x00000000,
126        BRR: 0x00000000,
127        CR1: 0x00000000,
128        CR2: 0x00000000,
129        CR3: 0x00000000,
130        GTPR: 0x00000000,
131    };
132
133    #[cfg(not(feature = "nosync"))]
134    #[allow(renamed_and_removed_lints)]
135    #[allow(private_no_mangle_statics)]
136    #[no_mangle]
137    static mut USART2_TAKEN: bool = false;
138
139    /// Safe access to USART2
140    ///
141    /// This function returns `Some(Instance)` if this instance is not
142    /// currently taken, and `None` if it is. This ensures that if you
143    /// do get `Some(Instance)`, you are ensured unique access to
144    /// the peripheral and there cannot be data races (unless other
145    /// code uses `unsafe`, of course). You can then pass the
146    /// `Instance` around to other functions as required. When you're
147    /// done with it, you can call `release(instance)` to return it.
148    ///
149    /// `Instance` itself dereferences to a `RegisterBlock`, which
150    /// provides access to the peripheral's registers.
151    #[cfg(not(feature = "nosync"))]
152    #[inline]
153    pub fn take() -> Option<Instance> {
154        external_cortex_m::interrupt::free(|_| unsafe {
155            if USART2_TAKEN {
156                None
157            } else {
158                USART2_TAKEN = true;
159                Some(INSTANCE)
160            }
161        })
162    }
163
164    /// Release exclusive access to USART2
165    ///
166    /// This function allows you to return an `Instance` so that it
167    /// is available to `take()` again. This function will panic if
168    /// you return a different `Instance` or if this instance is not
169    /// already taken.
170    #[cfg(not(feature = "nosync"))]
171    #[inline]
172    pub fn release(inst: Instance) {
173        external_cortex_m::interrupt::free(|_| unsafe {
174            if USART2_TAKEN && inst.addr == INSTANCE.addr {
175                USART2_TAKEN = false;
176            } else {
177                panic!("Released a peripheral which was not taken");
178            }
179        });
180    }
181
182    /// Unsafely steal USART2
183    ///
184    /// This function is similar to take() but forcibly takes the
185    /// Instance, marking it as taken irregardless of its previous
186    /// state.
187    #[cfg(not(feature = "nosync"))]
188    #[inline]
189    pub unsafe fn steal() -> Instance {
190        USART2_TAKEN = true;
191        INSTANCE
192    }
193}
194
195/// Raw pointer to USART2
196///
197/// Dereferencing this is unsafe because you are not ensured unique
198/// access to the peripheral, so you may encounter data races with
199/// other users of this peripheral. It is up to you to ensure you
200/// will not cause data races.
201///
202/// This constant is provided for ease of use in unsafe code: you can
203/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
204pub const USART2: *const RegisterBlock = 0x40004400 as *const _;
205
206/// Access functions for the USART3 peripheral instance
207pub mod USART3 {
208    use super::ResetValues;
209
210    #[cfg(not(feature = "nosync"))]
211    use super::Instance;
212
213    #[cfg(not(feature = "nosync"))]
214    const INSTANCE: Instance = Instance {
215        addr: 0x40004800,
216        _marker: ::core::marker::PhantomData,
217    };
218
219    /// Reset values for each field in USART3
220    pub const reset: ResetValues = ResetValues {
221        SR: 0x000000C0,
222        DR: 0x00000000,
223        BRR: 0x00000000,
224        CR1: 0x00000000,
225        CR2: 0x00000000,
226        CR3: 0x00000000,
227        GTPR: 0x00000000,
228    };
229
230    #[cfg(not(feature = "nosync"))]
231    #[allow(renamed_and_removed_lints)]
232    #[allow(private_no_mangle_statics)]
233    #[no_mangle]
234    static mut USART3_TAKEN: bool = false;
235
236    /// Safe access to USART3
237    ///
238    /// This function returns `Some(Instance)` if this instance is not
239    /// currently taken, and `None` if it is. This ensures that if you
240    /// do get `Some(Instance)`, you are ensured unique access to
241    /// the peripheral and there cannot be data races (unless other
242    /// code uses `unsafe`, of course). You can then pass the
243    /// `Instance` around to other functions as required. When you're
244    /// done with it, you can call `release(instance)` to return it.
245    ///
246    /// `Instance` itself dereferences to a `RegisterBlock`, which
247    /// provides access to the peripheral's registers.
248    #[cfg(not(feature = "nosync"))]
249    #[inline]
250    pub fn take() -> Option<Instance> {
251        external_cortex_m::interrupt::free(|_| unsafe {
252            if USART3_TAKEN {
253                None
254            } else {
255                USART3_TAKEN = true;
256                Some(INSTANCE)
257            }
258        })
259    }
260
261    /// Release exclusive access to USART3
262    ///
263    /// This function allows you to return an `Instance` so that it
264    /// is available to `take()` again. This function will panic if
265    /// you return a different `Instance` or if this instance is not
266    /// already taken.
267    #[cfg(not(feature = "nosync"))]
268    #[inline]
269    pub fn release(inst: Instance) {
270        external_cortex_m::interrupt::free(|_| unsafe {
271            if USART3_TAKEN && inst.addr == INSTANCE.addr {
272                USART3_TAKEN = false;
273            } else {
274                panic!("Released a peripheral which was not taken");
275            }
276        });
277    }
278
279    /// Unsafely steal USART3
280    ///
281    /// This function is similar to take() but forcibly takes the
282    /// Instance, marking it as taken irregardless of its previous
283    /// state.
284    #[cfg(not(feature = "nosync"))]
285    #[inline]
286    pub unsafe fn steal() -> Instance {
287        USART3_TAKEN = true;
288        INSTANCE
289    }
290}
291
292/// Raw pointer to USART3
293///
294/// Dereferencing this is unsafe because you are not ensured unique
295/// access to the peripheral, so you may encounter data races with
296/// other users of this peripheral. It is up to you to ensure you
297/// will not cause data races.
298///
299/// This constant is provided for ease of use in unsafe code: you can
300/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
301pub const USART3: *const RegisterBlock = 0x40004800 as *const _;