stm32ral/stm32mp/instances/
fdcan.rs

1#![allow(non_snake_case, non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3//! FDCAN1
4//!
5//! Used by: stm32mp153, stm32mp157
6
7#[cfg(not(feature = "nosync"))]
8pub use crate::stm32mp::peripherals::fdcan::Instance;
9pub use crate::stm32mp::peripherals::fdcan::{RegisterBlock, ResetValues};
10pub use crate::stm32mp::peripherals::fdcan::{
11    FDCAN_CCCR, FDCAN_CREL, FDCAN_DBTP, FDCAN_ECR, FDCAN_ENDN, FDCAN_GFC, FDCAN_HPMS, FDCAN_IE,
12    FDCAN_ILE, FDCAN_ILS, FDCAN_IR, FDCAN_NBTP, FDCAN_NDAT1, FDCAN_NDAT2, FDCAN_PSR, FDCAN_RWD,
13    FDCAN_RXBC, FDCAN_RXESC, FDCAN_RXF0A, FDCAN_RXF0C, FDCAN_RXF0S, FDCAN_RXF1A, FDCAN_RXF1C,
14    FDCAN_RXF1S, FDCAN_SIDFC, FDCAN_TDCR, FDCAN_TEST, FDCAN_TOCC, FDCAN_TOCV, FDCAN_TSCC,
15    FDCAN_TSCV, FDCAN_TTCPT, FDCAN_TTCSM, FDCAN_TTCTC, FDCAN_TTGTP, FDCAN_TTIE, FDCAN_TTILS,
16    FDCAN_TTIR, FDCAN_TTLGT, FDCAN_TTMLM, FDCAN_TTOCF, FDCAN_TTOCN, FDCAN_TTOST, FDCAN_TTRMC,
17    FDCAN_TTTMC, FDCAN_TTTMK, FDCAN_TTTS, FDCAN_TURCF, FDCAN_TURNA, FDCAN_TXBAR, FDCAN_TXBC,
18    FDCAN_TXBCF, FDCAN_TXBCIE, FDCAN_TXBCR, FDCAN_TXBTIE, FDCAN_TXBTO, FDCAN_TXEFA, FDCAN_TXEFC,
19    FDCAN_TXEFS, FDCAN_TXESC, FDCAN_TXFQS, FDCAN_XIDAM, FDCAN_XIDFC,
20};
21
22/// Access functions for the FDCAN1 peripheral instance
23pub mod FDCAN1 {
24    use super::ResetValues;
25
26    #[cfg(not(feature = "nosync"))]
27    use super::Instance;
28
29    #[cfg(not(feature = "nosync"))]
30    const INSTANCE: Instance = Instance {
31        addr: 0x4400e000,
32        _marker: ::core::marker::PhantomData,
33    };
34
35    /// Reset values for each field in FDCAN1
36    pub const reset: ResetValues = ResetValues {
37        FDCAN_CREL: 0x32141218,
38        FDCAN_ENDN: 0x87654321,
39        FDCAN_DBTP: 0x00000A33,
40        FDCAN_TEST: 0x00000000,
41        FDCAN_RWD: 0x00000000,
42        FDCAN_CCCR: 0x00000001,
43        FDCAN_NBTP: 0x00000A33,
44        FDCAN_TSCC: 0x00000000,
45        FDCAN_TSCV: 0x00000000,
46        FDCAN_TOCC: 0xFFFF0000,
47        FDCAN_TOCV: 0x0000FFFF,
48        FDCAN_ECR: 0x00000000,
49        FDCAN_PSR: 0x00000707,
50        FDCAN_TDCR: 0x00000000,
51        FDCAN_IR: 0x00000000,
52        FDCAN_IE: 0x00000000,
53        FDCAN_ILS: 0x00000000,
54        FDCAN_ILE: 0x00000000,
55        FDCAN_GFC: 0x00000000,
56        FDCAN_SIDFC: 0x00000000,
57        FDCAN_XIDFC: 0x00000000,
58        FDCAN_XIDAM: 0x1FFFFFFF,
59        FDCAN_HPMS: 0x00000000,
60        FDCAN_NDAT1: 0x00000000,
61        FDCAN_NDAT2: 0x00000000,
62        FDCAN_RXF0C: 0x00000000,
63        FDCAN_RXF0S: 0x00000000,
64        FDCAN_RXF0A: 0x00000000,
65        FDCAN_RXBC: 0x00000000,
66        FDCAN_RXF1C: 0x00000000,
67        FDCAN_RXF1S: 0x00000000,
68        FDCAN_RXF1A: 0x00000000,
69        FDCAN_RXESC: 0x00000000,
70        FDCAN_TXBC: 0x00000000,
71        FDCAN_TXFQS: 0x00000000,
72        FDCAN_TXESC: 0x00000000,
73        FDCAN_TXBAR: 0x00000000,
74        FDCAN_TXBCR: 0x00000000,
75        FDCAN_TXBTO: 0x00000000,
76        FDCAN_TXBCF: 0x00000000,
77        FDCAN_TXBTIE: 0x00000000,
78        FDCAN_TXBCIE: 0x00000000,
79        FDCAN_TXEFC: 0x00000000,
80        FDCAN_TXEFS: 0x00000000,
81        FDCAN_TXEFA: 0x00000000,
82        FDCAN_TTTMC: 0x00000000,
83        FDCAN_TTRMC: 0x00000000,
84        FDCAN_TTOCF: 0x00010000,
85        FDCAN_TTMLM: 0x00000000,
86        FDCAN_TURCF: 0x00000000,
87        FDCAN_TTOCN: 0x00000000,
88        FDCAN_TTGTP: 0x00000000,
89        FDCAN_TTTMK: 0x00000000,
90        FDCAN_TTIR: 0x00000000,
91        FDCAN_TTIE: 0x00000000,
92        FDCAN_TTILS: 0x00000000,
93        FDCAN_TTOST: 0x00000080,
94        FDCAN_TURNA: 0x00000000,
95        FDCAN_TTLGT: 0x00000000,
96        FDCAN_TTCTC: 0x003F0000,
97        FDCAN_TTCPT: 0x00000000,
98        FDCAN_TTCSM: 0x00000000,
99        FDCAN_TTTS: 0x00000000,
100    };
101
102    #[cfg(not(feature = "nosync"))]
103    #[allow(renamed_and_removed_lints)]
104    #[allow(private_no_mangle_statics)]
105    #[no_mangle]
106    static mut FDCAN1_TAKEN: bool = false;
107
108    /// Safe access to FDCAN1
109    ///
110    /// This function returns `Some(Instance)` if this instance is not
111    /// currently taken, and `None` if it is. This ensures that if you
112    /// do get `Some(Instance)`, you are ensured unique access to
113    /// the peripheral and there cannot be data races (unless other
114    /// code uses `unsafe`, of course). You can then pass the
115    /// `Instance` around to other functions as required. When you're
116    /// done with it, you can call `release(instance)` to return it.
117    ///
118    /// `Instance` itself dereferences to a `RegisterBlock`, which
119    /// provides access to the peripheral's registers.
120    #[cfg(not(feature = "nosync"))]
121    #[inline]
122    pub fn take() -> Option<Instance> {
123        external_cortex_m::interrupt::free(|_| unsafe {
124            if FDCAN1_TAKEN {
125                None
126            } else {
127                FDCAN1_TAKEN = true;
128                Some(INSTANCE)
129            }
130        })
131    }
132
133    /// Release exclusive access to FDCAN1
134    ///
135    /// This function allows you to return an `Instance` so that it
136    /// is available to `take()` again. This function will panic if
137    /// you return a different `Instance` or if this instance is not
138    /// already taken.
139    #[cfg(not(feature = "nosync"))]
140    #[inline]
141    pub fn release(inst: Instance) {
142        external_cortex_m::interrupt::free(|_| unsafe {
143            if FDCAN1_TAKEN && inst.addr == INSTANCE.addr {
144                FDCAN1_TAKEN = false;
145            } else {
146                panic!("Released a peripheral which was not taken");
147            }
148        });
149    }
150
151    /// Unsafely steal FDCAN1
152    ///
153    /// This function is similar to take() but forcibly takes the
154    /// Instance, marking it as taken irregardless of its previous
155    /// state.
156    #[cfg(not(feature = "nosync"))]
157    #[inline]
158    pub unsafe fn steal() -> Instance {
159        FDCAN1_TAKEN = true;
160        INSTANCE
161    }
162}
163
164/// Raw pointer to FDCAN1
165///
166/// Dereferencing this is unsafe because you are not ensured unique
167/// access to the peripheral, so you may encounter data races with
168/// other users of this peripheral. It is up to you to ensure you
169/// will not cause data races.
170///
171/// This constant is provided for ease of use in unsafe code: you can
172/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
173pub const FDCAN1: *const RegisterBlock = 0x4400e000 as *const _;
174
175/// Access functions for the FDCAN2 peripheral instance
176pub mod FDCAN2 {
177    use super::ResetValues;
178
179    #[cfg(not(feature = "nosync"))]
180    use super::Instance;
181
182    #[cfg(not(feature = "nosync"))]
183    const INSTANCE: Instance = Instance {
184        addr: 0x4400f000,
185        _marker: ::core::marker::PhantomData,
186    };
187
188    /// Reset values for each field in FDCAN2
189    pub const reset: ResetValues = ResetValues {
190        FDCAN_CREL: 0x32141218,
191        FDCAN_ENDN: 0x87654321,
192        FDCAN_DBTP: 0x00000A33,
193        FDCAN_TEST: 0x00000000,
194        FDCAN_RWD: 0x00000000,
195        FDCAN_CCCR: 0x00000001,
196        FDCAN_NBTP: 0x00000A33,
197        FDCAN_TSCC: 0x00000000,
198        FDCAN_TSCV: 0x00000000,
199        FDCAN_TOCC: 0xFFFF0000,
200        FDCAN_TOCV: 0x0000FFFF,
201        FDCAN_ECR: 0x00000000,
202        FDCAN_PSR: 0x00000707,
203        FDCAN_TDCR: 0x00000000,
204        FDCAN_IR: 0x00000000,
205        FDCAN_IE: 0x00000000,
206        FDCAN_ILS: 0x00000000,
207        FDCAN_ILE: 0x00000000,
208        FDCAN_GFC: 0x00000000,
209        FDCAN_SIDFC: 0x00000000,
210        FDCAN_XIDFC: 0x00000000,
211        FDCAN_XIDAM: 0x1FFFFFFF,
212        FDCAN_HPMS: 0x00000000,
213        FDCAN_NDAT1: 0x00000000,
214        FDCAN_NDAT2: 0x00000000,
215        FDCAN_RXF0C: 0x00000000,
216        FDCAN_RXF0S: 0x00000000,
217        FDCAN_RXF0A: 0x00000000,
218        FDCAN_RXBC: 0x00000000,
219        FDCAN_RXF1C: 0x00000000,
220        FDCAN_RXF1S: 0x00000000,
221        FDCAN_RXF1A: 0x00000000,
222        FDCAN_RXESC: 0x00000000,
223        FDCAN_TXBC: 0x00000000,
224        FDCAN_TXFQS: 0x00000000,
225        FDCAN_TXESC: 0x00000000,
226        FDCAN_TXBAR: 0x00000000,
227        FDCAN_TXBCR: 0x00000000,
228        FDCAN_TXBTO: 0x00000000,
229        FDCAN_TXBCF: 0x00000000,
230        FDCAN_TXBTIE: 0x00000000,
231        FDCAN_TXBCIE: 0x00000000,
232        FDCAN_TXEFC: 0x00000000,
233        FDCAN_TXEFS: 0x00000000,
234        FDCAN_TXEFA: 0x00000000,
235        FDCAN_TTTMC: 0x00000000,
236        FDCAN_TTRMC: 0x00000000,
237        FDCAN_TTOCF: 0x00010000,
238        FDCAN_TTMLM: 0x00000000,
239        FDCAN_TURCF: 0x00000000,
240        FDCAN_TTOCN: 0x00000000,
241        FDCAN_TTGTP: 0x00000000,
242        FDCAN_TTTMK: 0x00000000,
243        FDCAN_TTIR: 0x00000000,
244        FDCAN_TTIE: 0x00000000,
245        FDCAN_TTILS: 0x00000000,
246        FDCAN_TTOST: 0x00000080,
247        FDCAN_TURNA: 0x00000000,
248        FDCAN_TTLGT: 0x00000000,
249        FDCAN_TTCTC: 0x003F0000,
250        FDCAN_TTCPT: 0x00000000,
251        FDCAN_TTCSM: 0x00000000,
252        FDCAN_TTTS: 0x00000000,
253    };
254
255    #[cfg(not(feature = "nosync"))]
256    #[allow(renamed_and_removed_lints)]
257    #[allow(private_no_mangle_statics)]
258    #[no_mangle]
259    static mut FDCAN2_TAKEN: bool = false;
260
261    /// Safe access to FDCAN2
262    ///
263    /// This function returns `Some(Instance)` if this instance is not
264    /// currently taken, and `None` if it is. This ensures that if you
265    /// do get `Some(Instance)`, you are ensured unique access to
266    /// the peripheral and there cannot be data races (unless other
267    /// code uses `unsafe`, of course). You can then pass the
268    /// `Instance` around to other functions as required. When you're
269    /// done with it, you can call `release(instance)` to return it.
270    ///
271    /// `Instance` itself dereferences to a `RegisterBlock`, which
272    /// provides access to the peripheral's registers.
273    #[cfg(not(feature = "nosync"))]
274    #[inline]
275    pub fn take() -> Option<Instance> {
276        external_cortex_m::interrupt::free(|_| unsafe {
277            if FDCAN2_TAKEN {
278                None
279            } else {
280                FDCAN2_TAKEN = true;
281                Some(INSTANCE)
282            }
283        })
284    }
285
286    /// Release exclusive access to FDCAN2
287    ///
288    /// This function allows you to return an `Instance` so that it
289    /// is available to `take()` again. This function will panic if
290    /// you return a different `Instance` or if this instance is not
291    /// already taken.
292    #[cfg(not(feature = "nosync"))]
293    #[inline]
294    pub fn release(inst: Instance) {
295        external_cortex_m::interrupt::free(|_| unsafe {
296            if FDCAN2_TAKEN && inst.addr == INSTANCE.addr {
297                FDCAN2_TAKEN = false;
298            } else {
299                panic!("Released a peripheral which was not taken");
300            }
301        });
302    }
303
304    /// Unsafely steal FDCAN2
305    ///
306    /// This function is similar to take() but forcibly takes the
307    /// Instance, marking it as taken irregardless of its previous
308    /// state.
309    #[cfg(not(feature = "nosync"))]
310    #[inline]
311    pub unsafe fn steal() -> Instance {
312        FDCAN2_TAKEN = true;
313        INSTANCE
314    }
315}
316
317/// Raw pointer to FDCAN2
318///
319/// Dereferencing this is unsafe because you are not ensured unique
320/// access to the peripheral, so you may encounter data races with
321/// other users of this peripheral. It is up to you to ensure you
322/// will not cause data races.
323///
324/// This constant is provided for ease of use in unsafe code: you can
325/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
326pub const FDCAN2: *const RegisterBlock = 0x4400f000 as *const _;