1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#![allow(non_snake_case, non_upper_case_globals)]
#![allow(non_camel_case_types)]
//! Backup registers
//!
//! Used by: stm32f100, stm32f101, stm32f102, stm32f103, stm32f107
#[cfg(not(feature = "nosync"))]
pub use crate::stm32f1::peripherals::bkp::Instance;
pub use crate::stm32f1::peripherals::bkp::{RegisterBlock, ResetValues};
pub use crate::stm32f1::peripherals::bkp::{
BKP_DR11, BKP_DR12, BKP_DR13, BKP_DR14, BKP_DR15, BKP_DR16, BKP_DR17, BKP_DR18, BKP_DR19,
BKP_DR20, BKP_DR21, BKP_DR22, BKP_DR23, BKP_DR24, BKP_DR25, BKP_DR26, BKP_DR27, BKP_DR28,
BKP_DR29, BKP_DR30, BKP_DR31, BKP_DR32, BKP_DR33, BKP_DR34, BKP_DR35, BKP_DR36, BKP_DR37,
BKP_DR38, BKP_DR39, BKP_DR40, BKP_DR41, BKP_DR42, CR, CSR, DR1, DR10, DR2, DR3, DR4, DR5, DR6,
DR7, DR8, DR9, RTCCR,
};
/// Access functions for the BKP peripheral instance
pub mod BKP {
use super::ResetValues;
#[cfg(not(feature = "nosync"))]
use super::Instance;
#[cfg(not(feature = "nosync"))]
const INSTANCE: Instance = Instance {
addr: 0x40006c04,
_marker: ::core::marker::PhantomData,
};
/// Reset values for each field in BKP
pub const reset: ResetValues = ResetValues {
DR1: 0x00000000,
DR2: 0x00000000,
DR3: 0x00000000,
DR4: 0x00000000,
DR5: 0x00000000,
DR6: 0x00000000,
DR7: 0x00000000,
DR8: 0x00000000,
DR9: 0x00000000,
DR10: 0x00000000,
BKP_DR11: 0x00000000,
BKP_DR12: 0x00000000,
BKP_DR13: 0x00000000,
BKP_DR14: 0x00000000,
BKP_DR15: 0x00000000,
BKP_DR16: 0x00000000,
BKP_DR17: 0x00000000,
BKP_DR18: 0x00000000,
BKP_DR19: 0x00000000,
BKP_DR20: 0x00000000,
BKP_DR21: 0x00000000,
BKP_DR22: 0x00000000,
BKP_DR23: 0x00000000,
BKP_DR24: 0x00000000,
BKP_DR25: 0x00000000,
BKP_DR26: 0x00000000,
BKP_DR27: 0x00000000,
BKP_DR28: 0x00000000,
BKP_DR29: 0x00000000,
BKP_DR30: 0x00000000,
BKP_DR31: 0x00000000,
BKP_DR32: 0x00000000,
BKP_DR33: 0x00000000,
BKP_DR34: 0x00000000,
BKP_DR35: 0x00000000,
BKP_DR36: 0x00000000,
BKP_DR37: 0x00000000,
BKP_DR38: 0x00000000,
BKP_DR39: 0x00000000,
BKP_DR40: 0x00000000,
BKP_DR41: 0x00000000,
BKP_DR42: 0x00000000,
RTCCR: 0x00000000,
CR: 0x00000000,
CSR: 0x00000000,
};
#[cfg(not(feature = "nosync"))]
#[allow(renamed_and_removed_lints)]
#[allow(private_no_mangle_statics)]
#[no_mangle]
static mut BKP_TAKEN: bool = false;
/// Safe access to BKP
///
/// This function returns `Some(Instance)` if this instance is not
/// currently taken, and `None` if it is. This ensures that if you
/// do get `Some(Instance)`, you are ensured unique access to
/// the peripheral and there cannot be data races (unless other
/// code uses `unsafe`, of course). You can then pass the
/// `Instance` around to other functions as required. When you're
/// done with it, you can call `release(instance)` to return it.
///
/// `Instance` itself dereferences to a `RegisterBlock`, which
/// provides access to the peripheral's registers.
#[cfg(not(feature = "nosync"))]
#[inline]
pub fn take() -> Option<Instance> {
external_cortex_m::interrupt::free(|_| unsafe {
if BKP_TAKEN {
None
} else {
BKP_TAKEN = true;
Some(INSTANCE)
}
})
}
/// Release exclusive access to BKP
///
/// This function allows you to return an `Instance` so that it
/// is available to `take()` again. This function will panic if
/// you return a different `Instance` or if this instance is not
/// already taken.
#[cfg(not(feature = "nosync"))]
#[inline]
pub fn release(inst: Instance) {
external_cortex_m::interrupt::free(|_| unsafe {
if BKP_TAKEN && inst.addr == INSTANCE.addr {
BKP_TAKEN = false;
} else {
panic!("Released a peripheral which was not taken");
}
});
}
/// Unsafely steal BKP
///
/// This function is similar to take() but forcibly takes the
/// Instance, marking it as taken irregardless of its previous
/// state.
#[cfg(not(feature = "nosync"))]
#[inline]
pub unsafe fn steal() -> Instance {
BKP_TAKEN = true;
INSTANCE
}
}
/// Raw pointer to BKP
///
/// Dereferencing this is unsafe because you are not ensured unique
/// access to the peripheral, so you may encounter data races with
/// other users of this peripheral. It is up to you to ensure you
/// will not cause data races.
///
/// This constant is provided for ease of use in unsafe code: you can
/// simply call for example `write_reg!(gpio, GPIOA, ODR, 1);`.
pub const BKP: *const RegisterBlock = 0x40006c04 as *const _;