Skip to content

Commit 766137b

Browse files
committed
improve SPI pin docs
1 parent a2f8c27 commit 766137b

File tree

1 file changed

+42
-20
lines changed

1 file changed

+42
-20
lines changed

src/spi.rs

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
/*!
22
# Serial Peripheral Interface
3+
To construct the SPI instances, use the `Spi::spiX` functions.
34
4-
## Alternate function remapping
5+
The pin parameter is a tuple containing `(sck, miso, mosi)` which should be configured as `(Alternate<PushPull>, Input<Floating>, Alternate<PushPull>)`.
56
6-
### SPI1
7+
You can also use `NoSck`, `NoMiso` or `NoMosi` if you don't want to use the pins
78
8-
| Function | Spi1NoRemap | Spi1Remap |
9-
|:----:|:-----------:|:---------:|
10-
| SCK | PA5 | PB3 |
11-
| MISO | PA6 | PB4 |
12-
| MOSI | PA7 | PB5 |
9+
- `SPI1` can use `(PA5, PA6, PA7)` or `(PB3, PB4, PB5)`.
10+
- `SPI2` can use `(PB13, PB14, PB15)`
11+
- `SPI3` can use `(PB3, PB4, PB5)` or `(PC10, PC11, PC12)`
1312
14-
### SPI2
1513
16-
| Function | Spi2NoRemap |
17-
|:----:|:-----------:|
18-
| SCK | PB13 |
19-
| MISO | PB14 |
20-
| MOSI | PB15 |
14+
## Initialisation example
2115
22-
### SPI3
16+
```rust
17+
// Acquire the GPIOB peripheral
18+
let mut gpiob = dp.GPIOB.split(&mut rcc.apb2);
2319
24-
Available only on high density devices.
20+
let pins = (
21+
gpiob.pb13.into_alternate_push_pull(&mut gpiob.crh),
22+
gpiob.pb14.into_floating_input(&mut gpiob.crh),
23+
gpiob.pb15.into_alternate_push_pull(&mut gpiob.crh),
24+
);
2525
26-
| Function | Spi3NoRemap | Spi3Remap |
27-
|:----:|:-----------:|:---------:|
28-
| SCK | PB3 | PC10 |
29-
| MISO | PB4 | PC11 |
30-
| MOSI | PB5 | PC12 |
26+
let spi_mode = Mode {
27+
polarity: Polarity::IdleLow,
28+
phase: Phase::CaptureOnFirstTransition,
29+
};
30+
let spi = Spi::spi2(dp.SPI2, pins, spi_mode, 100.khz(), clocks, &mut rcc.apb1);
31+
```
3132
*/
3233

3334
use core::ops::Deref;
@@ -147,6 +148,13 @@ remap!(Spi3NoRemap, SPI3, false, PB3, PB4, PB5);
147148
remap!(Spi3Remap, SPI3, true, PC10, PC11, PC12);
148149

149150
impl<REMAP, PINS> Spi<SPI1, REMAP, PINS> {
151+
/**
152+
Constructs an SPI instance using SPI1.
153+
154+
The pin parameter tuple (sck, miso, mosi) should be `(PA5, PA6, PA7)` or `(PB3, PB4, PB5)` configured as `(Alternate<PushPull>, Input<Floating>, Alternate<PushPull>)`.
155+
156+
You can also use `NoSck`, `NoMiso` or `NoMosi` if you don't want to use the pins
157+
*/
150158
pub fn spi1<F, POS>(
151159
spi: SPI1,
152160
pins: PINS,
@@ -167,6 +175,13 @@ impl<REMAP, PINS> Spi<SPI1, REMAP, PINS> {
167175
}
168176

169177
impl<REMAP, PINS> Spi<SPI2, REMAP, PINS> {
178+
/**
179+
Constructs an SPI instance using SPI1.
180+
181+
The pin parameter tuple (sck, miso, mosi) should be `(PB13, PB14, PB15)` configured as `(Alternate<PushPull>, Input<Floating>, Alternate<PushPull>)`.
182+
183+
You can also use `NoSck`, `NoMiso` or `NoMosi` if you don't want to use the pins
184+
*/
170185
pub fn spi2<F, POS>(
171186
spi: SPI2,
172187
pins: PINS,
@@ -186,6 +201,13 @@ impl<REMAP, PINS> Spi<SPI2, REMAP, PINS> {
186201

187202
#[cfg(any(feature = "high", feature = "connectivity"))]
188203
impl<REMAP, PINS> Spi<SPI3, REMAP, PINS> {
204+
/**
205+
Constructs an SPI instance using SPI1.
206+
207+
The pin parameter tuple (sck, miso, mosi) should be `(PB3, PB4, PB5)` or `(PC10, PC11, PC12)` configured as `(Alternate<PushPull>, Input<Floating>, Alternate<PushPull>)`.
208+
209+
You can also use `NoSck`, `NoMiso` or `NoMosi` if you don't want to use the pins
210+
*/
189211
pub fn spi3<F, POS>(
190212
spi: SPI3,
191213
pins: PINS,

0 commit comments

Comments
 (0)