Skip to content

Commit 8a89078

Browse files
bors[bot]burrbull
andauthored
Merge #311
311: Rcc Enable/Reset + features r=thalesfragoso a=burrbull Co-authored-by: Andrey Zgarbul <zgarbul.andrey@gmail.com>
2 parents 3c8e308 + d749a9f commit 8a89078

29 files changed

+1071
-2359
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ jobs:
4646
- uses: actions-rs/cargo@v1
4747
with:
4848
command: check
49-
args: --features=${{ matrix.mcu }},rt,usb_fs,sdio,can,i2s,fsmc_lcd --examples
49+
args: --features=${{ matrix.mcu }},rt,usb_fs,sdio-host,can,i2s,fsmc_lcd --examples

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Added
1111

12+
- `Enable`, `LPEnable` and `Reset` traits in `rcc`. Implemented for all used peripherals
13+
- Features corresponding to peripherals
1214
- Fixed typo in string representation in DMAError type
1315
- Added an example of integration with RTIC.
1416
- Added internal pullup configuaration for the AlternateOD pin type

Cargo.toml

Lines changed: 240 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,35 +65,255 @@ device-selected = []
6565
rt = ["stm32f4/rt"]
6666
# Note: stm32f4 has only one feature for some very similar device families,
6767
# so it's intended for e.g. stm32f405/415 to both enable stm32f4/stm32f405.
68-
stm32f401 = ["stm32f4/stm32f401", "device-selected"]
69-
stm32f405 = ["stm32f4/stm32f405", "device-selected"]
70-
stm32f407 = ["stm32f4/stm32f407", "device-selected"]
71-
stm32f410 = ["stm32f4/stm32f410", "device-selected"]
72-
stm32f411 = ["stm32f4/stm32f411", "device-selected"]
73-
stm32f412 = ["stm32f4/stm32f412", "device-selected"]
74-
stm32f413 = ["stm32f4/stm32f413", "device-selected"]
75-
stm32f415 = ["stm32f4/stm32f405", "device-selected"]
76-
stm32f417 = ["stm32f4/stm32f407", "device-selected"]
77-
stm32f423 = ["stm32f4/stm32f413", "device-selected"]
78-
stm32f427 = ["stm32f4/stm32f427", "device-selected"]
79-
stm32f429 = ["stm32f4/stm32f429", "device-selected"]
80-
stm32f437 = ["stm32f4/stm32f427", "device-selected"]
81-
stm32f439 = ["stm32f4/stm32f429", "device-selected"]
82-
stm32f446 = ["stm32f4/stm32f446", "device-selected"]
83-
stm32f469 = ["stm32f4/stm32f469", "device-selected"]
84-
stm32f479 = ["stm32f4/stm32f469", "device-selected"]
68+
stm32f401 = ["stm32f4/stm32f401", "device-selected",
69+
"gpiod", "gpioe",
70+
"i2c3",
71+
"otg-fs",
72+
"sdio",
73+
"spi3", "spi4",
74+
]
75+
stm32f405 = ["stm32f4/stm32f405", "device-selected",
76+
"adc2", "adc3",
77+
"can1", "can2",
78+
"dac",
79+
"fsmc",
80+
"gpiod", "gpioe", "gpiof", "gpiog", "gpioi",
81+
"i2c3",
82+
"otg-fs",
83+
"otg-hs",
84+
"rng",
85+
"sdio",
86+
"spi3",
87+
"usart3", "uart4", "uart5",
88+
]
89+
stm32f407 = ["stm32f4/stm32f407", "device-selected",
90+
"adc2", "adc3",
91+
"can1", "can2",
92+
"dac",
93+
"fsmc",
94+
"gpiod", "gpioe", "gpiof", "gpiog", "gpioi",
95+
"i2c3",
96+
"otg-fs",
97+
"otg-hs",
98+
"rng",
99+
"sdio",
100+
"spi3",
101+
"usart3", "uart4", "uart5",
102+
]
103+
stm32f410 = ["stm32f4/stm32f410", "device-selected",
104+
"dac",
105+
"spi5",
106+
]
107+
stm32f411 = ["stm32f4/stm32f411", "device-selected",
108+
"gpiod", "gpioe",
109+
"i2c3",
110+
"otg-fs",
111+
"sdio",
112+
"spi3", "spi4", "spi5",
113+
]
114+
stm32f412 = ["stm32f4/stm32f412", "device-selected",
115+
"can1", "can2",
116+
"fsmc",
117+
"gpiod", "gpioe", "gpiof", "gpiog",
118+
"i2c3",
119+
"otg-fs",
120+
"rng",
121+
"sdio",
122+
"spi3", "spi4", "spi5",
123+
"usart3",
124+
]
125+
stm32f413 = ["stm32f4/stm32f413", "device-selected",
126+
"can1", "can2",
127+
"dac",
128+
"fsmc",
129+
"fmpi2c1",
130+
"gpiod", "gpioe", "gpiof", "gpiog",
131+
"i2c3",
132+
"otg-fs",
133+
"rng",
134+
"sdio",
135+
"spi3", "spi4", "spi5",
136+
"usart3", "uart4", "uart5", "uart7", "uart8", "uart9", "uart10",
137+
]
138+
stm32f415 = ["stm32f4/stm32f405", "device-selected",
139+
"adc2", "adc3",
140+
"can1", "can2",
141+
"dac",
142+
"fsmc",
143+
"gpiod", "gpioe", "gpiof", "gpiog", "gpioi",
144+
"i2c3",
145+
"otg-fs",
146+
"otg-hs",
147+
"rng",
148+
"sdio",
149+
"spi3",
150+
"usart3", "uart4", "uart5",
151+
]
152+
stm32f417 = ["stm32f4/stm32f407", "device-selected",
153+
"adc2", "adc3",
154+
"can1", "can2",
155+
"dac",
156+
"fsmc",
157+
"gpiod", "gpioe", "gpiof", "gpiog", "gpioi",
158+
"i2c3",
159+
"otg-fs",
160+
"otg-hs",
161+
"rng",
162+
"sdio",
163+
"spi3",
164+
"usart3", "uart4", "uart5",
165+
]
166+
stm32f423 = ["stm32f4/stm32f413", "device-selected",
167+
"can1", "can2",
168+
"dac",
169+
"fsmc",
170+
"fmpi2c1",
171+
"gpiod", "gpioe", "gpiof", "gpiog",
172+
"i2c3",
173+
"otg-fs",
174+
"rng",
175+
"sdio",
176+
"spi3", "spi4", "spi5",
177+
"usart3", "uart4", "uart5", "uart7", "uart8", "uart9", "uart10",
178+
]
179+
stm32f427 = ["stm32f4/stm32f427", "device-selected",
180+
"adc2", "adc3",
181+
"can1", "can2",
182+
"dac",
183+
"fsmc",
184+
"gpiod", "gpioe", "gpiof", "gpiog", "gpioi", "gpioj", "gpiok",
185+
"i2c3",
186+
"otg-fs",
187+
"otg-hs",
188+
"rng",
189+
"sdio",
190+
"spi3", "spi4", "spi5", "spi6",
191+
"usart3", "uart4", "uart5", "uart7", "uart8",
192+
]
193+
stm32f429 = ["stm32f4/stm32f429", "device-selected",
194+
"adc2", "adc3",
195+
"can1", "can2",
196+
"dac",
197+
"fmc",
198+
"gpiod", "gpioe", "gpiof", "gpiog", "gpioi", "gpioj", "gpiok",
199+
"i2c3",
200+
"otg-fs",
201+
"otg-hs",
202+
"rng",
203+
"sdio",
204+
"spi3", "spi4", "spi5", "spi6",
205+
"usart3", "uart4", "uart5", "uart7", "uart8",
206+
]
207+
stm32f437 = ["stm32f4/stm32f427", "device-selected",
208+
"adc2", "adc3",
209+
"can1", "can2",
210+
"dac",
211+
"fsmc",
212+
"gpiod", "gpioe", "gpiof", "gpiog", "gpioi", "gpioj", "gpiok",
213+
"i2c3",
214+
"otg-fs",
215+
"otg-hs",
216+
"rng",
217+
"sdio",
218+
"spi3", "spi4", "spi5", "spi6",
219+
"usart3", "uart4", "uart5", "uart7", "uart8",
220+
]
221+
stm32f439 = ["stm32f4/stm32f429", "device-selected",
222+
"adc2", "adc3",
223+
"can1", "can2",
224+
"dac",
225+
"fmc",
226+
"gpiod", "gpioe", "gpiof", "gpiog", "gpioi", "gpioj", "gpiok",
227+
"i2c3",
228+
"otg-fs",
229+
"otg-hs",
230+
"rng",
231+
"sdio",
232+
"spi3", "spi4", "spi5", "spi6",
233+
"usart3", "uart4", "uart5", "uart7", "uart8",
234+
]
235+
stm32f446 = ["stm32f4/stm32f446", "device-selected",
236+
"adc2", "adc3",
237+
"can1", "can2",
238+
"dac",
239+
"fmc",
240+
"gpiod", "gpioe", "gpiof", "gpiog",
241+
"i2c3",
242+
"otg-fs",
243+
"otg-hs",
244+
"spi3", "spi4",
245+
"usart3", "uart4", "uart5",
246+
]
247+
stm32f469 = ["stm32f4/stm32f469", "device-selected",
248+
"adc2", "adc3",
249+
"can1", "can2",
250+
"dac",
251+
"fmc",
252+
"gpiod", "gpioe", "gpiof", "gpiog", "gpioi", "gpioj", "gpiok",
253+
"i2c3",
254+
"otg-fs",
255+
"otg-hs",
256+
"rng",
257+
"sdio",
258+
"spi3", "spi4", "spi5", "spi6",
259+
"usart3", "uart4", "uart5", "uart7", "uart8",
260+
]
261+
stm32f479 = ["stm32f4/stm32f469", "device-selected",
262+
"adc2", "adc3",
263+
"can1", "can2",
264+
"dac",
265+
"fmc",
266+
"gpiod", "gpioe", "gpiof", "gpiog", "gpioi", "gpioj", "gpiok",
267+
"i2c3",
268+
"otg-fs",
269+
"otg-hs",
270+
"rng",
271+
"sdio",
272+
"spi3", "spi4", "spi5", "spi6",
273+
"usart3", "uart4", "uart5", "uart7", "uart8",
274+
]
85275

