stm32ral/stm32wl/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: stm32wl5x_cm0p, stm32wl5x_cm4, stm32wle5
6
7#[cfg(not(feature = "nosync"))]
8pub use crate::stm32wl::peripherals::usart::Instance;
9pub use crate::stm32wl::peripherals::usart::{RegisterBlock, ResetValues};
10pub use crate::stm32wl::peripherals::usart::{
11 BRR, CR1, CR2, CR3, GTPR, ICR, ISR, PRESC, RDR, RQR, RTOR, TDR,
12};
13
14/// Access functions for the USART1 peripheral instance
15pub mod USART1 {
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 USART1
28 pub const reset: ResetValues = ResetValues {
29 CR1: 0x00000000,
30 CR2: 0x00000000,
31 CR3: 0x00000000,
32 BRR: 0x00000000,
33 GTPR: 0x00000000,
34 RTOR: 0x00000000,
35 RQR: 0x00000000,
36 ISR: 0x00000000,
37 ICR: 0x00000000,
38 RDR: 0x00000000,
39 TDR: 0x00000000,
40 PRESC: 0x00000000,
41 };
42
43 #[cfg(not(feature = "nosync"))]
44 #[allow(renamed_and_removed_lints)]
45 #[allow(private_no_mangle_statics)]
46 #[no_mangle]
47 static mut USART1_TAKEN: bool = false;
48
49 /// Safe access to USART1
50 ///
51 /// This function returns `Some(Instance)` if this instance is not
52 /// currently taken, and `None` if it is. This ensures that if you
53 /// do get `Some(Instance)`, you are ensured unique access to
54 /// the peripheral and there cannot be data races (unless other
55 /// code uses `unsafe`, of course). You can then pass the
56 /// `Instance` around to other functions as required. When you're
57 /// done with it, you can call `release(instance)` to return it.
58 ///
59 /// `Instance` itself dereferences to a `RegisterBlock`, which
60 /// provides access to the peripheral's registers.
61 #[cfg(not(feature = "nosync"))]
62 #[inline]
63 pub fn take() -> Option<Instance> {
64 external_cortex_m::interrupt::free(|_| unsafe {
65 if USART1_TAKEN {
66 None
67 } else {
68 USART1_TAKEN = true;
69 Some(INSTANCE)
70 }
71 })
72 }
73
74 /// Release exclusive access to USART1
75 ///
76 /// This function allows you to return an `Instance` so that it
77 /// is available to `take()` again. This function will panic if
78 /// you return a different `Instance` or if this instance is not
79 /// already taken.
80 #[cfg(not(feature = "nosync"))]
81 #[inline]
82 pub fn release(inst: Instance) {
83 external_cortex_m::interrupt::free(|_| unsafe {
84 if USART1_TAKEN && inst.addr == INSTANCE.addr {
85 USART1_TAKEN = false;
86 } else {
87 panic!("Released a peripheral which was not taken");
88 }
89 });
90 }
91
92 /// Unsafely steal USART1
93 ///
94 /// This function is similar to take() but forcibly takes the
95 /// Instance, marking it as taken irregardless of its previous
96 /// state.
97 #[cfg(not(feature = "nosync"))]
98 #[inline]
99 pub unsafe fn steal() -> Instance {
100 USART1_TAKEN = true;
101 INSTANCE
102 }
103}
104
105/// Raw pointer to USART1
106///
107/// Dereferencing this is unsafe because you are not ensured unique
108/// access to the peripheral, so you may encounter data races with
109/// other users of this peripheral. It is up to you to ensure you
110/// will not cause data races.
111///
112/// This constant is provided for ease of use in unsafe code: you can
113/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
114pub const USART1: *const RegisterBlock = 0x40013800 as *const _;
115
116/// Access functions for the USART2 peripheral instance
117pub mod USART2 {
118 use super::ResetValues;
119
120 #[cfg(not(feature = "nosync"))]
121 use super::Instance;
122
123 #[cfg(not(feature = "nosync"))]
124 const INSTANCE: Instance = Instance {
125 addr: 0x40004400,
126 _marker: ::core::marker::PhantomData,
127 };
128
129 /// Reset values for each field in USART2
130 pub const reset: ResetValues = ResetValues {
131 CR1: 0x00000000,
132 CR2: 0x00000000,
133 CR3: 0x00000000,
134 BRR: 0x00000000,
135 GTPR: 0x00000000,
136 RTOR: 0x00000000,
137 RQR: 0x00000000,
138 ISR: 0x00000000,
139 ICR: 0x00000000,
140 RDR: 0x00000000,
141 TDR: 0x00000000,
142 PRESC: 0x00000000,
143 };
144
145 #[cfg(not(feature = "nosync"))]
146 #[allow(renamed_and_removed_lints)]
147 #[allow(private_no_mangle_statics)]
148 #[no_mangle]
149 static mut USART2_TAKEN: bool = false;
150
151 /// Safe access to USART2
152 ///
153 /// This function returns `Some(Instance)` if this instance is not
154 /// currently taken, and `None` if it is. This ensures that if you
155 /// do get `Some(Instance)`, you are ensured unique access to
156 /// the peripheral and there cannot be data races (unless other
157 /// code uses `unsafe`, of course). You can then pass the
158 /// `Instance` around to other functions as required. When you're
159 /// done with it, you can call `release(instance)` to return it.
160 ///
161 /// `Instance` itself dereferences to a `RegisterBlock`, which
162 /// provides access to the peripheral's registers.
163 #[cfg(not(feature = "nosync"))]
164 #[inline]
165 pub fn take() -> Option<Instance> {
166 external_cortex_m::interrupt::free(|_| unsafe {
167 if USART2_TAKEN {
168 None
169 } else {
170 USART2_TAKEN = true;
171 Some(INSTANCE)
172 }
173 })
174 }
175
176 /// Release exclusive access to USART2
177 ///
178 /// This function allows you to return an `Instance` so that it
179 /// is available to `take()` again. This function will panic if
180 /// you return a different `Instance` or if this instance is not
181 /// already taken.
182 #[cfg(not(feature = "nosync"))]
183 #[inline]
184 pub fn release(inst: Instance) {
185 external_cortex_m::interrupt::free(|_| unsafe {
186 if USART2_TAKEN && inst.addr == INSTANCE.addr {
187 USART2_TAKEN = false;
188 } else {
189 panic!("Released a peripheral which was not taken");
190 }
191 });
192 }
193
194 /// Unsafely steal USART2
195 ///
196 /// This function is similar to take() but forcibly takes the
197 /// Instance, marking it as taken irregardless of its previous
198 /// state.
199 #[cfg(not(feature = "nosync"))]
200 #[inline]
201 pub unsafe fn steal() -> Instance {
202 USART2_TAKEN = true;
203 INSTANCE
204 }
205}
206
207/// Raw pointer to USART2
208///
209/// Dereferencing this is unsafe because you are not ensured unique
210/// access to the peripheral, so you may encounter data races with
211/// other users of this peripheral. It is up to you to ensure you
212/// will not cause data races.
213///
214/// This constant is provided for ease of use in unsafe code: you can
215/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
216pub const USART2: *const RegisterBlock = 0x40004400 as *const _;