Skip to content

Commit 2601bf6

Browse files
danielgallagher0Sh3Rm4n
authored andcommitted
Update SPI impls for STM32F302 family
Based on the datasheets for the 302x6/8, 302xb/c, and 302xd/e, the following pins and peripherals are supported: - SPI1 (b/c, and d/e): - SCK: PA5<AF5>, PB3<AF5> - MISO: PA6<AF5>, PB4<AF5> - MOSI: PA7<AF5>, PB5<AF5> - SPI2 (6/8, b/c and d/e): - SCK: PB13<AF5> - MISO: PB14<AF5> - MOSI: PB15<AF5> - Additional SPI2 Pin options (6/8 and d/e): - SCK: PF1<AF5> - MISO: PA10<AF5> - MOSI: PA11<AF5> - Additional SPI2 Pin options (b/c and d/e): - SCK: PF9<AF5>, PF10<AF5> - SPI3 (6/8, b/c and d/e): - SCK: PB3<AF6>, PC10<AF6> - MISO: PB4<AF6>, PC11<AF6> - MOSI: PB5<AF6>, PC12<AF6> - SPI4 (d/e only): - SCK: PE2<AF5>, PE12<AF5> - MISO: PE5<AF5>, PE13<AF5> - MOSI: PE6<AF5>, PE14<AF5> Note that this HAL doesn't currently have features for the 302x6/8 processors, so those peripherals aren't usable at the moment.
1 parent e156201 commit 2601bf6

File tree

1 file changed

+143
-23
lines changed

1 file changed

+143
-23
lines changed

src/spi.rs

Lines changed: 143 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,22 @@ use crate::pac::{
1010
};
1111
use crate::stm32::spi1;
1212

13-
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
13+
#[cfg(any(
14+
feature = "stm32f302xd",
15+
feature = "stm32f302xe",
16+
feature = "stm32f303xd",
17+
feature = "stm32f303xe"
18+
))]
1419
use crate::stm32::SPI4;
15-
use nb;
1620

17-
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
21+
#[cfg(any(
22+
feature = "stm32f302x6",
23+
feature = "stm32f302x8",
24+
feature = "stm32f302xd",
25+
feature = "stm32f302xe",
26+
feature = "stm32f303xd",
27+
feature = "stm32f303xe"
28+
))]
1829
use crate::gpio::gpioa::{PA10, PA11};
1930
use crate::gpio::gpioa::{PA5, PA6, PA7};
2031
#[cfg(any(
@@ -29,14 +40,30 @@ use crate::gpio::gpioa::{PA5, PA6, PA7};
2940
))]
3041
use crate::gpio::gpiob::PB13;
3142
use crate::gpio::gpiob::{PB14, PB15, PB5};
32-
#[cfg(feature = "stm32f303")]
43+
#[cfg(any(feature = "stm32f302", feature = "stm32f303"))]
3344
use crate::gpio::gpiob::{PB3, PB4};
3445
use crate::gpio::gpioc::{PC10, PC11, PC12};
35-
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
46+
#[cfg(any(
47+
feature = "stm32f302xd",
48+
feature = "stm32f302xe",
49+
feature = "stm32f303xd",
50+
feature = "stm32f303xe"
51+
))]
3652
use crate::gpio::gpioe::{PE12, PE13, PE14, PE2, PE5, PE6};
37-
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
53+
#[cfg(any(
54+
feature = "stm32f302x6",
55+
feature = "stm32f302x8",
56+
feature = "stm32f302xd",
57+
feature = "stm32f302xe",
58+
feature = "stm32f303xd",
59+
feature = "stm32f303xe"
60+
))]
3861
use crate::gpio::gpiof::PF1;
3962
#[cfg(any(
63+
feature = "stm32f302xb",
64+
feature = "stm32f302xc",
65+
feature = "stm32f302xd",
66+
feature = "stm32f302xe",
4067
feature = "stm32f303xb",
4168
feature = "stm32f303xc",
4269
feature = "stm32f303xd",
@@ -61,7 +88,10 @@ use crate::rcc::Clocks;
6188
))]
6289
use crate::rcc::APB1;
6390
#[cfg(any(
64-
feature = "stm32f302",
91+
feature = "stm32f302xb",
92+
feature = "stm32f302xc",
93+
feature = "stm32f302xd",
94+
feature = "stm32f302xe",
6595
feature = "stm32f303",
6696
feature = "stm32f328",
6797
feature = "stm32f334",
@@ -97,7 +127,13 @@ pub unsafe trait MisoPin<SPI> {}
97127
pub unsafe trait MosiPin<SPI> {}
98128

