Skip to content

Commit e156201

Browse files
danielgallagher0Sh3Rm4n
authored andcommitted
Update SPI impls for STM32F303 family
Based on the datasheets for the 303x6/8, 303xb/c, and 303xd/e, the following pins and peripherals are supported: - SPI1 (6/8, b/c, and d/e): - SCK: PA5<AF5>, PB3<AF5> - MISO: PA6<AF5>, PB4<AF5> - MOSI: PA7<AF5>, PB5<AF5> - SPI2 (b/c and d/e): - SCK: PB13<AF5>, PF9<AF5>, PF10<AF5> - MISO: PB14<AF5> - MOSI: PB15<AF5> - Additional SPI2 Pin options (d/e only): - SCK: PF1<AF5> - MISO: PA10<AF5> - MOSI: PA11<AF5> - SPI3 (b/c and d/e): - SCK: PC10<AF6> - MISO: PC11<AF6> - MOSI: PC12<AF6> - Additional SPI3 Pin options (d/e only): - SCK: PB3<AF6> - MISO: PB4<AF6> - MOSI: PB5<AF6> - SPI4 (d/e only): - SCK: PE2<AF5>, PE12<AF5> - MISO: PE5<AF5>, PE13<AF5> - MOSI: PE6<AF5>, PE14<AF5>
1 parent 9f8128e commit e156201

File tree

1 file changed

+41
-66
lines changed

1 file changed

+41
-66
lines changed

src/spi.rs

Lines changed: 41 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,12 @@ use crate::pac::{
99
SPI1, SPI2, SPI3,
1010
};
1111
use crate::stm32::spi1;
12-
#[cfg(any(
13-
feature = "stm32f303xb",
14-
feature = "stm32f303xc",
15-
feature = "stm32f303xd",
16-
feature = "stm32f303xe"
17-
))]
12+
13+
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
1814
use crate::stm32::SPI4;
1915
use nb;
2016

21-
#[cfg(feature = "stm32f303")]
17+
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
2218
use crate::gpio::gpioa::{PA10, PA11};
2319
use crate::gpio::gpioa::{PA5, PA6, PA7};
2420
#[cfg(any(
@@ -36,26 +32,26 @@ use crate::gpio::gpiob::{PB14, PB15, PB5};
3632
#[cfg(feature = "stm32f303")]
3733
use crate::gpio::gpiob::{PB3, PB4};
3834
use crate::gpio::gpioc::{PC10, PC11, PC12};
39-
#[cfg(any(
40-
feature = "stm32f303xb",
41-
feature = "stm32f303xc",
42-
feature = "stm32f303xd",
43-
feature = "stm32f303xe"
44-
))]
35+
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
4536
use crate::gpio::gpioe::{PE12, PE13, PE14, PE2, PE5, PE6};
37+
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
38+
use crate::gpio::gpiof::PF1;
4639
#[cfg(any(
4740
feature = "stm32f303xb",
4841
feature = "stm32f303xc",
4942
feature = "stm32f303xd",
5043
feature = "stm32f303xe"
5144
))]
52-
use crate::gpio::gpiof::{PF1, PF10, PF9};
45+
use crate::gpio::gpiof::{PF10, PF9};
5346
use crate::gpio::{AF5, AF6};
5447
use crate::rcc::Clocks;
5548
#[cfg(any(
5649
feature = "stm32f301",
5750
feature = "stm32f302",
58-
feature = "stm32f303",
51+
feature = "stm32f303xb",
52+
feature = "stm32f303xc",
53+
feature = "stm32f303xd",
54+
feature = "stm32f303xe",
5955
feature = "stm32f318",
6056
feature = "stm32f328",
6157
feature = "stm32f358",
@@ -115,12 +111,7 @@ unsafe impl SckPin<SPI1> for PB3<AF5> {}
115111
feature = "stm32f398"
116112
))]
117113
unsafe impl SckPin<SPI2> for PB13<AF5> {}
118-
#[cfg(any(
119-
feature = "stm32f303xb",
120-
feature = "stm32f303xc",
121-
feature = "stm32f303xd",
122-
feature = "stm32f303xe"
123-
))]
114+
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
124115
unsafe impl SckPin<SPI2> for PF1<AF5> {}
125116
#[cfg(any(
126117
feature = "stm32f303xb",
@@ -137,75 +128,45 @@ unsafe impl SckPin<SPI2> for PF9<AF5> {}
137128
))]
138129
unsafe impl SckPin<SPI2> for PF10<AF5> {}
139130

140-
#[cfg(feature = "stm32f303")]
131+
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
141132
unsafe impl SckPin<SPI3> for PB3<AF6> {}
142133
unsafe impl SckPin<SPI3> for PC10<AF6> {}
143134

