diff options
| author | Rasmus Melchior Jacobsen <[email protected]> | 2022-12-23 09:34:42 +0100 |
|---|---|---|
| committer | Rasmus Melchior Jacobsen <[email protected]> | 2022-12-23 09:34:42 +0100 |
| commit | 662bb5797f7723f16b0d5211c17e6a9fdeb2cf50 (patch) | |
| tree | 3056355ea0a38831be41b04936f8da7f211d915a | |
| parent | 2457fcaa35f7ceafcaee44f5e4b2a63c83674c89 (diff) | |
fix(stm32): Ensure that gpio speed is VeryHigh for all spi versions
This fixes #1095
| -rw-r--r-- | embassy-stm32/src/spi/mod.rs | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 1d4baf46d..439d92b97 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs | |||
| @@ -95,13 +95,10 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 95 | into_ref!(peri, sck, mosi, miso); | 95 | into_ref!(peri, sck, mosi, miso); |
| 96 | unsafe { | 96 | unsafe { |
| 97 | sck.set_as_af(sck.af_num(), AFType::OutputPushPull); | 97 | sck.set_as_af(sck.af_num(), AFType::OutputPushPull); |
| 98 | #[cfg(any(spi_v2, spi_v3, spi_v4))] | ||
| 99 | sck.set_speed(crate::gpio::Speed::VeryHigh); | 98 | sck.set_speed(crate::gpio::Speed::VeryHigh); |
| 100 | mosi.set_as_af(mosi.af_num(), AFType::OutputPushPull); | 99 | mosi.set_as_af(mosi.af_num(), AFType::OutputPushPull); |
| 101 | #[cfg(any(spi_v2, spi_v3, spi_v4))] | ||
| 102 | mosi.set_speed(crate::gpio::Speed::VeryHigh); | 100 | mosi.set_speed(crate::gpio::Speed::VeryHigh); |
| 103 | miso.set_as_af(miso.af_num(), AFType::Input); | 101 | miso.set_as_af(miso.af_num(), AFType::Input); |
| 104 | #[cfg(any(spi_v2, spi_v3, spi_v4))] | ||
| 105 | miso.set_speed(crate::gpio::Speed::VeryHigh); | 102 | miso.set_speed(crate::gpio::Speed::VeryHigh); |
| 106 | } | 103 | } |
| 107 | 104 | ||
| @@ -129,10 +126,8 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 129 | into_ref!(sck, miso); | 126 | into_ref!(sck, miso); |
| 130 | unsafe { | 127 | unsafe { |
| 131 | sck.set_as_af(sck.af_num(), AFType::OutputPushPull); | 128 | sck.set_as_af(sck.af_num(), AFType::OutputPushPull); |
| 132 | #[cfg(any(spi_v2, spi_v3, spi_v4))] | ||
| 133 | sck.set_speed(crate::gpio::Speed::VeryHigh); | 129 | sck.set_speed(crate::gpio::Speed::VeryHigh); |
| 134 | miso.set_as_af(miso.af_num(), AFType::Input); | 130 | miso.set_as_af(miso.af_num(), AFType::Input); |
| 135 | #[cfg(any(spi_v2, spi_v3, spi_v4))] | ||
| 136 | miso.set_speed(crate::gpio::Speed::VeryHigh); | 131 | miso.set_speed(crate::gpio::Speed::VeryHigh); |
| 137 | } | 132 | } |
| 138 | 133 | ||
| @@ -160,10 +155,8 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 160 | into_ref!(sck, mosi); | 155 | into_ref!(sck, mosi); |
| 161 | unsafe { | 156 | unsafe { |
| 162 | sck.set_as_af(sck.af_num(), AFType::OutputPushPull); | 157 | sck.set_as_af(sck.af_num(), AFType::OutputPushPull); |
| 163 | #[cfg(any(spi_v2, spi_v3, spi_v4))] | ||
| 164 | sck.set_speed(crate::gpio::Speed::VeryHigh); | 158 | sck.set_speed(crate::gpio::Speed::VeryHigh); |
| 165 | mosi.set_as_af(mosi.af_num(), AFType::OutputPushPull); | 159 | mosi.set_as_af(mosi.af_num(), AFType::OutputPushPull); |
| 166 | #[cfg(any(spi_v2, spi_v3, spi_v4))] | ||
| 167 | mosi.set_speed(crate::gpio::Speed::VeryHigh); | 160 | mosi.set_speed(crate::gpio::Speed::VeryHigh); |
| 168 | } | 161 | } |
| 169 | 162 | ||
| @@ -772,10 +765,13 @@ fn finish_dma(regs: Regs) { | |||
| 772 | #[cfg(not(any(spi_v3, spi_v4)))] | 765 | #[cfg(not(any(spi_v3, spi_v4)))] |
| 773 | while regs.sr().read().bsy() {} | 766 | while regs.sr().read().bsy() {} |
| 774 | 767 | ||
| 768 | // Disable the spi peripheral | ||
| 775 | regs.cr1().modify(|w| { | 769 | regs.cr1().modify(|w| { |
| 776 | w.set_spe(false); | 770 | w.set_spe(false); |
| 777 | }); | 771 | }); |
| 778 | 772 | ||
| 773 | // The peripheral automatically disables the DMA stream on completion without error, | ||
| 774 | // but it does not clear the RXDMAEN/TXDMAEN flag in CR2. | ||
| 779 | #[cfg(not(any(spi_v3, spi_v4)))] | 775 | #[cfg(not(any(spi_v3, spi_v4)))] |
| 780 | regs.cr2().modify(|reg| { | 776 | regs.cr2().modify(|reg| { |
| 781 | reg.set_txdmaen(false); | 777 | reg.set_txdmaen(false); |