99129
unsafe impl SckPin<SPI1> for PA5<AF5> {}
100-
#[cfg(feature = "stm32f303")]
130+
#[cfg(any(
131+
feature = "stm32f302xb",
132+
feature = "stm32f302xc",
133+
feature = "stm32f302xd",
134+
feature = "stm32f302xe",
135+
feature = "stm32f303"
136+
))]
101137
unsafe impl SckPin<SPI1> for PB3<AF5> {}
102138

103139
#[cfg(any(
@@ -111,62 +147,135 @@ unsafe impl SckPin<SPI1> for PB3<AF5> {}
111147
feature = "stm32f398"
112148
))]
113149
unsafe impl SckPin<SPI2> for PB13<AF5> {}
114-
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
150+
#[cfg(any(
151+
feature = "stm32f302x6",
152+
feature = "stm32f302x8",
153+
feature = "stm32f302xd",
154+
feature = "stm32f302xe",
155+
feature = "stm32f303xd",
156+
feature = "stm32f303xe"
157+
))]
115158
unsafe impl SckPin<SPI2> for PF1<AF5> {}
116159
#[cfg(any(
160+
feature = "stm32f302xb",
161+
feature = "stm32f302xc",
162+
feature = "stm32f302xd",
163+
feature = "stm32f302xe",
117164
feature = "stm32f303xb",
118165
feature = "stm32f303xc",
119166
feature = "stm32f303xd",
120167
feature = "stm32f303xe"
121168
))]
122169
unsafe impl SckPin<SPI2> for PF9<AF5> {}
123170
#[cfg(any(
171+
feature = "stm32f302xb",
172+
feature = "stm32f302xc",
173+
feature = "stm32f302xd",
174+
feature = "stm32f302xe",
124175
feature = "stm32f303xb",
125176
feature = "stm32f303xc",
126177
feature = "stm32f303xd",
127178
feature = "stm32f303xe"
128179
))]
129180
unsafe impl SckPin<SPI2> for PF10<AF5> {}
130181

131-
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
182+
#[cfg(any(
183+
feature = "stm32f302",
184+
feature = "stm32f303xd",
185+
feature = "stm32f303xe"
186+
))]
132187
unsafe impl SckPin<SPI3> for PB3<AF6> {}
133188
unsafe impl SckPin<SPI3> for PC10<AF6> {}
134189

135-
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
190+
#[cfg(any(
191+
feature = "stm32f302xd",
192+
feature = "stm32f302xe",
193+
feature = "stm32f303xd",
194+
feature = "stm32f303xe"
195+
))]
136196
unsafe impl SckPin<SPI4> for PE2<AF5> {}
137-
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
197+
#[cfg(any(
198+
feature = "stm32f302xd",
199+
feature = "stm32f302xe",
200+
feature = "stm32f303xd",
201+
feature = "stm32f303xe"
202+
))]
138203
unsafe impl SckPin<SPI4> for PE12<AF5> {}
139204

140205
unsafe impl MisoPin<SPI1> for PA6<AF5> {}
141-
#[cfg(feature = "stm32f303")]
206+
#[cfg(any(
207+
feature = "stm32f302xb",
208+
feature = "stm32f302xc",
209+
feature = "stm32f302xd",
210+
feature = "stm32f302xe",
211+
feature = "stm32f303"
212+
))]
142213
unsafe impl MisoPin<SPI1> for PB4<AF5> {}
143214

144-
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
215+
#[cfg(any(
216+
feature = "stm32f302x6",
217+
feature = "stm32f302x8",
218+
feature = "stm32f302xd",
219+
feature = "stm32f302xe",
220+
feature = "stm32f303xd",
221+
feature = "stm32f303xe"
222+
))]
145223
unsafe impl MisoPin<SPI2> for PA10<AF5> {}
146224
unsafe impl MisoPin<SPI2> for PB14<AF5> {}
147225

