Skip to content

Commit fc2e381

Browse files
authored
Merge pull request stm32-rs#43 from aurelj/all_devices
Add support for all existing stm32f4 devices
2 parents 4ebab3d + c4f0f62 commit fc2e381

File tree

5 files changed

+176
-72
lines changed

5 files changed

+176
-72
lines changed

src/gpio.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ macro_rules! gpio {
514514
}
515515
}
516516

517+
#[cfg(any(feature = "stm32f401", feature = "stm32f405", feature = "stm32f407", feature = "stm32f410", feature = "stm32f411", feature = "stm32f412", feature = "stm32f413", feature = "stm32f415", feature = "stm32f417", feature = "stm32f423", feature = "stm32f427", feature = "stm32f429", feature = "stm32f437", feature = "stm32f439", feature = "stm32f446", feature = "stm32f469", feature = "stm32f479"))]
517518
gpio!(GPIOA, gpioa, gpioaen, PA, [
518519
PA0: (pa0, 0, Input<Floating>),
519520
PA1: (pa1, 1, Input<Floating>),
@@ -533,6 +534,7 @@ gpio!(GPIOA, gpioa, gpioaen, PA, [
533534
PA15: (pa15, 15, Input<Floating>),
534535
]);
535536

537+
#[cfg(any(feature = "stm32f401", feature = "stm32f405", feature = "stm32f407", feature = "stm32f410", feature = "stm32f411", feature = "stm32f412", feature = "stm32f413", feature = "stm32f415", feature = "stm32f417", feature = "stm32f423", feature = "stm32f427", feature = "stm32f429", feature = "stm32f437", feature = "stm32f439", feature = "stm32f446", feature = "stm32f469", feature = "stm32f479"))]
536538
gpio!(GPIOB, gpiob, gpioben, PB, [
537539
PB0: (pb0, 0, Input<Floating>),
538540
PB1: (pb1, 1, Input<Floating>),
@@ -552,6 +554,7 @@ gpio!(GPIOB, gpiob, gpioben, PB, [
552554
PB15: (pb15, 15, Input<Floating>),
553555
]);
554556

557+
#[cfg(any(feature = "stm32f401", feature = "stm32f405", feature = "stm32f407", feature = "stm32f410", feature = "stm32f411", feature = "stm32f412", feature = "stm32f413", feature = "stm32f415", feature = "stm32f417", feature = "stm32f423", feature = "stm32f427", feature = "stm32f429", feature = "stm32f437", feature = "stm32f439", feature = "stm32f446", feature = "stm32f469", feature = "stm32f479"))]
555558
gpio!(GPIOC, gpioc, gpiocen, PC, [
556559
PC0: (pc0, 0, Input<Floating>),
557560
PC1: (pc1, 1, Input<Floating>),
@@ -571,6 +574,7 @@ gpio!(GPIOC, gpioc, gpiocen, PC, [
571574
PC15: (pc15, 15, Input<Floating>),
572575
]);
573576

577+
#[cfg(any(feature = "stm32f401", feature = "stm32f405", feature = "stm32f407", feature = "stm32f411", feature = "stm32f412", feature = "stm32f413", feature = "stm32f415", feature = "stm32f417", feature = "stm32f423", feature = "stm32f427", feature = "stm32f429", feature = "stm32f437", feature = "stm32f439", feature = "stm32f446", feature = "stm32f469", feature = "stm32f479"))]
574578
gpio!(GPIOD, gpiod, gpioden, PD, [
575579
PD0: (pd0, 0, Input<Floating>),
576580
PD1: (pd1, 1, Input<Floating>),
@@ -590,6 +594,7 @@ gpio!(GPIOD, gpiod, gpioden, PD, [
590594
PD15: (pd15, 15, Input<Floating>),
591595
]);
592596

597+
#[cfg(any(feature = "stm32f401", feature = "stm32f405", feature = "stm32f407", feature = "stm32f411", feature = "stm32f412", feature = "stm32f413", feature = "stm32f415", feature = "stm32f417", feature = "stm32f423", feature = "stm32f427", feature = "stm32f429", feature = "stm32f437", feature = "stm32f439", feature = "stm32f446", feature = "stm32f469", feature = "stm32f479"))]
593598
gpio!(GPIOE, gpioe, gpioeen, PE, [
594599
PE0: (pe0, 0, Input<Floating>),
595600
PE1: (pe1, 1, Input<Floating>),
@@ -609,7 +614,7 @@ gpio!(GPIOE, gpioe, gpioeen, PE, [
609614
PE15: (pe15, 15, Input<Floating>),
610615
]);
611616

612-
#[cfg(any(feature = "stm32f407", feature = "stm32f412", feature = "stm32f429"))]
617+
#[cfg(any(feature = "stm32f405", feature = "stm32f407", feature = "stm32f412", feature = "stm32f413", feature = "stm32f415", feature = "stm32f417", feature = "stm32f423", feature = "stm32f427", feature = "stm32f429", feature = "stm32f437", feature = "stm32f439", feature = "stm32f446", feature = "stm32f469", feature = "stm32f479"))]
613618
gpio!(GPIOF, gpiof, gpiofen, PF, [
614619
PF0: (pf0, 0, Input<Floating>),
615620
PF1: (pf1, 1, Input<Floating>),
@@ -629,7 +634,7 @@ gpio!(GPIOF, gpiof, gpiofen, PF, [
629634
PF15: (pf15, 15, Input<Floating>),
630635
]);
631636

632-
#[cfg(any(feature = "stm32f407", feature = "stm32f412", feature = "stm32f429"))]
637+
#[cfg(any(feature = "stm32f405", feature = "stm32f407", feature = "stm32f412", feature = "stm32f413", feature = "stm32f415", feature = "stm32f417", feature = "stm32f423", feature = "stm32f427", feature = "stm32f429", feature = "stm32f437", feature = "stm32f439", feature = "stm32f446", feature = "stm32f469", feature = "stm32f479"))]
633638
gpio!(GPIOG, gpiog, gpiogen, PG, [
634639
PG0: (pg0, 0, Input<Floating>),
635640
PG1: (pg1, 1, Input<Floating>),
@@ -649,7 +654,7 @@ gpio!(GPIOG, gpiog, gpiogen, PG, [
649654
PG15: (pg15, 15, Input<Floating>),
650655
]);
651656

652-
#[cfg(any(feature = "stm32f407", feature = "stm32f412", feature = "stm32f429", feature = "stm32f411"))]
657+
#[cfg(any(feature = "stm32f405", feature = "stm32f407", feature = "stm32f410", feature = "stm32f411", feature = "stm32f412", feature = "stm32f413", feature = "stm32f415", feature = "stm32f417", feature = "stm32f423", feature = "stm32f427", feature = "stm32f429", feature = "stm32f437", feature = "stm32f439", feature = "stm32f446", feature = "stm32f469", feature = "stm32f479"))]
653658
gpio!(GPIOH, gpioh, gpiohen, PH, [
654659
PH0: (ph0, 0, Input<Floating>),
655660
PH1: (ph1, 1, Input<Floating>),
@@ -675,7 +680,7 @@ gpio!(GPIOH, gpioh, gpiohen, PH, [
675680
PH1: (ph1, 1, Input<Floating>),
676681
]);
677682

678-
#[cfg(any(feature = "stm32f407", feature = "stm32f429"))]
683+
#[cfg(any(feature = "stm32f405", feature = "stm32f407", feature = "stm32f415", feature = "stm32f417", feature = "stm32f427", feature = "stm32f429", feature = "stm32f437", feature = "stm32f439", feature = "stm32f469", feature = "stm32f479"))]
679684
gpio!(GPIOI, gpioi, gpioien, PI, [
680685
PI0: (pi0, 0, Input<Floating>),
681686
PI1: (pi1, 1, Input<Floating>),

src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ pub use stm32f4::stm32f411 as stm32;
3131
#[cfg(feature = "rt")]
3232
pub use stm32f4::interrupt;
3333

34-
#[cfg(any(feature = "stm32f401", feature = "stm32f407", feature = "stm32f412", feature = "stm32f429", feature = "stm32f411"))]
34+
#[cfg(any(feature = "stm32f401", feature = "stm32f405", feature = "stm32f407", feature = "stm32f410", feature = "stm32f411", feature = "stm32f412", feature = "stm32f413", feature = "stm32f415", feature = "stm32f417", feature = "stm32f423", feature = "stm32f427", feature = "stm32f429", feature = "stm32f437", feature = "stm32f439", feature = "stm32f446", feature = "stm32f469", feature = "stm32f479"))]
3535
pub mod delay;
36-
#[cfg(any(feature = "stm32f401", feature = "stm32f407", feature = "stm32f412", feature = "stm32f429", feature = "stm32f411"))]
36+
#[cfg(any(feature = "stm32f401", feature = "stm32f405", feature = "stm32f407", feature = "stm32f410", feature = "stm32f411", feature = "stm32f412", feature = "stm32f413", feature = "stm32f415", feature = "stm32f417", feature = "stm32f423", feature = "stm32f427", feature = "stm32f429", feature = "stm32f437", feature = "stm32f439", feature = "stm32f446", feature = "stm32f469", feature = "stm32f479"))]
3737
pub mod gpio;
3838
#[cfg(any(feature = "stm32f401", feature = "stm32f407", feature = "stm32f412", feature = "stm32f429", feature = "stm32f411"))]
3939
pub mod i2c;
4040
#[cfg(any(feature = "stm32f401", feature = "stm32f407", feature = "stm32f412", feature = "stm32f429", feature = "stm32f411"))]
4141
pub mod prelude;
42-
#[cfg(any(feature = "stm32f401", feature = "stm32f407", feature = "stm32f412", feature = "stm32f429", feature = "stm32f411"))]
42+
#[cfg(any(feature = "stm32f401", feature = "stm32f405", feature = "stm32f407", feature = "stm32f410", feature = "stm32f411", feature = "stm32f412", feature = "stm32f413", feature = "stm32f415", feature = "stm32f417", feature = "stm32f423", feature = "stm32f427", feature = "stm32f429", feature = "stm32f437", feature = "stm32f439", feature = "stm32f446", feature = "stm32f469", feature = "stm32f479"))]
4343
pub mod rcc;
4444
#[cfg(any(feature = "stm32f401", feature = "stm32f407", feature = "stm32f412", feature = "stm32f429", feature = "stm32f411"))]
4545
pub mod serial;
46-
#[cfg(any(feature = "stm32f401", feature = "stm32f407", feature = "stm32f412", feature = "stm32f429", feature = "stm32f411"))]
46+
#[cfg(any(feature = "stm32f401", feature = "stm32f405", feature = "stm32f407", feature = "stm32f410", feature = "stm32f411", feature = "stm32f412", feature = "stm32f413", feature = "stm32f415", feature = "stm32f417", feature = "stm32f423", feature = "stm32f427", feature = "stm32f429", feature = "stm32f437", feature = "stm32f439", feature = "stm32f446", feature = "stm32f469", feature = "stm32f479"))]
4747
pub mod spi;
4848
pub mod time;
49-
#[cfg(any(feature = "stm32f401", feature = "stm32f407", feature = "stm32f412", feature = "stm32f429", feature = "stm32f411"))]
49+
#[cfg(any(feature = "stm32f401", feature = "stm32f405", feature = "stm32f407", feature = "stm32f410", feature = "stm32f411", feature = "stm32f412", feature = "stm32f413", feature = "stm32f415", feature = "stm32f417", feature = "stm32f423", feature = "stm32f427", feature = "stm32f429", feature = "stm32f437", feature = "stm32f439", feature = "stm32f446", feature = "stm32f469", feature = "stm32f479"))]
5050
pub mod timer;

src/rcc.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,22 @@ impl CFGR {
114114
sysclk: Hertz(sysclk),
115115
}
116116
} else {
117-
#[cfg(any(feature = "stm32f401", feature = "stm32f407", feature = "stm32f411", feature = "stm32f412", feature = "stm32f429"))]
117+
#[cfg(any(feature = "stm32f401", feature = "stm32f405", feature = "stm32f407", feature = "stm32f410", feature = "stm32f411", feature = "stm32f412", feature = "stm32f413", feature = "stm32f415", feature = "stm32f417", feature = "stm32f423", feature = "stm32f427", feature = "stm32f429", feature = "stm32f437", feature = "stm32f439", feature = "stm32f469", feature = "stm32f479"))]
118118
let sysclk_min = 24_000_000;
119119

120+
#[cfg(any(feature = "stm32f446"))]
121+
let sysclk_min = 12_500_000;
122+
120123
#[cfg(feature = "stm32f401")]
121124
let sysclk_max = 84_000_000;
122125

123-
#[cfg(feature = "stm32f407")]
126+
#[cfg(any(feature = "stm32f405", feature = "stm32f407", feature = "stm32f415", feature = "stm32f417"))]
124127
let sysclk_max = 168_000_000;
125128

126-
#[cfg(any(feature = "stm32f412", feature = "stm32f411"))]
129+
#[cfg(any(feature = "stm32f410", feature = "stm32f411", feature = "stm32f412", feature = "stm32f413", feature = "stm32f423"))]
127130
let sysclk_max = 100_000_000;
128-
129-
#[cfg(feature = "stm32f429")]
131+
132+
#[cfg(any(feature = "stm32f427", feature = "stm32f429", feature = "stm32f437", feature = "stm32f439", feature = "stm32f446", feature = "stm32f469", feature = "stm32f479"))]
130133
let sysclk_max = 180_000_000;
131134

132135
assert!(sysclk <= sysclk_max && sysclk >= sysclk_min);
@@ -161,10 +164,16 @@ impl CFGR {
161164
let pclk1 = hclk / ppre1 as u32;
162165
let pclk2 = hclk / ppre2 as u32;
163166

167+
#[cfg(any(feature = "stm32f401", feature = "stm32f405", feature = "stm32f407", feature = "stm32f410", feature = "stm32f411", feature = "stm32f412", feature = "stm32f415", feature = "stm32f417", feature = "stm32f427", feature = "stm32f429", feature = "stm32f437", feature = "stm32f439", feature = "stm32f446", feature = "stm32f469", feature = "stm32f479"))]
168+
let flash_latency_step = 30_000_000;
169+
170+
#[cfg(any(feature = "stm32f413", feature = "stm32f423"))]
171+
let flash_latency_step = 25_000_000;
172+
164173
// Adjust flash wait states
165174
unsafe {
166175
flash.acr.modify(|_, w| {
167-
w.latency().bits(((sysclk - 1) / 30_000_000) as u8)
176+
w.latency().bits(((sysclk - 1) / flash_latency_step) as u8)
168177
})
169178
}
170179

0 commit comments

Comments
 (0)