Skip to content

Commit 5af487e

Browse files
authored
Merge pull request #9 from jessebraham/stm32f070-support
Add initial STM32F070 support
2 parents a959593 + 982b503 commit 5af487e

File tree

8 files changed

+56
-22
lines changed

8 files changed

+56
-22
lines changed

.travis.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ rust:
44
- nightly
55
cache: cargo
66
env:
7-
- MCU=stm32f042
8-
- MCU=stm32f030
9-
- MCU=stm32f030x6
10-
- MCU=stm32f030x8
11-
- MCU=stm32f030xc
7+
- MCU=stm32f042
8+
- MCU=stm32f030
9+
- MCU=stm32f030x6
10+
- MCU=stm32f030x8
11+
- MCU=stm32f030xc
12+
- MCU=stm32f070
13+
- MCU=stm32f070x6
14+
- MCU=stm32f070xb
1215
matrix:
1316
allow_failures:
1417
- rust: nightly

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ stm32f030x4 = ["stm32f030x6"]
5353
stm32f030x6 = ["stm32f030"]
5454
stm32f030x8 = ["stm32f030"]
5555
stm32f030xc = ["stm32f030"]
56+
stm32f070 = ["stm32f0/stm32f0x0"]
57+
stm32f070x6 = ["stm32f070"]
58+
stm32f070xb = ["stm32f070"]
5659

5760
[profile.dev]
5861
debug = true

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Currently supported configuration are:
1212
* stm32f030x6
1313
* stm32f030x8
1414
* stm32f030xc
15+
* stm32f070
16+
* stm32f070x6
17+
* stm32f070xb
1518

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

src/gpio.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ macro_rules! gpio {
497497
}
498498
}
499499