148-
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
226+
#[cfg(any(
227+
feature = "stm32f302",
228+
feature = "stm32f303xd",
229+
feature = "stm32f303xe"
230+
))]
149231
unsafe impl MisoPin<SPI3> for PB4<AF6> {}
150232
unsafe impl MisoPin<SPI3> for PC11<AF6> {}
151233

152-
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
234+
#[cfg(any(
235+
feature = "stm32f302xd",
236+
feature = "stm32f302xe",
237+
feature = "stm32f303xd",
238+
feature = "stm32f303xe"
239+
))]
153240
unsafe impl MisoPin<SPI4> for PE5<AF5> {}
154-
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
241+
#[cfg(any(
242+
feature = "stm32f302xd",
243+
feature = "stm32f302xe",
244+
feature = "stm32f303xd",
245+
feature = "stm32f303xe"
246+
))]
155247
unsafe impl MisoPin<SPI4> for PE13<AF5> {}
156248

157249
unsafe impl MosiPin<SPI1> for PA7<AF5> {}
158250
unsafe impl MosiPin<SPI1> for PB5<AF5> {}
159251

160-
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
252+
#[cfg(any(
253+
feature = "stm32f302x6",
254+
feature = "stm32f302x8",
255+
feature = "stm32f302xd",
256+
feature = "stm32f302xe",
257+
feature = "stm32f303xd",
258+
feature = "stm32f303xe"
259+
))]
161260
unsafe impl MosiPin<SPI2> for PA11<AF5> {}
162261
unsafe impl MosiPin<SPI2> for PB15<AF5> {}
163262

164263
unsafe impl MosiPin<SPI3> for PB5<AF6> {}
165264
unsafe impl MosiPin<SPI3> for PC12<AF6> {}
166265

167-
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
266+
#[cfg(any(
267+
feature = "stm32f302xd",
268+
feature = "stm32f302xe",
269+
feature = "stm32f303xd",
270+
feature = "stm32f303xe"
271+
))]
168272
unsafe impl MosiPin<SPI4> for PE6<AF5> {}
169-
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
273+
#[cfg(any(
274+
feature = "stm32f302xd",
275+
feature = "stm32f302xe",
276+
feature = "stm32f303xd",
277+
feature = "stm32f303xe"
278+
))]
170279
unsafe impl MosiPin<SPI4> for PE14<AF5> {}
171280

172281
pub trait Word {
@@ -358,14 +467,20 @@ hal! {
358467
SPI1: (spi1, APB2, spi1en, spi1rst, pclk2),
359468
}
360469

361-
#[cfg(any(feature = "stm32f301", feature = "stm32f318"))]
470+
#[cfg(any(
471+
feature = "stm32f301",
472+
feature = "stm32f302x6",
473+
feature = "stm32f302x8",
474+
feature = "stm32f318"
475+
))]
362476
hal! {
363477
SPI2: (spi2, APB1, spi2en, spi2rst, pclk1),
364478
SPI3: (spi3, APB1, spi3en, spi3rst, pclk1),
365479
}
366480

367481
#[cfg(any(
368-
feature = "stm32f302",
482+
feature = "stm32f302xb",
483+
feature = "stm32f302xc",
369484
feature = "stm32f303xb",
370485
feature = "stm32f303xc",
371486
feature = "stm32f318",
@@ -381,7 +496,12 @@ hal! {
381496
SPI3: (spi3, APB1, spi3en, spi3rst, pclk1),
382497
}
383498

384-
#[cfg(any(feature = "stm32f303xd", feature = "stm32f303xe"))]
499+
#[cfg(any(
500+
feature = "stm32f302xd",
501+
feature = "stm32f302xe",
502+
feature = "stm32f303xd",
503+
feature = "stm32f303xe"
504+
))]
385505
hal! {
386506
SPI1: (spi1, APB2, spi1en, spi1rst, pclk2),
387507
SPI2: (spi2, APB1, spi2en, spi2rst, pclk1),

0 commit comments

Comments
 (0)