Skip to content

Commit 6f13445

Browse files
jessebrahamtherealprof
authored andcommitted
Add support for the STM32f091 (#35)
* Add GPIO support for the stm32f091 * Implement RCC, Serial and Timers for stm32f091 * Implement ADC, I2C and SPI for stm32f091 * Add STM32F091 to Travis config, CHANGELOG and README
1 parent 35abc7a commit 6f13445

File tree

12 files changed

+93
-31
lines changed

12 files changed

+93
-31
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ env:
1313
- MCU=stm32f070x6
1414
- MCU=stm32f070xb
1515
- MCU=stm32f072
16+
- MCU=stm32f091
1617
matrix:
1718
allow_failures:
1819
- rust: nightly

CHANGELOG.md

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

88
## [Unreleased]
99

10+
### Added
11+
12+
- Support for STM32F091 - @jessebraham
13+
1014
## [v0.11.1] - 2019-01-05
1115

1216
### Added

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ stm32f070 = ["stm32f0/stm32f0x0", "device-selected"]
5656
stm32f070x6 = ["stm32f070"]
5757
stm32f070xb = ["stm32f070"]
5858
stm32f072 = ["stm32f0/stm32f0x2", "device-selected"]
59+
stm32f091 = ["stm32f0/stm32f0x1", "device-selected"]
5960

6061
[profile.dev]
6162
debug = true

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Currently supported configuration are:
1919
* stm32f070x6
2020
* stm32f070xb
2121
* stm32f072
22+
* stm32f091
2223

2324
The idea behind this crate is to gloss over the slight differences in the
2425
various peripherals available on those MCUs so a HAL can be written for all

src/adc.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ adc_pins!(
219219
#[cfg(any(
220220
feature = "stm32f030",
221221
feature = "stm32f070",
222-
feature = "stm32f072"
222+
feature = "stm32f072",
223+
feature = "stm32f091"
223224
))]
224225
adc_pins!(
225226
gpioc::PC0<Analog> => 10_u8,
@@ -364,17 +365,17 @@ impl VRef {
364365
}
365366
}
366367

367-
#[cfg(any(feature = "stm32f042", feature = "stm32f072"))]
368+
#[cfg(any(feature = "stm32f042", feature = "stm32f072", feature = "stm32f091"))]
368369
#[derive(Debug, Default)]
369370
/// Battery reference voltage (ADC Channel 18)
370371
pub struct VBat;
371372

372-
#[cfg(any(feature = "stm32f042", feature = "stm32f072"))]
373+
#[cfg(any(feature = "stm32f042", feature = "stm32f072", feature = "stm32f091"))]
373374
adc_pins!(
374375
VBat => 18_u8,
375376
);
376377

377-
#[cfg(any(feature = "stm32f042", feature = "stm32f072"))]
378+
#[cfg(any(feature = "stm32f042", feature = "stm32f072", feature = "stm32f091"))]
378379
impl VBat {
379380
/// Init a new VBat
380381
pub fn new() -> Self {

src/gpio.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,8 @@ gpio!(GPIOC, gpioc, iopcen, PC, [
577577
#[cfg(any(
578578
feature = "stm32f030",
579579
feature = "stm32f070",
580-
feature = "stm32f072"
580+
feature = "stm32f072",
581+
feature = "stm32f091",
581582
))]
582583
gpio!(GPIOC, gpioc, iopcen, PC, [
583584
PC0: (pc0, 0, Input<Floating>),
@@ -598,15 +599,12 @@ gpio!(GPIOC, gpioc, iopcen, PC, [
598599
PC15: (pc15, 15, Input<Floating>),
599600
]);
600601

601-
#[cfg(any(
602-
feature = "stm32f030",
603-
feature = "stm32f070"
604-
))]
602+
#[cfg(any(feature = "stm32f030", feature = "stm32f070"))]
605603
gpio!(GPIOD, gpiod, iopden, PD, [
606604
PD2: (pd2, 2, Input<Floating>),
607605
]);
608606