86276
usb_fs = ["synopsys-usb-otg", "synopsys-usb-otg/fs"]
87277
usb_hs = ["synopsys-usb-otg", "synopsys-usb-otg/hs"]
88278

89279
can = ["bxcan"]
90280

91-
sdio = ["sdio-host"]
92-
93281
i2s = ["stm32_i2s_v12x"]
94282

95283
fsmc_lcd = ["display-interface"]
96284

285+
adc2 = []
286+
adc3 = []
287+
can1 = []
288+
can2 = []
289+
dac = []
290+
fmc = []
291+
fsmc = []
292+
fmpi2c1 = []
293+
gpiod = []
294+
gpioe = []
295+
gpiof = []
296+
gpiog = []
297+
gpioi = []
298+
gpioj = []
299+
gpiok = []
300+
i2c3 = []
301+
otg-fs = []
302+
otg-hs = []
303+
rng = []
304+
sdio = []
305+
spi3 = []
306+
spi4 = []
307+
spi5 = []
308+
spi6 = []
309+
usart3 = []
310+
uart4 = []
311+
uart5 = []
312+
uart7 = []
313+
uart8 = []
314+
uart9 = []
315+
uart10 = []
316+
97317
[profile.dev]
98318
debug = true
99319
lto = true
@@ -113,7 +333,7 @@ required-features = ["rt", "stm32f401", "usb_fs"]
113333

