stm32f072x_memory_map/
lib.rs

1//! Memory map for STM32F30X microcontrollers
2
3#![deny(missing_docs)]
4#![no_std]
5
6extern crate volatile_register;
7
8#[allow(missing_docs)]
9pub mod btim;
10#[allow(missing_docs)]
11pub mod dbgmcu;
12#[allow(missing_docs)]
13pub mod gpio;
14#[allow(missing_docs)]
15pub mod gptim;
16#[allow(missing_docs)]
17pub mod i2c;
18#[allow(missing_docs)]
19pub mod rcc;
20#[allow(missing_docs)]
21pub mod spi;
22#[allow(missing_docs)]
23pub mod usart;
24
25use btim::BTim;
26use dbgmcu::Dbgmcu;
27use gpio::Gpio;
28use gptim::GpTim;
29use i2c::I2c;
30use rcc::Rcc;
31use spi::Spi;
32use usart::Usart;
33
34const CRC: usize = 0x40023000;
35const GPIOF: usize = 0x48001400;
36const GPIOD: usize = 0x48000c00;
37const GPIOC: usize = 0x48000800;
38const GPIOB: usize = 0x48000400;
39const GPIOE: usize = 0x48001000;
40const GPIOA: usize = 0x48000000;
41const SPI1: usize = 0x40013000;
42const SPI2: usize = 0x40003800;
43const DAC: usize = 0x40007400;
44const PWR: usize = 0x40007000;
45const I2C1: usize = 0x40005400;
46const I2C2: usize = 0x40005800;
47const IWDG: usize = 0x40003000;
48const WWDG: usize = 0x40002c00;
49const TIM1: usize = 0x40012c00;
50const TIM2: usize = 0x40000000;
51const TIM3: usize = 0x40000400;
52const TIM14: usize = 0x40002000;
53const TIM6: usize = 0x40001000;
54const TIM7: usize = 0x40001400;
55const EXTI: usize = 0x40010400;
56const NVIC: usize = 0xe000e100;
57const DMA: usize = 0x40020000;
58const RCC: usize = 0x40021000;
59const SYSCFG: usize = 0x40010000;
60const ADC: usize = 0x40012400;
61const USART1: usize = 0x40013800;
62const USART2: usize = 0x40004400;
63const USART3: usize = 0x40004800;
64const USART4: usize = 0x40004c00;
65const COMP: usize = 0x4001001c;
66const RTC: usize = 0x40002800;
67const TIM15: usize = 0x40014000;
68const TIM16: usize = 0x40014400;
69const TIM17: usize = 0x40014800;
70const TSC: usize = 0x40024000;
71const CEC: usize = 0x40007800;
72const FLASH: usize = 0x40022000;
73const DBGMCU: usize = 0x40015800;
74const USB: usize = 0x40005c00;
75const CRS: usize = 0x40006c00;
76const CAN: usize = 0x40006400;
77
78
79
80/// DBGMCU register block (&'static)
81pub fn dbgmcu() -> &'static Dbgmcu {
82    unsafe { deref(DBGMCU) }
83}
84
85/// DBGMCU register block (&'static mut)
86pub unsafe fn dbgmcu_mut() -> &'static mut Dbgmcu {
87    deref_mut(DBGMCU)
88}
89
90/// GPIOA register block (&'static)
91pub fn gpioa() -> &'static Gpio {
92    unsafe { deref(GPIOA) }
93}
94
95/// GPIOA register block (&'static mut)
96pub unsafe fn gpioa_mut() -> &'static mut Gpio {
97    deref_mut(GPIOA)
98}
99
100/// GPIOB register block (&'static)
101pub fn gpiob() -> &'static Gpio {
102    unsafe { deref(GPIOB) }
103}
104
105/// GPIOB register block (&'static mut)
106pub unsafe fn gpiob_mut() -> &'static mut Gpio {
107    deref_mut(GPIOB)
108}
109
110/// GPIOC register block (&'static)
111pub fn gpioc() -> &'static Gpio {
112    unsafe { deref(GPIOC) }
113}
114
115/// GPIOC register block (&'static mut)
116pub unsafe fn gpioc_mut() -> &'static mut Gpio {
117    deref_mut(GPIOC)
118}
119
120/// GPIOD register block (&'static)
121pub fn gpiod() -> &'static Gpio {
122    unsafe { deref(GPIOD) }
123}
124
125/// GPIOD register block (&'static mut)
126pub unsafe fn gpiod_mut() -> &'static mut Gpio {
127    deref_mut(GPIOD)
128}
129
130/// GPIOE register block (&'static)
131pub fn gpioe() -> &'static Gpio {
132    unsafe { deref(GPIOE) }
133}
134
135/// GPIOE register block (&'static mut)
136pub unsafe fn gpioe_mut() -> &'static mut Gpio {
137    deref_mut(GPIOE)
138}
139
140/// GPIOF register block (&'static)
141pub fn gpiof() -> &'static Gpio {
142    unsafe { deref(GPIOF) }
143}
144
145/// GPIOF register block (&'static mut)
146pub unsafe fn gpiof_mut() -> &'static mut Gpio {
147    deref_mut(GPIOF)
148}
149
150/// I2C1 register block (&'static)
151pub fn i2c1() -> &'static I2c {
152    unsafe { deref(I2C1) }
153}
154
155/// I2C1 register block (&'static mut)
156pub unsafe fn i2c1_mut() -> &'static mut I2c {
157    deref_mut(I2C1)
158}
159
160/// RCC register block (&'static)
161pub fn rcc() -> &'static Rcc {
162    unsafe { deref(RCC) }
163}
164
165/// RCC register block (&'static mut)
166pub unsafe fn rcc_mut() -> &'static mut Rcc {
167    deref_mut(RCC)
168}
169
170/// SPI1 register block (&'static)
171pub fn spi1() -> &'static Spi {
172    unsafe { deref(SPI1) }
173}
174
175/// SPI1 register block (&'static mut)
176pub unsafe fn spi1_mut() -> &'static mut Spi {
177    deref_mut(SPI1)
178}
179
180/// TIM2 register block (&'static)
181pub fn tim2() -> &'static GpTim {
182    unsafe { deref(TIM2) }
183}
184
185/// TIM2 register block (&'static mut)
186pub unsafe fn tim2_mut() -> &'static mut GpTim {
187    deref_mut(TIM2)
188}
189
190/// TIM3 register block (&'static)
191pub fn tim3() -> &'static GpTim {
192    unsafe { deref(TIM3) }
193}
194
195/// TIM3 register block (&'static mut)
196pub unsafe fn tim3_mut() -> &'static mut GpTim {
197    deref_mut(TIM3)
198}
199
200
201/// TIM6 register block (&'static)
202pub fn tim6() -> &'static BTim {
203    unsafe { deref(TIM6) }
204}
205
206/// TIM6 register block (&'static mut)
207pub unsafe fn tim6_mut() -> &'static mut BTim {
208    deref_mut(TIM6)
209}
210
211/// TIM7 register block (&'static)
212pub fn tim7() -> &'static BTim {
213    unsafe { deref(TIM7) }
214}
215
216/// TIM7 register block (&'static mut)
217pub unsafe fn tim7_mut() -> &'static mut BTim {
218    deref_mut(TIM7)
219}
220
221/// USART1 register block (&'static)
222pub fn usart1() -> &'static Usart {
223    unsafe { deref(USART1) }
224}
225
226/// USART1 register block (&'static mut)
227pub unsafe fn usart1_mut() -> &'static mut Usart {
228    deref_mut(USART1)
229}
230
231/// USART2 register block (&'static)
232pub fn usart2() -> &'static Usart {
233    unsafe { deref(USART2) }
234}
235
236/// USART2 register block (&'static mut)
237pub unsafe fn usart2_mut() -> &'static mut Usart {
238    deref_mut(USART2)
239}
240
241/// USART3 register block (&'static)
242pub fn usart3() -> &'static Usart {
243    unsafe { deref(USART3) }
244}
245
246/// USART3 register block (&'static mut)
247pub unsafe fn usart3_mut() -> &'static mut Usart {
248    deref_mut(USART3)
249}
250
251unsafe fn deref<T>(address: usize) -> &'static T {
252    &*(address as *const T)
253}
254
255unsafe fn deref_mut<T>(address: usize) -> &'static mut T {
256    &mut *(address as *mut T)
257}
258
259// Here we extend the peripheral API -- AKA ~~svd2rust is~~ SVD files are great
260// but not perfect
261use core::ptr;
262
263impl spi::Dr {
264    /// Reads a byte (`u8`) from this register
265    pub fn read_u8(&self) -> u8 {
266        unsafe { ptr::read_volatile(self as *const _ as *const u8) }
267    }
268
269    /// Writes a byte (`u8`) to this register
270    pub fn write_u8(&mut self, value: u8) {
271        unsafe { ptr::write_volatile(self as *mut _ as *mut u8, value) }
272    }
273}