609-
#[cfg(feature = "stm32f072")]
607+
#[cfg(any(feature = "stm32f072", feature = "stm32f091"))]
610608
gpio!(GPIOD, gpiod, iopden, PD, [
611609
PD0: (pd0, 0, Input<Floating>),
612610
PD1: (pd1, 1, Input<Floating>),
@@ -629,7 +627,7 @@ gpio!(GPIOD, gpiod, iopden, PD, [
629627
// TODO: The ST SVD files are missing the entire PE enable register.
630628
// Re-enable as soon as this gets fixed.
631629

632-
// #[cfg(feature = "stm32f072")]
630+
// #[cfg(any(feature = "stm32f072", feature = "stm32f091"))]
633631
// gpio!(GPIOE, gpioe, iopeen, PE, [
634632
// PE0: (pe0, 0, Input<Floating>),
635633
// PE1: (pe1, 1, Input<Floating>),
@@ -672,7 +670,7 @@ gpio!(GPIOF, gpiof, iopfen, PF, [
672670
PF1: (pf1, 1, Input<Floating>),
673671
]);
674672

675-
#[cfg(feature = "stm32f072")]
673+
#[cfg(any(feature = "stm32f072", feature = "stm32f091"))]
676674
gpio!(GPIOF, gpiof, iopfen, PF, [
677675
PF0: (pf0, 0, Input<Floating>),
678676
PF1: (pf1, 1, Input<Floating>),
@@ -681,4 +679,4 @@ gpio!(GPIOF, gpiof, iopfen, PF, [
681679
PF6: (pf6, 6, Input<Floating>),
682680
PF9: (pf9, 9, Input<Floating>),
683681
PF10: (pf10, 10, Input<Floating>),
684-
]);
682+
]);

src/i2c.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ i2c_pins! {
4848
feature = "stm32f030x6",
4949
feature = "stm32f030xc",
5050
feature = "stm32f042",
51+
feature = "stm32f091",
5152
))]
5253
i2c_pins! {
5354
I2C1 => {
@@ -69,7 +70,7 @@ i2c_pins! {
6970
sda => [gpiob::PB14<Alternate<AF5>>, gpiof::PF0<Alternate<AF1>>],
7071
}
7172
}
72-
#[cfg(any(feature = "stm32f070", feature = "stm32f072"))]
73+
#[cfg(any(feature = "stm32f070", feature = "stm32f072", feature = "stm32f091"))]
7374
i2c_pins! {
7475
I2C1 => {
7576
scl => [gpiob::PB6<Alternate<AF1>>, gpiob::PB8<Alternate<AF1>>],
@@ -83,6 +84,13 @@ i2c_pins! {
8384
sda => [gpioa::PA10<Alternate<AF4>>, gpiof::PF1<Alternate<AF1>>],
8485
}
8586
}
87+
#[cfg(feature = "stm32f091")]
88+
i2c_pins! {
89+
I2C1 => {
90+
scl => [gpiof::PF1<Alternate<AF1>>],
91+
sda => [gpiof::PF0<Alternate<AF1>>],
92+
}
93+
}
8694

8795
#[cfg(any(feature = "stm32f030x8"))]
8896
i2c_pins! {
@@ -91,13 +99,25 @@ i2c_pins! {
9199
sda => [gpiob::PB11<Alternate<AF1>>],
92100
}
93101
}
94-
#[cfg(any(feature = "stm32f030xc", feature = "stm32f070xb", feature = "stm32f072"))]
102+
#[cfg(any(
103+
feature = "stm32f030xc",
104+
feature = "stm32f070xb",
105+
feature = "stm32f072",
106+
feature = "stm32f091",
107+
))]
95108
i2c_pins! {
96109
I2C2 => {
97110
scl => [gpiob::PB10<Alternate<AF1>>, gpiob::PB13<Alternate<AF5>>],
98111
sda => [gpiob::PB11<Alternate<AF1>>, gpiob::PB14<Alternate<AF5>>],
99112
}
100113
}
114+
#[cfg(feature = "stm32f091")]
115+
i2c_pins! {
116+
I2C2 => {
117+
scl => [gpioa::PA11<Alternate<AF5>>],
118+
sda => [gpioa::PA12<Alternate<AF5>>],
119+
}
120+
}
101121

102122
#[derive(Debug)]
103123
pub enum Error {
@@ -142,7 +162,8 @@ i2c! {
142162
// XXX: This can't be right
143163
feature = "stm32f030xc",
144164
feature = "stm32f070xb",
145-
feature = "stm32f072"
165+
feature = "stm32f072",
166+
feature = "stm32f091",
146167
))]
147168
i2c! {
148169
I2C2: (i2c2, i2c2en, i2c2rst, apb1enr, apb1rstr),

src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33

44
pub use stm32f0;
55

6-
#[cfg(any(feature = "stm32f042", feature = "stm32f072"))]
7-
pub use stm32f0::stm32f0x2 as stm32;
8-
96
#[cfg(any(feature = "stm32f030", feature = "stm32f070"))]
107
pub use stm32f0::stm32f0x0 as stm32;
118

9+
#[cfg(feature = "stm32f091")]
10+
pub use stm32f0::stm32f0x1 as stm32;
11+
12+
#[cfg(any(feature = "stm32f042", feature = "stm32f072"))]
13+
pub use stm32f0::stm32f0x2 as stm32;
14+
1215
pub mod adc;
1316
pub mod delay;
1417
pub mod gpio;

src/rcc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl CFGR {
8787
self
8888
}
8989

90-
#[cfg(feature = "stm32f042")]
90+
#[cfg(any(feature = "stm32f042", feature = "stm32f091"))]
9191
pub fn enable_hsi48(mut self, is_enabled: bool) -> Self {
9292
self.enable_hsi48 = is_enabled;
9393
self

src/serial.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ usart_pins! {
9595
rx => [gpioa::PA3<Alternate<AF1>>, gpioa::PA15<Alternate<AF1>>],
9696
}
9797
}
98-
#[cfg(any(feature = "stm32f070", feature = "stm32f072"))]
98+
#[cfg(any(feature = "stm32f070", feature = "stm32f072", feature = "stm32f091"))]
9999
usart_pins! {
100100
USART1 => {
101101
tx => [gpioa::PA9<Alternate<AF1>>, gpiob::PB6<Alternate<AF0>>],
@@ -108,14 +108,15 @@ usart_pins! {
108108
feature = "stm32f042",
109109
feature = "stm32f070",
110110
feature = "stm32f072",
111+
feature = "stm32f091",
111112
))]
112113
usart_pins! {
113114
USART2 => {
114115
tx => [gpioa::PA2<Alternate<AF1>>, gpioa::PA14<Alternate<AF1>>],
115116
rx => [gpioa::PA3<Alternate<AF1>>, gpioa::PA15<Alternate<AF1>>],
116117
}
117118
}
118-
#[cfg(feature = "stm32f072")]
119+
#[cfg(any(feature = "stm32f072", feature = "stm32f091"))]
119120
usart_pins! {
120121
USART2 => {
121122
tx => [gpiod::PD5<Alternate<AF0>>],
@@ -125,7 +126,8 @@ usart_pins! {
125126
#[cfg(any(
126127
feature = "stm32f030xc",
127128
feature = "stm32f070xb",
128-
feature = "stm32f072"
129+
feature = "stm32f072",
130+
feature = "stm32f091",
129131
))]
130132
usart_pins! {
131133
USART3 => {
@@ -138,14 +140,23 @@ usart_pins! {
138140
rx => [gpioa::PA1<Alternate<AF4>>, gpioc::PC11<Alternate<AF0>>],
139141
}
140142
}
141-
#[cfg(feature = "stm32f072")]
143+
#[cfg(any(feature = "stm32f072", feature = "stm32f091"))]
142144
usart_pins! {
143145
USART3 => {
144146
tx => [gpiod::PD8<Alternate<AF0>>],
145147
rx => [gpiod::PD9<Alternate<AF0>>],
146148
}
147149
}
148-
#[cfg(feature = "stm32f030xc")]
150+
// TODO: The ST SVD files are missing the entire PE enable register.
151+
// Re-enable as soon as this gets fixed.
152+
// #[cfg(feature = "stm32f091")]
153+
// usart_pins! {
154+
// USART4 => {
155+
// tx => [gpioe::PE8<Alternate<AF1>>],
156+
// rx => [gpioe::PE9<Alternate<AF1>>],
157+
// }
158+
// }
159+
#[cfg(any(feature = "stm32f030xc", feature = "stm32f091"))]
149160
usart_pins! {
150161
USART5 => {
151162
tx => [gpiob::PB3<Alternate<AF4>>, gpioc::PC12<Alternate<AF2>>],
@@ -156,6 +167,19 @@ usart_pins! {
156167
rx => [gpioa::PA5<Alternate<AF5>>, gpioc::PC1<Alternate<AF2>>],
157168
}
158169
}
170+
// TODO: The ST SVD files are missing the entire PE enable register.
171+
// Re-enable as soon as this gets fixed.
172+
#[cfg(feature = "stm32f091")]
173+
usart_pins! {
174+
// USART5 => {
175+
// tx => [gpioe::PE10<Alternate<AF1>>],
176+
// rx => [gpioe::PE11<Alternate<AF1>>],
177+
// }
178+
USART6 => {
179+
tx => [gpiof::PF9<Alternate<AF1>>],
180+
rx => [gpiof::PF10<Alternate<AF1>>],
181+
}
182+
}
159183

160184
/// Serial abstraction
161185
#[allow(unused)]
@@ -260,6 +284,7 @@ usart! {
260284
feature = "stm32f042",
261285
feature = "stm32f070",
262286
feature = "stm32f072",
287+
feature = "stm32f091",
263288
))]
264289
usart! {
265290
USART2: (usart2, usart2en, apb1enr),
@@ -268,12 +293,13 @@ usart! {
268293
feature = "stm32f030xc",
269294
feature = "stm32f070xb",
270295
feature = "stm32f072",
296+
feature = "stm32f091",
271297
))]
272298
usart! {
273299
USART3: (usart3, usart3en, apb1enr),
274300
USART4: (usart4, usart4en, apb1enr),
275301
}
276-
#[cfg(feature = "stm32f030xc")]
302+
#[cfg(any(feature = "stm32f030xc", feature = "stm32f091"))]
277303
usart! {
278304
USART5: (usart5, usart5en, apb1enr),
279305
USART6: (usart6, usart6en, apb2enr),

0 commit comments

Comments
 (0)