Skip to content

Commit b56040d

Browse files
authored
Merge pull request #16 from jessebraham/stm32f070-peripherals
Add SPI and I2C support for STM32F070 devices
2 parents 5af487e + a075397 commit b56040d

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

src/i2c.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,32 @@ i2c_pins! {
6464
sda => [gpiob::PB14<Alternate<AF5>>, gpiof::PF0<Alternate<AF1>>],
6565
}
6666
}
67-
#[cfg(any(feature = "stm32f030x8", feature = "stm32f030xc"))]
67+
#[cfg(feature = "stm32f070")]
68+
i2c_pins! {
69+
I2C1 => {
70+
scl => [gpiob::PB6<Alternate<AF1>>, gpiob::PB8<Alternate<AF1>>],
71+
sda => [gpiob::PB7<Alternate<AF1>>, gpiob::PB9<Alternate<AF1>>],
72+
}
73+
}
74+
#[cfg(feature = "stm32f070x6")]
75+
i2c_pins! {
76+
I2C1 => {
77+
scl => [gpioa::PA9<Alternate<AF4>>, gpiof::PF0<Alternate<AF1>>],
78+
sda => [gpioa::PA10<Alternate<AF4>>, gpiof::PF1<Alternate<AF1>>],
79+
}
80+
}
81+
#[cfg(any(
82+
feature = "stm32f030x8",
83+
feature = "stm32f030xc",
84+
feature = "stm32f070xb"
85+
))]
6886
i2c_pins! {
6987
I2C2 => {
7088
scl => [gpiob::PB10<Alternate<AF1>>],
7189
sda => [gpiob::PB11<Alternate<AF1>>],
7290
}
7391
}
74-
#[cfg(feature = "stm32f030xc")]
92+
#[cfg(any(feature = "stm32f030xc", feature = "stm32f070xb"))]
7593
i2c_pins! {
7694
I2C2 => {
7795
scl => [gpiob::PB13<Alternate<AF5>>],
@@ -110,11 +128,15 @@ macro_rules! i2c {
110128
)+
111129
}
112130
}
113-
#[cfg(any(feature = "stm32f042", feature = "stm32f030"))]
131+
#[cfg(any(feature = "stm32f042", feature = "stm32f030", feature = "stm32f070"))]
114132
i2c! {
115133
I2C1: (i2c1, i2c1en, i2c1rst, apb1enr, apb1rstr),
116134
}
117-
#[cfg(any(feature = "stm32f030xc", feature = "stm32f030xc"))]
135+
#[cfg(any(
136+
feature = "stm32f030xc",
137+
feature = "stm32f030xc",
138+
feature = "stm32f070xb"
139+
))]
118140
i2c! {
119141
I2C2: (i2c2, i2c2en, i2c2rst, apb1enr, apb1rstr),
120142
}

src/spi.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ pub use embedded_hal::spi::{Mode, Phase, Polarity};
88
use crate::stm32;
99
// TODO Put this inside the macro
1010
// Currently that causes a compiler panic
11-
#[cfg(any(feature = "stm32f042", feature = "stm32f030"))]
11+
#[cfg(any(feature = "stm32f042", feature = "stm32f030", feature = "stm32f070"))]
1212
use crate::stm32::SPI1;
13-
#[cfg(any(feature = "stm32f030x8", feature = "stm32f030xc"))]
13+
#[cfg(any(
14+
feature = "stm32f030x8",
15+
feature = "stm32f030xc",
16+
feature = "stm32f070xb"
17+
))]
1418
use crate::stm32::SPI2;
1519

1620
use crate::gpio::*;
@@ -60,7 +64,7 @@ macro_rules! spi_pins {
6064
}
6165
}
6266

63-
#[cfg(any(feature = "stm32f042", feature = "stm32f030"))]
67+
#[cfg(any(feature = "stm32f042", feature = "stm32f030", feature = "stm32f070"))]
6468
spi_pins! {
6569
SPI1 => {
6670
sck => [gpioa::PA5<Alternate<AF0>>, gpiob::PB3<Alternate<AF0>>],
@@ -76,15 +80,19 @@ spi_pins! {
7680
mosi => [gpiob::PB15<Alternate<AF0>>],
7781
}
7882
}
79-
#[cfg(any(feature = "stm32f030x8", feature = "stm32f030xc"))]
83+
#[cfg(any(
84+
feature = "stm32f030x8",
85+
feature = "stm32f030xc",
86+
feature = "stm32f070xb"
87+
))]
8088
spi_pins! {
8189
SPI2 => {
8290
sck => [gpiob::PB13<Alternate<AF0>>],
8391
miso => [gpiob::PB14<Alternate<AF0>>],
8492
mosi => [gpiob::PB15<Alternate<AF0>>],
8593
}
8694
}
87-
#[cfg(feature = "stm32f030xc")]
95+
#[cfg(any(feature = "stm32f030xc", feature = "stm32f070xb"))]
8896
spi_pins! {
8997
SPI2 => {
9098
sck => [gpiob::PB10<Alternate<AF5>>],
@@ -126,11 +134,15 @@ macro_rules! spi {
126134
}
127135
}
128136

129-
#[cfg(any(feature = "stm32f042", feature = "stm32f030"))]
137+
#[cfg(any(feature = "stm32f042", feature = "stm32f030", feature = "stm32f070"))]
130138
spi! {
131139
SPI1: (spi1, spi1en, spi1rst, apb2enr, apb2rstr),
132140
}
133-
#[cfg(any(feature = "stm32f030x8", feature = "stm32f030xc"))]
141+
#[cfg(any(
142+
feature = "stm32f030x8",
143+
feature = "stm32f030xc",
144+
feature = "stm32f070xb"
145+
))]
134146
spi! {
135147
SPI2: (spi2, spi2en, spi2rst, apb1enr, apb1rstr),
136148
}

0 commit comments

Comments
 (0)