500-
#[cfg(any(feature = "stm32f042", feature = "stm32f030",))]
500+
#[cfg(any(feature = "stm32f042", feature = "stm32f030", feature = "stm32f070"))]
501501
gpio!(GPIOA, gpioa, iopaen, PA, [
502502
PA0: (pa0, 0, Input<Floating>),
503503
PA1: (pa1, 1, Input<Floating>),
@@ -517,7 +517,7 @@ gpio!(GPIOA, gpioa, iopaen, PA, [
517517
PA15: (pa15, 15, Input<Floating>),
518518
]);
519519

520-
#[cfg(any(feature = "stm32f042", feature = "stm32f030"))]
520+
#[cfg(any(feature = "stm32f042", feature = "stm32f030", feature = "stm32f070"))]
521521
gpio!(GPIOB, gpiob, iopben, PB, [
522522
PB0: (pb0, 0, Input<Floating>),
523523
PB1: (pb1, 1, Input<Floating>),
@@ -544,7 +544,7 @@ gpio!(GPIOC, gpioc, iopcen, PC, [
544544
PC15: (pc15, 15, Input<Floating>),
545545
]);
546546

547-
#[cfg(feature = "stm32f030")]
547+
#[cfg(any(feature = "stm32f030", feature = "stm32f070"))]
548548
gpio!(GPIOC, gpioc, iopcen, PC, [
549549
PC0: (pb0, 0, Input<Floating>),
550550
PC1: (pb1, 1, Input<Floating>),
@@ -564,7 +564,7 @@ gpio!(GPIOC, gpioc, iopcen, PC, [
564564
PC15: (pb15, 15, Input<Floating>),
565565
]);
566566

567-
#[cfg(feature = "stm32f030")]
567+
#[cfg(any(feature = "stm32f030", feature = "stm32f070"))]
568568
gpio!(GPIOD, gpiod, iopden, PD, [
569569
PD2: (pd2, 2, Input<Floating>),
570570
]);
@@ -585,3 +585,9 @@ gpio!(GPIOF, gpiof, iopfen, PF, [
585585
PF6: (pf6, 5, Input<Floating>),
586586
PF7: (pf7, 5, Input<Floating>),
587587
]);
588+
589+
#[cfg(feature = "stm32f070")]
590+
gpio!(GPIOF, gpiof, iopfen, PF, [
591+
PF0: (pf0, 0, Input<Floating>),
592+
PF1: (pf1, 1, Input<Floating>),
593+
]);

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub use stm32f0;
66
#[cfg(feature = "stm32f042")]
77
pub use stm32f0::stm32f0x2 as stm32;
88

9-
#[cfg(feature = "stm32f030")]
9+
#[cfg(any(feature = "stm32f030", feature = "stm32f070"))]
1010
pub use stm32f0::stm32f0x0 as stm32;
1111

1212
pub mod delay;

src/rcc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use core::cmp;
22

3-
use cast::u32;
4-
#[cfg(any(feature = "stm32f042", feature = "stm32f030"))]
3+
#[cfg(any(feature = "stm32f042", feature = "stm32f030", feature = "stm32f070"))]
54
use crate::stm32::{FLASH, RCC};
5+
use cast::u32;
66

77
use crate::time::Hertz;
88

@@ -12,7 +12,7 @@ pub trait RccExt {
1212
fn constrain(self) -> Rcc;
1313
}
1414

15-
#[cfg(any(feature = "stm32f042", feature = "stm32f030"))]
15+
#[cfg(any(feature = "stm32f042", feature = "stm32f030", feature = "stm32f070"))]
1616
impl RccExt for RCC {
1717
fn constrain(self) -> Rcc {
1818
Rcc {
@@ -38,7 +38,7 @@ pub struct CFGR {
3838
sysclk: Option<u32>,
3939
}
4040

41-
#[cfg(any(feature = "stm32f042", feature = "stm32f030"))]
41+
#[cfg(any(feature = "stm32f042", feature = "stm32f030", feature = "stm32f070"))]
4242
impl CFGR {
4343
pub fn hclk<F>(mut self, freq: F) -> Self
4444
where

src/serial.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use embedded_hal::prelude::*;
3131
use nb::block;
3232
use void::Void;
3333

34-
#[cfg(any(feature = "stm32f042", feature = "stm32f030"))]
34+
#[cfg(any(feature = "stm32f042", feature = "stm32f030", feature = "stm32f070"))]
3535
use crate::stm32;
3636

3737
use crate::gpio::*;
@@ -94,18 +94,26 @@ usart_pins! {
9494
rx => [gpioa::PA3<Alternate<AF1>>, gpioa::PA15<Alternate<AF1>>],
9595
}
9696
}
97+
#[cfg(feature = "stm32f070")]
98+
usart_pins! {
99+
USART1 => {
100+
tx => [gpioa::PA9<Alternate<AF1>>, gpiob::PB6<Alternate<AF0>>],
101+
rx => [gpioa::PA10<Alternate<AF1>>, gpiob::PB7<Alternate<AF0>>],
102+
}
103+
}
97104
#[cfg(any(
98105
feature = "stm32f042",
99106
feature = "stm32f030x8",
100107
feature = "stm32f030xc",
108+
feature = "stm32f070",
101109
))]
102110
usart_pins! {
103111
USART2 => {
104112
tx => [gpioa::PA2<Alternate<AF1>>, gpioa::PA14<Alternate<AF1>>],
105113
rx => [gpioa::PA3<Alternate<AF1>>, gpioa::PA15<Alternate<AF1>>],
106114
}
107115
}
108-
#[cfg(feature = "stm32f030xc")]
116+
#[cfg(any(feature = "stm32f030xc", feature = "stm32f070xb"))]
109117
usart_pins! {
110118
USART3 => {
111119
// According to the datasheet PB10 is both tx and rx, but in stm32cubemx it's only tx
@@ -116,6 +124,9 @@ usart_pins! {
116124
tx => [gpioa::PA0<Alternate<AF4>>, gpioc::PC10<Alternate<AF0>>],
117125
rx => [gpioa::PA1<Alternate<AF4>>, gpioc::PC11<Alternate<AF0>>],
118126
}
127+
}
128+
#[cfg(feature = "stm32f030xc")]
129+
usart_pins! {
119130
USART5 => {
120131
tx => [gpiob::PB3<Alternate<AF4>>, gpioc::PC12<Alternate<AF2>>],
121132
rx => [gpiob::PB4<Alternate<AF4>>, gpiod::PD2<Alternate<AF2>>],
@@ -179,22 +190,26 @@ macro_rules! usart {
179190
}
180191
}
181192

182-
#[cfg(any(feature = "stm32f042", feature = "stm32f030"))]
193+
#[cfg(any(feature = "stm32f042", feature = "stm32f030", feature = "stm32f070"))]
183194
usart! {
184195
USART1: (usart1, usart1en, apb2enr),
185196
}
186197
#[cfg(any(
187198
feature = "stm32f042",
188199
feature = "stm32f030x8",
189-
feature = "stm32f030xc"
200+
feature = "stm32f030xc",
201+
feature = "stm32f070",
190202
))]
191203
usart! {
192204
USART2: (usart2, usart2en, apb1enr),
193205
}
194-
#[cfg(any(feature = "stm32f030xc"))]
206+
#[cfg(any(feature = "stm32f030xc", feature = "stm32f070xb"))]
195207
usart! {
196208
USART3: (usart3, usart3en, apb1enr),
197209
USART4: (usart4, usart4en, apb1enr),
210+
}
211+
#[cfg(feature = "stm32f030xc")]
212+
usart! {
198213
USART5: (usart5, usart5en, apb1enr),
199214
USART6: (usart6, usart6en, apb2enr),
200215
}

src/timers.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ macro_rules! timers {
209209
}
210210
}
211211

212-
#[cfg(any(feature = "stm32f030", feature = "stm32f042",))]
212+
#[cfg(any(feature = "stm32f030", feature = "stm32f042", feature = "stm32f070"))]
213213
timers! {
214214
TIM1: (tim1, tim1en, tim1rst, apb2enr, apb2rstr),
215215
TIM3: (tim3, tim3en, tim3rst, apb1enr, apb1rstr),
@@ -218,13 +218,17 @@ timers! {
218218
TIM17: (tim17, tim17en, tim17rst, apb2enr, apb2rstr),
219219
}
220220

221-
#[cfg(any(feature = "stm32f030x8", feature = "stm32f030xc"))]
221+
#[cfg(any(
222+
feature = "stm32f030x8",
223+
feature = "stm32f030xc",
224+
feature = "stm32f070xb",
225+
))]
222226
timers! {
223227
TIM6: (tim6, tim6en, tim6rst, apb1enr, apb1rstr),
224228
TIM15: (tim15, tim15en, tim15rst, apb2enr, apb2rstr),
225229
}
226230

227-
#[cfg(feature = "stm32f030xc")]
231+
#[cfg(any(feature = "stm32f030xc", feature = "stm32f070xb"))]
228232
timers! {
229233
TIM7: (tim7, tim7en, tim7rst, apb1enr, apb1rstr),
230234
}

0 commit comments

Comments
 (0)