114334
[[example]]
115335
name = "sd"
116-
required-features = ["rt", "stm32f405", "sdio"]
336+
required-features = ["rt", "stm32f405", "sdio-host"]
117337

118338
[[example]]
119339
name = "delay-blinky"

src/adc.rs

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
*/
1010

1111
use crate::dma::traits::PeriAddress;
12-
use crate::{bb, gpio::*, pac, signature::VrefCal, signature::VDDA_CALIB};
12+
use crate::rcc::{Enable, Reset};
13+
use crate::{gpio::*, pac, signature::VrefCal, signature::VDDA_CALIB};
1314
use core::fmt;
1415
use embedded_hal::adc::{Channel, OneShot};
1516

@@ -700,20 +701,15 @@ macro_rules! adc {
700701
pub fn $constructor_fn_name(adc: pac::$adc_type, reset: bool, config: config::AdcConfig) -> Adc<pac::$adc_type> {
701702
unsafe {
702703
// All ADCs share the same reset interface.
703-
const RESET_BIT: u8 = 8;
704704
// NOTE(unsafe) this reference will only be used for atomic writes with no side effects.
705705
let rcc = &(*pac::RCC::ptr());
706706

707707
//Enable the clock
708-
bb::set(&rcc.apb2enr, $en_bit);
709-
710-
// Stall the pipeline to work around erratum 2.1.13 (DM00037591)
711-
cortex_m::asm::dsb();
708+
pac::$adc_type::enable(rcc);
712709

713710
if reset {
714711
//Reset the peripheral(s)
715-
bb::set(&rcc.apb2rstr, RESET_BIT);
716-
bb::clear(&rcc.apb2rstr, RESET_BIT);
712+
pac::$adc_type::reset(rcc);
717713
}
718714
}
719715

@@ -1044,25 +1040,6 @@ macro_rules! adc {
10441040
};
10451041
}
10461042

1047-
#[cfg(any(
1048-
feature = "stm32f401",
1049-
feature = "stm32f405",
1050-
feature = "stm32f415",
1051-
feature = "stm32f407",
1052-
feature = "stm32f417",
1053-
feature = "stm32f410",
1054-
feature = "stm32f411",
1055-
feature = "stm32f412",
1056-
feature = "stm32f413",
1057-
feature = "stm32f423",
1058-
feature = "stm32f427",
1059-
feature = "stm32f437",
1060-
feature = "stm32f429",
1061-
feature = "stm32f439",
1062-
feature = "stm32f446",
1063-
feature = "stm32f469",
1064-
feature = "stm32f479",
1065-
))]
10661043
adc!(ADC1 => (adc1, ADC_COMMON, 8));
10671044

10681045
#[cfg(any(

0 commit comments

Comments
 (0)