144-
#[cfg(any(
145-
feature = "stm32f303xb",
146-
feature = "stm32f303xc",
147-
feature = "stm32f303xd",
148-
feature = "stm32f303xe"
149-
))]
135+
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
150136
unsafe impl SckPin<SPI4> for PE2<AF5> {}
151-
#[cfg(any(
152-
feature = "stm32f303xb",
153-
feature = "stm32f303xc",
154-
feature = "stm32f303xd",
155-
feature = "stm32f303xe"
156-
))]
137+
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
157138
unsafe impl SckPin<SPI4> for PE12<AF5> {}
158139

159140
unsafe impl MisoPin<SPI1> for PA6<AF5> {}
160141
#[cfg(feature = "stm32f303")]
161142
unsafe impl MisoPin<SPI1> for PB4<AF5> {}
162143

163-
#[cfg(any(feature = "stm32f303"))]
144+
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
164145
unsafe impl MisoPin<SPI2> for PA10<AF5> {}
165146
unsafe impl MisoPin<SPI2> for PB14<AF5> {}
166147

167-
#[cfg(any(
168-
feature = "stm32f303xb",
169-
feature = "stm32f303xc",
170-
feature = "stm32f303xd",
171-
feature = "stm32f303xe"
172-
))]
173-
unsafe impl MisoPin<SPI4> for PE5<AF5> {}
174-
#[cfg(any(
175-
feature = "stm32f303xb",
176-
feature = "stm32f303xc",
177-
feature = "stm32f303xd",
178-
feature = "stm32f303xe"
179-
))]
180-
unsafe impl MisoPin<SPI4> for PE13<AF5> {}
181-
182-
#[cfg(any(feature = "stm32f303"))]
148+
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
183149
unsafe impl MisoPin<SPI3> for PB4<AF6> {}
184150
unsafe impl MisoPin<SPI3> for PC11<AF6> {}
185151

152+
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
153+
unsafe impl MisoPin<SPI4> for PE5<AF5> {}
154+
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
155+
unsafe impl MisoPin<SPI4> for PE13<AF5> {}
156+
186157
unsafe impl MosiPin<SPI1> for PA7<AF5> {}
187158
unsafe impl MosiPin<SPI1> for PB5<AF5> {}
188159

189-
#[cfg(any(feature = "stm32f303"))]
160+
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
190161
unsafe impl MosiPin<SPI2> for PA11<AF5> {}
191162
unsafe impl MosiPin<SPI2> for PB15<AF5> {}
192163

193164
unsafe impl MosiPin<SPI3> for PB5<AF6> {}
194165
unsafe impl MosiPin<SPI3> for PC12<AF6> {}
195166

196-
#[cfg(any(
197-
feature = "stm32f303xb",
198-
feature = "stm32f303xc",
199-
feature = "stm32f303xd",
200-
feature = "stm32f303xe"
201-
))]
167+
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
202168
unsafe impl MosiPin<SPI4> for PE6<AF5> {}
203-
#[cfg(any(
204-
feature = "stm32f303xb",
205-
feature = "stm32f303xc",
206-
feature = "stm32f303xd",
207-
feature = "stm32f303xe"
208-
))]
169+
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
209170
unsafe impl MosiPin<SPI4> for PE14<AF5> {}
210171

211172
pub trait Word {
@@ -388,7 +349,11 @@ macro_rules! hal {
388349
}
389350
}
390351

391-
#[cfg(feature = "stm32f334")]
352+
#[cfg(any(
353+
feature = "stm32f303x6",
354+
feature = "stm32f303x8",
355+
feature = "stm32f334",
356+
))]
392357
hal! {
393358
SPI1: (spi1, APB2, spi1en, spi1rst, pclk2),
394359
}
@@ -401,7 +366,9 @@ hal! {
401366

402367
#[cfg(any(
403368
feature = "stm32f302",
404-
feature = "stm32f303",
369+
feature = "stm32f303xb",
370+
feature = "stm32f303xc",
371+
feature = "stm32f318",
405372
feature = "stm32f328",
406373
feature = "stm32f358",
407374
feature = "stm32f373",
@@ -414,6 +381,14 @@ hal! {
414381
SPI3: (spi3, APB1, spi3en, spi3rst, pclk1),
415382
}
416383

384+
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
385+
hal! {
386+
SPI1: (spi1, APB2, spi1en, spi1rst, pclk2),
387+
SPI2: (spi2, APB1, spi2en, spi2rst, pclk1),
388+
SPI3: (spi3, APB1, spi3en, spi3rst, pclk1),
389+
SPI4: (spi4, APB2, spi4en, spi4rst, pclk2),
390+
}
391+
417392
// FIXME not working
418393
// TODO measure if this actually faster than the default implementation
419394
// impl ::hal::blocking::spi::Write<u8> for Spi {

0 commit comments

Comments
 (0)